function[finalImg]=TransImg2(mbImg,colorTrans,whitePoint); [rows,cols]=size(mbImg); mbImg=bayerInterp(mbImg); mbImg=Rgb2XyzModel2(mbImg,colorTrans); Xplane=mbImg(:,:,1); Yplane=mbImg(:,:,2); Zplane=mbImg(:,:,3); xyzImg=zeros(rows*cols,3); xyzImg(:,1)=reshape(Xplane,rows*cols,1); xyzImg(:,2)=reshape(Yplane,rows*cols,1); xyzImg(:,3)=reshape(Zplane,rows*cols,1); labImg=xyz2lab(xyzImg,whitePoint); % Right here, LStar = reshape(labImg(:,1),rows,cols), etc. % labImg is correct. rgbImg=Lab2MonRgb(labImg'); finalImg=zeros(rows,cols,3); finalImg(:,:,1)=reshape(rgbImg(1,:),rows,cols); finalImg(:,:,2)=reshape(rgbImg(2,:),rows,cols); finalImg(:,:,3)=reshape(rgbImg(3,:),rows,cols);