creating 3 3 matrix with image

조회 수: 17 (최근 30일)
Malini Bakthavatchalam
Malini Bakthavatchalam 2020년 5월 24일
답변: Shravan Kumar Vankaramoni 2021년 3월 24일
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
Malini Bakthavatchalam
Malini Bakthavatchalam 2020년 5월 24일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shravan Kumar Vankaramoni
Shravan Kumar Vankaramoni 2021년 3월 24일
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);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by