% function[out]=Rgb2XyzModel3(img,colorTrans); % Input: img, an RGB image, size = rows*cols*3 % colorTrans, a 9x3 linear transformation matrix from RGB % to XYZ space. % Output: out, an XYZ image % % Uses colorTrans transformation matrix to transform input RGB % values to CIE-XYZ values. % function[out]=Rgb2XyzModel3(img,colorTrans); [rows,cols,colors]=size(img); if(colors~=3) error('ERROR(Rgb2XyzModel3): Input must be three color image!') end img=reshape(img,rows*cols,3); m2img=zeros(size(img,1),9); m2img(:,1)=img(:,1); m2img(:,2)=img(:,2); m2img(:,3)=img(:,3); m2img(:,4)=img(:,1).*img(:,2); m2img(:,5)=img(:,2).*img(:,3); m2img(:,6)=img(:,3).*img(:,1); m2img(:,7)=img(:,1).*img(:,1); m2img(:,8)=img(:,2).*img(:,2); m2img(:,9)=img(:,3).*img(:,3); out = colorTrans*m2img'; out = reshape(out',rows,cols,3);