首页 > 解决方案 > 如何控制 pcolor 图中的颜色和强度?

问题描述

我正在尝试模拟 Coronae(液滴的衍射)。颜色取决于波长,强度取决于衍射。如何通过波长 ( lambda ) 和强度 ( I ) 同时控制颜色?我现在只能控制 lambda 以获得不同颜色的衍射图案。

lambda=400;  % wavelength [nm] 
a=10e3;  % obstruct disc radius [nm](um)
x=linspace(-0.2,0.2,1000);
y=x;
[X,Y]=meshgrid(x,y);
r=sqrt(X.^2+Y.^2);
% diffraction pattern
u=2.*pi.*a./lambda;
J=besselj(1,u.*sin(r));
I=sqrt((u.*((1+cos(r))./2).*(J./sin(r))).^2);  % Intensity
% colormap
w=lambda;
if (w >= 380) && (w < 440)
    R = -(w - 440.) / (440. - 380.);
    G = 0.0;
    B = 1.0;
    elseif (w >= 440) && (w < 490)
        R = 0.0;
        G = (w - 440.) / (490. - 440.);
        B = 1.0;
    elseif (w >= 490) && (w < 510)
        R = 0.0;
        G = 1.0;
        B = -(w - 510.) / (510. - 490.);
    elseif (w >= 510) && (w < 580)
        R = (w - 510.) / (580. - 510.);
        G = 1.0;
        B = 0.0;
    elseif (w >= 580) && (w < 645)
        R = 1.0;
        G = -(w - 645.) / (645. - 580.);
        B = 0.0;
    elseif (w >= 645) && (w <= 780)
        R = 1.0;
        G = 0.0;
        B = 0.0;
    else
        R = 0.0;
        G = 0.0;
        B = 0.0;
end
c=[R,G,B]; 
h=linspace(0,1,256);  % illumination (intensity) from [0,1]
for i=1:length(h)
    S{i}=h(i).*c;
end
map=cell2mat(S');
% figure
pcolor(X,Y,I); shading flat; axis image; title([num2str(lambda)]);
colormap(map);

这就是我想要模拟的。(图片来自谷歌搜索)

这就是我到目前为止所得到的(可以通过波长改变颜色)

标签: matlabimage-processingsimulationcolormap

解决方案


推荐阅读