# creating 3 3 matrix with image

35 views (last 30 days)
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
Malini Bakthavatchalam on 24 May 2020
I have used RGB = imread(image.jpg);
M = reshape(RGB,[],3);
and after this i have a [3 3] matrix I have to multiple it with M to get the color transform from RGB to LMS space... But it is showing me error. Thats the reason I want to know the matrix conversion from image.

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
% 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);