Converting a image matrix from RGB to XYZ color space
36 次查看(过去 30 天)
显示 更早的评论
Hi,
I would like to convert RGB data in 24x3 to xyz, using makecform and applycform. But, I am getting the number out of range - not scaled right.
function [xyz2D]=convertsrgb2xyz(srgb)
format3D = reshape(srgb,24,1,3);
C=makecform('srgb2xyz');
xyz=applycform(format3D,C);
xyz2D=reshape(xyz,24,3);
I am not sure what I am doing wrong here. Could you help me?
Thank you to whomever!
Sam
1 个评论
Andrew Newell
2012-1-10
编辑:Image Analyst
2025-4-3
I don't get any errors when I try
srgb=rand(24,3);
xyz2D=convertsrgb2xyz(srgb);
回答(2 个)
Image Analyst
2025-4-3
% In range 0-1
srgb=rand(24,3);
[xyz2D]=convertsrgb2xyz(srgb)
% uint8 variables in range 0-255
srgbUint8 = uint8(255 * rand(24, 3));
[xyz2D8]=convertsrgb2xyz(srgbUint8)
% Your function
function [xyz2D]=convertsrgb2xyz(srgb)
format3D = reshape(srgb,24,1,3);
C=makecform('srgb2xyz');
xyz=applycform(format3D,C);
xyz2D=reshape(xyz,24,3);
end
There doesn't seem to be any error thrown but the values are not correct for uint8-ranged values.
0 个评论
nick
2025-4-3
Hi Youngsam,
Kindly share the data used as input for the function to help debug the issue. I didn't get any errors while using the function 'convertssrgb2xyz':
srgb=rand(24,3);
xyz2D=convertsrgb2xyz(srgb);
Please ensure that the input RGB values are correctly scaled and formatted. The 'makecform('srgb2xyz')' expects the RGB values to be in the range of [0, 1]. A possible cause for out of scale error could be RGB data is in the range [0, 255], and hence need normalization before applying the color transformation.
You can refer to the documentation of 'makecform' to know more about it by executing the following commmand in MATLAB Command window:
doc makecform
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Color 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!