def RGBFromIntensity(intensity): sat = 1.0 lum = 0.5 if sat == 0.0: return (lum * 255, lum * 255, lum * 255) else: _hue = intensity / 360 v2 = lum * (1 + sat) if lum < 0.5 else (lum + sat) - (lum * sat) v1 = 2 * lum - v2 r = 255 * Hue2RGB(v1, v2, _hue + (1.0 / 3)) g = 255 * Hue2RGB(v1, v2, _hue) b = 255 * Hue2RGB(v1, v2, _hue - (1.0 / 3)) return (r, g, b)
时间: 2023-02-08 15:02:10 浏览: 121
这是一个使用 HSL 色彩模型 (Hue, Saturation, Lightness) 将灰度值转换为 RGB 值的 Python 函数。它首先定义了饱和度和亮度的值,如果饱和度为 0,则直接返回灰色(即所有 RGB 值相等)。否则,使用输入的灰度值计算出色相,然后使用 Hue2RGB 函数计算出 RGB 值,最后返回 RGB 值。
相关问题
traceH = hilbert(trace); clear trace traceH = traceH.*conj(traceH(:,1)); GAPL = 0.4; moveN = round(8/GAPL); [output] = moveVectorMean2(traceH,moveN); traceH=output; clear output amp = abs(traceH); [M,N] = size(amp); gapD = round(4/GAPL); [output] = spacephsed(traceH,gapD); clear traceH phaOutput = angle(output); clear output phaseUnw(:,:) = unwrap(squeeze(phaOutput(:,:))')'; clear phaOutput [~,axisTp,outputtp] = denoiseFunc(5,500,phaseUnw,fd,fs,GAPL); % 慢轴,快轴 clear phaseUnw [~,axisT,outputint] = denoiseFunc(5,490,amp,fd,fs,GAPL); % 慢轴,快轴 clear amp for i=1:1:floor(length(outputtp(:,1))/10) phase(i,:)=mean(outputtp((i-1)*10+1:i*10,:)); end clear outputtp for i=1:1:floor(length(outputint(:,1))/10) intensity(i,:)=mean(outputint((i-1)*10+1:i*10,:)); end clear outputint figure for i=1:1:22 plot(axisTp,phase(i,:)/10*10+i*4); hold on end hold off figure for i=1:1:22 plot(axisT,intensity(i,:)/10*10+i*4); hold on end hold off % for i=1:1:floor(length(intensity(1,:))/4000) % stdp(:,i)=var(phase(:,(i-1)*4000+1:i*4000),0,2); % stdt(:,i)=var(intensity(:,(i-1)*4000+1:i*4000),0,2); % end % for i=1:1:29 % positionp(i)=find(stdp(:,i)==max(stdp(:,i))); % positioni(i)=find(stdt(:,i)==max(stdt(:,i))); % end %%将数据切为不同帧 for i=1:1:10 trandatap(:,:,i)=phase(1:8,(i-1)*4000+1:(i)*4000); trandatai(:,:,i)=intensity(1:8,(i-1)*4000+1:(i)*4000); end %%删除信噪比较差的数据。(先把数据图像画图,然后筛选) trainphase=trandatap; traintensity=trandatai; trainphase(:,:,27:29)=[]; trainphase(:,:,1:2)=[]; trainphase(:,:,16)=[]; trainphase(:,:,14)=[]; trainphase(:,:,10)=[]; trainphase(:,:,7:8)=[]; trainphase(:,:,4)=[]; trainphase(:,:,1)=[]; traintensity(:,:,27:29)=[]; traintensity(:,:,1:2)=[]; traintensity(:,:,16)=[]; traintensity(:,:,14)=[]; traintensity(:,:,10)=[]; traintensity(:,:,7:8)=[]; traintensity(:,:,4)=[]; traintensity(:,:,1)=[];
traceH = hilbert(trace);
clear trace
traceH = traceH.*conj(traceH(:,1));
GAPL = 0.4;
moveN = round(8/GAPL);
[output] = moveVectorMean2(traceH,moveN);
traceH=output;
clear output
amp = abs(traceH);
[M,N] = size(amp);
gapD = round(4/GAPL);
[output] = spacephsed(traceH,gapD);
clear traceH
phaOutput = angle(output);
clear output
phaseUnw(:,:) = unwrap(squeeze(phaOutput(:,:))')';
clear phaOutput
[~,axisTp,outputtp] = denoiseFunc(5,500,phaseUnw,fd,fs,GAPL); % Slow axis, Fast axis
clear phaseUnw
[~,axisT,outputint] = denoiseFunc(5,490,amp,fd,fs,GAPL); % Slow axis, Fast axis
clear amp
for i=1:1:floor(length(outputtp(:,1))/10)
phase(i,:)=mean(outputtp((i-1)*10+1:i*10,:));
end
clear outputtp
for i=1:1:floor(length(outputint(:,1))/10)
intensity(i,:)=mean(outputint((i-1)*10+1:i*10,:));
end
clear outputint
figure
for i=1:1:22
plot(axisTp,phase(i,:)/10*10+i*4);
hold on
end
hold off
figure
for i=1:1:22
plot(axisT,intensity(i,:)/10*10+i*4);
hold on
end
hold off
% for i=1:1:floor(length(intensity(1,:))/4000)
% stdp(:,i)=var(phase(:,(i-1)*4000+1:i*4000),0,2);
% stdt(:,i)=var(intensity(:,(i-1)*4000+1:i*4000),0,2);
% end
% for i=1:1:29
% positionp(i)=find(stdp(:,i)==max(stdp(:,i)));
% positioni(i)=find(stdt(:,i)==max(stdt(:,i)));
% end
%% Split the data into different frames
for i=1:1:10
trandatap(:,:,i)=phase(1:8,(i-1)*4000+1:(i)*4000);
trandatai(:,:,i)=intensity(1:8,(i-1)*4000+1:(i)*4000);
end
%% Remove data with poor signal-to-noise ratio (plot the data and then select)
trainphase=trandatap;
traintensity=trandatai;
trainphase(:,:,27:29)=[];
trainphase(:,:,1:2)=[];
trainphase(:,:,16)=[];
trainphase(:,:,14)=[];
trainphase(:,:,10)=[];
trainphase(:,:,7:8)=[];
trainphase(:,:,4)=[];
trainphase(:,:,1)=[];
traintensity(:,:,27:29)=[];
traintensity(:,:,1:2)=[];
traintensity(:,:,16)=[];
traintensity(:,:,14)=[];
traintensity(:,:,10)=[];
traintensity(:,:,7:8)=[];
traintensity(:,:,4)=[];
traintensity(:,:,1)=[];
怎么理解function [C] = IntensityToColor(wavelengths, Inten) %A(theta, phi, wavelength, vertical pol/horizontal pol) %两个偏振方向上的强度加在一起. %确定颜色: %加载CIE数据 CIEXYZ_Data = dlmread('SpectrumToColor/ciexyz31.csv'); CIE_1 = interp1(CIEXYZ_Data(:,1),CIEXYZ_Data(:,2),wavelengths*1000, 'pchip', 0); CIE_2 = interp1(CIEXYZ_Data(:,1),CIEXYZ_Data(:,3),wavelengths*1000, 'pchip', 0); CIE_3 = interp1(CIEXYZ_Data(:,1),CIEXYZ_Data(:,4),wavelengths*1000, 'pchip', 0); %将颜色映射初始化为零: C=zeros(size(Inten, 2), size(Inten, 3), 3); maxIntensity=max(max(max(Inten))); for ll= 1:size(Inten, 2) for jj=1:size(Inten, 3) %对整个图像进行归一化: intensity=Inten( :, ll, jj)/maxIntensity; %与颜色匹配函数相乘和积分 if not(sum(intensity)==0) X = sum(intensity'.*CIE_1)/sum(CIE_1); Y = sum(intensity'.*CIE_2)/sum(CIE_2); Z = sum(intensity'.*CIE_3)/sum(CIE_3); XYZ=[X;Y;Z]; %转换矩阵: xyzToRGB = [3.2404542, - 1.5371385, - 0.4985314; -0.9692660, 1.8760108, 0.0415560; 0.0556434, - 0.2040259, 1.0572252]; %线性 rgb: rgb=xyzToRGB*XYZ; %sRGB (伽玛校正): for kk=1:3 if (rgb(kk) > 0.0031308 ) rgb(kk) = 1.055 * ( rgb(kk) ^ ( 1 / 2.4 ) ) - 0.055; else rgb(kk) = 12.92 * rgb(kk); end end %color map: C(ll, jj, 1)=rgb(1); C(ll, jj, 2)=rgb(2); C(ll, jj, 3)=rgb(3); end end end end
这是一个 MATLAB 函数,它的作用是将波长和强度数据转换为对应的颜色值。函数中首先加载了 CIE 数据,然后将强度数据进行归一化并与颜色匹配函数相乘得到颜色的 XYZ 值,接着使用线性 RGB 转换矩阵将 XYZ 值转换为线性 RGB 值,最后使用伽玛校正将线性 RGB 值转换为 sRGB 值。最终返回的是每个波长对应的 RGB 值。
阅读全文