Color space transform: camera (linear) RGB to XYZ
    8 views (last 30 days)
  
       Show older comments
    
Hello all,
I have a problem...
Assume I have a Canon D40 camera and am producing .cr2 images in order to transform these images to XYZ color space. I want to do some color transformations and therefore I need XYZ color space.
I used Adobe DNG converter to get .dng files and then did some processing to get linear RGB images.
Now I want to do conversion from linear RGB to XYZ...but my results are faulty...
Please check the code:
% % .DNG file was converted to linear RGB (test_cc_lin_rgb.tif); import lin_rgb. % lin_rgb=im2double(imread('test_cc_lin_rgb.tif'));
% XYZ-to-Camera color space matrix provided by Adobe (Adobe with a D50 % white point) - THIS PART IS PROBABLY WRONG
xyz2cam=[6071,-747,-856;-7653,15365,2441;-2025,2553,7315]/10000;
xyz2cam = xyz2cam ./ repmat(sum(xyz2cam,2),1,3); % Normalize rows to 1 cam2xyz = xyz2cam^-1;
lin_xyz = apply_cmatrix(lin_rgb,cam2xyz); lin_xyz = max(0,min(lin_xyz,1));
function corrected = apply_cmatrix(im,cmatrix) % CORRECTED = apply_cmatrix(IM,CMATRIX) % % Applies CMATRIX to RGB input IM. Finds the appropriate weighting of the
% old color planes to form the new color planes, equivalent to but much
% more efficient than applying a matrix transformation to each pixel.
if size(im,3)˜=3
    error(’Apply cmatrix to RGB image only.’)
end
r = cmatrix(1,1)*im(:,:,1)+cmatrix(1,2)*im(:,:,2)+cmatrix(1,3)*im(:,:,3);
g = cmatrix(2,1)*im(:,:,1)+cmatrix(2,2)*im(:,:,2)+cmatrix(2,3)*im(:,:,3);
b = cmatrix(3,1)*im(:,:,1)+cmatrix(3,2)*im(:,:,2)+cmatrix(3,3)*im(:,:,3);
corrected = cat(3,r,g,b);
end
*My code is following code proposed by Rob Sumner in Processing RAW Images in MATLAB.
Please help!
Thanks, Matija.
0 Comments
Answers (1)
  Image Analyst
      
      
 on 5 May 2014
        There is a function called makecform() in the Image Processing Toolbox that does this if you can get the sRGB image.
Otherwise you'll have to explain why you believe/know "my results are faulty".
2 Comments
  Roger Breton
 on 23 Jan 2024
				I'm in a similar situation with this code:
lin_srgb = apply_cmatrix(lin_rgb, cam2rgb);
Matlab does not recognize the funtion "apply_cmatrix"?
  Roger Breton
 on 23 Jan 2024
				See Also
Categories
				Find more on Image Processing Toolbox in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

