Converting a image matrix from RGB to XYZ color space
36 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Andrew Newell
el 10 de En. de 2012
Editada: Image Analyst
el 3 de Abr. de 2025
I don't get any errors when I try
srgb=rand(24,3);
xyz2D=convertsrgb2xyz(srgb);
Respuestas (2)
Image Analyst
el 3 de Abr. de 2025
% 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 comentarios
nick
el 3 de Abr. de 2025
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 comentarios
Ver también
Categorías
Más información sobre Color en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!