I have a RGB image which I am trying to complement without using the built-in function imcomplement(A)
.
R=A(:,:,1);% A is the input image
G=A(:,:,2);
B=A(:,:,3);
[r,c]=size(B);
for i=1:1:r
for j=1:1:c
R(i,j)=255-R(i,j);
G(i,j)=255-G(i,j);
B(i,j)=255-B(i,j);
end
end
new=cat(3,R,G,B);
This solution gives the expected output.
How can I do the same thing without using the cat
function? This is my current unsuccessful attempt:
[r,c]=size(B);
new=zeros(size(A,1),size(A,2),'uint8');
for i=1:1:r
for j=1:1:c
for k=1:1:1
new(i,j,k)=(255-G(i,j));
end
end
end