Converting a image matrix from RGB to XYZ color space
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Andrew Newell
il 10 Gen 2012
Modificato: Image Analyst
il 3 Apr 2025
I don't get any errors when I try
srgb=rand(24,3);
xyz2D=convertsrgb2xyz(srgb);
Risposte (2)
Image Analyst
il 3 Apr 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 Commenti
nick
il 3 Apr 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 Commenti
Vedere anche
Categorie
Scopri di più su Color in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!