필터 지우기
필터 지우기

Why i'm getting different results from RGB to XYZ color conversion?

조회 수: 6 (최근 30일)
Bruno Tondin
Bruno Tondin 2018년 7월 4일
편집: KARSH THARYANI 2018년 7월 6일
Hello,
I'm performing a color conversion from RGB to XYZ using 3 methods. The first one is the MATLAB suggested function
IM_XYZ = rgb2xyz(IM_ORIG);
The second one is another bult in matlab function
cform = makecform('srgb2xyz');
IM_XYZ2 = applycform(IM_ORIG,cform);
The third one I did it myself using the the matrix used in Lindbloom website (inside one of the functions that the rgb2xyz() function calls i could find the same matrix and even the Lindbloom website reference).
The problem is that i'm getting different results from the 3 ways.
Can someone help me?
Thanks
All my code:
clc;
clear;
close all
%%Generate test image
R = [255 0 0; 255 0 85; 22 34 115];
G = [0 255 0; 255 0 85; 82 12 85];
B = [0 0 255; 255 0 85; 101 66 22];
IM_ORIG(:,:,1) = R;
IM_ORIG(:,:,2) = G;
IM_ORIG(:,:,3) = B;
IM_ORIG = (IM_ORIG)./255;
%%Converte imagem RGB para XYZ
IM_XYZ = rgb2xyz(IM_ORIG); % first method
cform = makecform('srgb2xyz');
IM_XYZ2 = applycform(IM_ORIG,cform); % second method
% conversion matrix (http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html)
M_conv = [0.4124564 0.3575761 0.1804375; ...
0.2126729 0.7151522 0.0721750; ...
0.0193339 0.1191920 0.9503041];
RGB(:) = IM_ORIG(1,1,:);
aa = M_conv*(RGB');
for i = 1:size(IM_ORIG,1)
for j = 1:size(IM_ORIG,2)
RGB(:) = IM_ORIG(i,j,:);
IM_XYZ3(i,j,:) = (M_conv*(RGB'))';
end
end
  댓글 수: 1
KARSH THARYANI
KARSH THARYANI 2018년 7월 6일
편집: KARSH THARYANI 2018년 7월 6일
Are you sure that the input to both the functions is absolute, in the sense that the RGB spectrum format for an image is relative(sRGB is different from RGB). Hence, if one function assumes input as RGB and the other as sRGB, is it not possible that their conversion outputs might be different?
Also, in your method 3 it seems that you are not making R_srgb to R_linear, as stated in the Wikipedia article here

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by