How to concatenate 3 RGB channels without using the cat(3,R,G,B) function [closed]

As mentioned by @Pascal, the most straightforward solution is

new = intmax('uint8') - A;

If you insist on using loops (which I highly advise against in this case), these should work:

[r,c,s] = size(A);
new = zeros(r,c,s,'uint8'); % alternatively: zeros(r,c,s,'like',A);
for iR = 1:r % the middle :1: is implied
  for iC = 1:c
    for iS = 1:s % s stands for "slice"
      new(iR, iC, iS) = intmax('uint8') - A(iR, iC, iS);
    end
  end
end
for iR = 1:r
  for iC = 1:c
    new(iR, iC, 1) = intmax('uint8') - R(iR, iC);
    new(iR, iC, 2) = intmax('uint8') - G(iR, iC);
    new(iR, iC, 3) = intmax('uint8') - B(iR, iC);
  end
end

As you can see, all of the above solutions do not use the cat function which you wanted to avoid.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top