⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rgb2luv.m

📁 快速高斯变换的程序
💻 M
字号:
function out = rgb2luv(in)
%RGB2LUV Convert RGB values to CIE LUV color space.

%   Copyright Changjiang Yang, 2003
%   Email: yangcj@umiacs.umd.edu
%   $Revision: 1.13 $  $Date: 2002/03/15 15:29:07 $

%   Reference: 
%     "David Bourgin's Color spaces FAQ"

if ndims(in)~=3 | size(in,3)~=3
   if ndims(in)==2 & size(in,2)==3 % a colormap
      iscolormap=1;
      colors = size(in,1);
      in = reshape(in, [colors 1 3]);
   else
      error('Invalid RGB input image');
   end
else
   iscolormap=0;
end

classin = class(in);
rgb = im2double(in);

% These equations transform RGB in [0,1] to YCBCR in [0, 255]
XYZ(:,:,1) = .4125*rgb(:,:,1) + .3576*rgb(:,:,2) + .1804*rgb(:,:,3);
XYZ(:,:,2) = .2125*rgb(:,:,1) + .7154*rgb(:,:,2) + .0721*rgb(:,:,3);
XYZ(:,:,3) = .0193*rgb(:,:,1) + .1192*rgb(:,:,2) + .9502*rgb(:,:,3);

Xn = 0.9505;
Yn = 1.0;
Zn = 1.0888;
Un_prime = 0.1978;
Vn_prime = 0.4683;
Lt = 0.008856;


%     CIE XYZ -> CIE Luv 
%     { L* = 116*((Y/Yn)^(1/3)-16) with Y/Yn>0.008856
%     { L* = 903.3*Y/Yn with Y/Yn<=0.008856
%     u* = 13*(L*)*(u'-u'n)
%     v* = 13*(L*)*(v'-v'n)
%     where u'=4*X/(X+15*Y*+3*Z) and v'=9*Y/(X+15*Y+3*Z)
%     and u'n and v'n have the same definitions for u' and v' but applied to the
%     white point reference. So, you have:
%     u'n=4*Xn/(Xn+15*Yn*+3*Zn) and v'n=9*Yn/(Xn+15*Yn+3*Zn)

y = XYZ(:,:,2) / 255;
out(:,:,1) = 903.3*y;
bigy = find(y > Lt);
out(bigy,1) = 116*y(bigy).^(1/3) - 16;
XYZ_prime = XYZ(:,:,1) + 15*XYZ(:,:,2) + 3*XYZ(:,:,3);
U_prime = 4*XYZ(:,:,1)./XYZ_prime;
V_prime = 9*XYZ(:,:,2)./XYZ_prime;
out(:,:,2) = 13*out(:,:,1) .* (U_prime - Un_prime);
out(:,:,3) = 13*out(:,:,1) .* (V_prime - Vn_prime);

% switch classin
% case 'uint8'
%    out = uint8(round(out));
% case 'uint16'
%    out = uint16(round(out*257));
% case 'double'
%    out = out / 255;
% end

if iscolormap
   out = reshape(out, [colors 3 1]);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -