matrix to rgb conversion
Show older comments
When we write
i=imread('test.jpg');
if test.jpg is a colored image then it returns us i as a 3D matrix.
if we write
figure,imshow(i)
it shows the colored image test.jpg
but if we assign the values in i to another variable using the following syntax:
a=i(:,:,1); a=i(:,:,2); a=i(:,:,3);
then if i write
figure,imshow(a)
it does not return me the colored image as test.jpg
can any one say why this happen? How can i get the make a rgb image if i assign value to a 3D matrix manually how can i get the corresponding colored rgb image?
Accepted Answer
More Answers (1)
Jan
on 28 Mar 2011
i = imread('test.jpg');
a = i(:,:,1);
% Now [a] is a 2D-Matrix containing the first
% submatrix of i.
a = i(:,:,2);
% Now [a] is a 2D-Matrix containing the second
% Submatrix of i. The former values are overwritten.
a = i(:,:,3);
% Now [a] is a 2D-Matrix containing the third
% Submatrix of i. The former values are overwritten.
Therefore [a] is a matrix at the end. To copy the 3D-Array:
a = cat(3, i(:,:,1), i(:,:,2), i(:,:,3));
% Or simpler:
a = i;
1 Comment
Mohammad Golam Kibria
on 29 Mar 2011
Categories
Find more on Image 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!