creating 3 3 matrix with image
Show older comments
Hi, I have an image and I have to convert that image to LMS color space, so the first step I want to know is how do I convert the given image in [3 3] matrix , is there any function?
Thanks
1 Comment
Malini Bakthavatchalam
on 24 May 2020
Answers (1)
Shravan Kumar Vankaramoni
on 24 Mar 2021
Hi Malini,
I assume that you are trying to convert RGB image to 3x1 and multiply it with 3x3 transformation matrix.
To convert the image to 3x1 , you can use
[R,G,B] = imsplit(image);
Which will extract R,G,B dimensions and then multiply with transformation matrix(3*3) to get the LMS colourspace image. Refer to RGB to HSV conversion example for more information.
The following code demonstrates RGB to LMS conversion
image = imread('corn.tif',2);
% imsplit() gives the image components separately
[R,G,B] = imsplit(image);
%converting to 3x1 matrix to multiply with tranformation matrix
b = [reshape(double(R),415*312,1) reshape(double(G),415*312,1) reshape(double(B),415*312,1)]';
transformation_matrix = [17.8824,43.5161,4.1194;3.4557,27.1554,3.8671;0.0300,0.1843,1.4671];
% output is in the L M S format
output = transformation_matrix * b;
[X,Y] = size(R);
%converting back to original shape
first = reshape(output(1,:),X,Y);
second = reshape(output(2,:),X,Y);
third = reshape(output(3,:),X,Y);
imout(:,:,1) = first ;
imout(:,:,2) = second ;
imout(:,:,3) = third ;
imout = uint8(imout);
imshow(imout);
Categories
Find more on Image Filtering and Enhancement 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!