function Image = rgb2lab(Image)
if size(Image,3) ~= 3
error('im 一定要为3通道颜色图像空间');
end
if ~isa(Image,'double')
Image = double(Image)/255;
end
R = invgammacorrection(Image(:,:,1));
G = invgammacorrection(Image(:,:,2));
B = invgammacorrection(Image(:,:,3));
T = inv([3.2406,-1.5372,-0.4986;-0.9689,1.8758,0.0415;0.0557,-0.2040,1.057])
Image(:,:,1) = T(1) * R + T(4) * G + T(7) * B %X
Image(:,:,2) = T(2) * R + T(5) * G + T(8) * B %Y
Image(:,:,3) = T(3) * R + T(6) * G + T(9) * B %Z
WhitePoint = [0.950456,1,1.088754];
X = Image(:,:,1)/WhitePoint(1);
Y = Image(:,:,2)/WhitePoint(2);
Z = Image(:,:,3)/WhitePoint(3);
fX = f(X);
fY = f(Y);
fZ = f(Z);
Image(:,:,1) = 116 * fY - 16;%L
Image(:,:,2) = 500 * (fX - fY);
Image
matlab颜色空间转换RGB转换到lab
最新推荐文章于 2025-06-22 16:26:34 发布