Color space transform: camera (linear) RGB to XYZ
조회 수: 9 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Image Analyst
2014년 5월 5일
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
Roger Breton
2024년 1월 23일
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
2024년 1월 23일
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!