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!