How to control color and the intensity in a pcolor figure?

조회 수: 2 (최근 30일)
chia ching lin
chia ching lin 2020년 12월 4일
답변: Bjorn Gustavsson 2020년 12월 4일
I'm try in to simulate a Coronae (diffraction of droplet). There are color depends by wavelength, and intensity depends by diffraction. How can I control both color by wavelength (lambda) and intensity (I) ?
I can only control lambda to have different color of diffraction pattern now.
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);
This is what I'm trying to simulate. (picture from google search)
And this is what I get so far (can change color by wavelength)
  댓글 수: 4
Bjorn Gustavsson
Bjorn Gustavsson 2020년 12월 4일
@Image Analyst, if there are small droplets in the atmosphere light will be diffracted, leading to coronae around light-sources (sun, moon etc): Corona
chia ching lin
chia ching lin 2020년 12월 4일
@Image Analyst, Can you give me an example of how to done it?

댓글을 달려면 로그인하십시오.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 12월 4일
You could try something like this:
lambda = 400:700; % Wavelengths in nm.
I_of_lambda = % Solar-spectral intensity as a function of wavelength
rgb_of_lambda = % your RGB-colour-map, one tripplet for each wavelength, like yours above
C_of_lambda = ones(size(lambda)); % Relative sensitivity at each wavelength, compare with ccd quantum efficiency. This is jus a placeholder
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);
Img_rgb = zeros([size(X),3]);
% diffraction pattern
for i_lambda = 1:numel(lambda)
% Here we calculate the diffraction-pattern wavelength-by-wavelength, and add their
% contributions to the R, G and B-channels together, one by one.
u=2.*pi.*a./lambda(i_lambda);
J=besselj(1,u.*sin(r));
I=sqrt((u.*((1+cos(r))./2).*(J./sin(r))).^2); % Intensity
Img_rgb(:,:,1) = Img_rgb(:,:,1) + I*rgb_of_lambda(i_lambda,1)*C_of_lambda(i_lambda);
Img_rgb(:,:,2) = Img_rgb(:,:,2) + I*rgb_of_lambda(i_lambda,2)*C_of_lambda(i_lambda);
Img_rgb(:,:,3) = Img_rgb(:,:,3) + I*rgb_of_lambda(i_lambda,3)*C_of_lambda(i_lambda);
end
Img_rgb = Img_rgb/max(Img_rgb(:)); % scale to 0-1
imagesc(X(1,:),Y(:,1),Img_rgb); shading flat; axis image; title('4000 - 7000 Å');
This should give you something to work with. You might have to scale the blue channel up. The colour-balancing in these type of tasks are notoriously confusing due to the characteristics of the colour-vision of our eyes.
HTH

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by