首页 > 编程知识 正文

matlab怎么改颜色,cielab颜色空间中的a指什么

时间:2023-05-04 17:11:38 阅读:59958 作者:3752

资料来源: http://www.mathworks.com/MATLAB central/file exchange/24009-RGB2lab/content/RGB2lab.m和http://www.mathworks .

% RGB2labconvertanimagefromrgbtocielab

%

% function [L,a,b]=RGB2lab(r,g,b ) )。

% function [L,a,b]=RGB2lab(I ) () ) ) ) ) )

% function I=RGB2Lab ()甜鱼)

%

% RGB2Lab takes red,green,and blue matrices,or a single M x N x 3 image,

% andreturnsanimageinthecielabcolorspace.rgbvaluescanbe

% either between0and1 or between0and 255.valuesforlareinthe

% range [ 0,100 ] whileaandbareroughlyintherange [-110,110 ].the

% output is of type double。

%

% thistransformisbasedonitu-rrecommendationbt.709 using the d65

% whitepointreference.theerrorintransformingrgb-la B- RGB is

% approximately 10^-5。

%

% see also lab2 RGB.% bymarkruzonfromccodebytlddx,23 September 1997。

% updatedformatlab 528日本1998。

% updatedformatlab 730 March 2009.ifnargin==1

b=双精度(r ) :3 );

g=双精度(r ) :2 );

r=双精度(r ) :1 );

endif max (最大(r )||max ) ) 1.0||max ) ) 1.0

R=double/255;

g=双精度(g )/255;

b=双精度(b )/255;

end% Set a threshold

T=0.008856;n )=size;

s=M * N; % RGB to XYZ

MAT=[0.412453 0.357580 0.180423;

0.212671 0.715160 0.072169;

0.019334 0.119193 0.950227];

XYZ=MAT * RGB; % Normalize for D65 white point

x=XYZ (1, )/0.950456;

y=XYZ (2,

z=XYZ (3, )/1.088754;=X T;

YT=Y T;

ZT=Z T;=y.^(1/3 fX=XT .纯酸奶(1/3);烂酸奶(.) ) * (7.787 .* X 16/116 );

fY=YT .* Y3 (冒着生命危险的唇彩(() ) ) * (7.787 .* Y 16/116 );

FZ=ZT.xsdyc(1/3) ) gjdxtd ).* ) * (7.787 .* Z 16/116 );=reshape(yt.*(116*y3-16.0 ) )生命之唇(.* ) * (903.3 * Y ),m,n );

a=reshape(500* ) FX-fy ),m,n );

b=reshape(200* ) fy-FZ ),m,n ); if nargout 2

L=cat(3,l,a,b );

function [R,g,b]fzdylab2RGB(l,a,b ) )。

% lab2 rgbconvertanimagefromcielabtorgb

%

% function [R,g,b]fzdylab2RGB(l,a,b ) )。

% function [R,g,B] fzdylab2RGB(I (

% function I fzdylab2RGB ((甜鱼) ) ) )。

%

% Lab2RGB takes L,a,and b double matrices,or an M x N x 3 double

% image,andreturnsanimageinthergbcolorspace.valuesforlarein

% the range [ 0,100 ] while a* andb * areroughlyintherange [-110,110 ]。

% If 3 outputs are specified,thevalueswillbereturnedasdoublesinthe

% range [ 0,1 ],otherwisethevalueswillbeuint8sintherange [ 0,255 ]。

%

% thistransformisbasedonitu-rrecommendationbt.709 using the d65

% whitepointreference.theerrorintransformingrgb-la B- RGB is

% approximately 10^-5。

%

% see also RGB2lab.% bymarkruzonfromccodebytlddx,23 September 1997。

% updatedformatlab 528日本1998。

% fixedabuginconversionbacktouint 89 September 1999。

% updatedformatlab 730 March 2009.ifnargin==1

bfzdyl(:3 );

afzdyl(:2;

lfzdyl(:1 );

end% Thresholds

T1=0.008856;

T2=0.206893;n )=size(L );

s=M * N;

L=reshape(L,1,s );

a=reshape(a,1,s );

b=reshape(b,1,s ); % Compute Y

fy=() L16 )/116 ).^ 3;

YT=fY T1;

fY=(冒着生命危险的唇彩(.* ) * (L/903.3 ) YT .* fY;

Y=fY; % alterfyslightlyforfurthercalculations

fy=yt.*(fy.^(1/3) )玩命唇彩).* ) * (7.787 .* fY 16/116 ) ); % Compute X

fX=a/500 fY;

XT=fX T2;

x=(XT.) (FX.^3) (腐烂的酸奶).) ) (FX-16/116 )/7.787 ) ) % Compute Z

fZ=fY - b/200;

ZT=fZ T2;

z=(ZT.*(FZ.^3) gjdxtd ).* ) ) FZ-16/116 )/7.787 ); % Normalize for D65 white point

X=X * 0.950456;

Z=Z * 1.088754; % XYZ to RGB

mat=[ 3.240479-1.537150-0.498535;

-0.969256 1.875992 0.041556;

0.055648 -0.204043 1.057311]; 很深的往事=max(min ) mat爱唠叨的小丸子x; y; Z],1 ),0 ); r=reshape (RGB (1, ),m,n );

g=reshape(RGB ) 2, ),m,n );

b=reshape(RGB(3, ),m,n ); if nargout 2

r=uint8(round(cat(3,r,g,b ) * 255 );

结束

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。