Regenerating an RGB image from its components
Show older comments
I extracted the red component of an image and displayed the image with just the red component and I got the following result:

if true
f=imread('Parrot.jpg');
[r,c,d]=size(f);
a=zeros(size(f,1),size(f,2));
red=f(:,:,1);
just_red=cat(3,red,a,a);
figure, imshow(just_red), title('Red component');
end
However, if I save the red component values in a matrix and then use the matrix to form the red image, I get the following result:

if true
f=imread('Parrot.jpg');
[r,c,d]=size(f);
a=zeros(size(f,1),size(f,2));
dred=[values of the 100x100 matrix];
just_red=cat(3,dred,a,a);
figure, imshow(just_red), title('Red component');
end
To give a background of what I am actually doing - I am trying to encrypt and decrypt an image. 'red' is the original red component, which I encrypted and am able to decrypt it successfully till the matrix form of dred (I have checked that red==dred). But dred is not producing the red image that it should.
Any help as to why this is happening will be much appreciated.
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!