How to generate sinusoidal color fringes in MATLAB??

조회 수: 5 (최근 30일)
LALITHA SREE
LALITHA SREE 2023년 3월 17일
댓글: LALITHA SREE 2023년 3월 18일
Hi. I am new to MATLAB, Can any one help me in getting the solution. I'm attempting to generate sinusoidal color fringe patterns, using MATLAB.
I'm struggling to find a way in which i can go about generating color fringes as shown in the below figure.
Any help would be appreciated,
Thanks.

채택된 답변

DGM
DGM 2023년 3월 17일
편집: DGM 2023년 3월 17일
It's not clear to me how these are sinusoidal or even periodic.
You can simply create an image like the one shown, but if you want some particular calculated pattern, it's up to you to explain the thing you're trying to create.
CT = [1 0 0; 0 1 0; 0 0 1]; % a colormap
% generate indexed color image as a vector
fringe = [3 1 2 1 3 2 3 1 2 3 1 2 3 1 3 2 1 2 3 1 2 3 2 1 2 3 1 3 2 3 1 3 1 2];
% expand the vector into a 2D image
blocksize = [50 10]; % [y x]
fringe = imresize(fringe,blocksize.*size(fringe,1:2),'nearest');
% convert to RGB
fringe = ind2rgb(fringe,CT);
% show it
imshow(fringe)
  댓글 수: 5
DGM
DGM 2023년 3월 17일
편집: DGM 2023년 3월 17일
Oh. So something more like this:
% parameters
center = [0,0]; %[0,0] is the middle of the image, [pi,pi] is the lower right
orientation = pi; %radians (pi/4 = 45 degrees)
width = .5; %1/e half width of Gaussian
spatialFrequency = 10; %spatial frequency of Sinewave carrier (cycles/image)
phase = pi; %spatial phase of sinewave carrier (radians)
contrast = 1; %contrast ranges from 0 to 1;
n = 201; %resolution of the image
[X,Y] = meshgrid(linspace(-pi,pi,n)); % Use meshgrid to define matrices X and Y that range from -pi to pi;
ramp = cos(orientation)*(X-center(1)) + sin(orientation)*(Y-center(2));
sinusoid1 = contrast*sin(spatialFrequency*ramp-phase);
phase2 = pi/2;
sinusoid2 = contrast*sin(spatialFrequency*ramp-phase2);
phase3 = 2*pi;
sinusoid3 = contrast*sin(spatialFrequency*ramp-phase3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% create the grating images as RGB images
Rgrating = (sinusoid1 + 1)/2.*permute([1 0 0],[1 3 2]);
Ggrating = (sinusoid2 + 1)/2.*permute([0 1 0],[1 3 2]);
Bgrating = (sinusoid3 + 1)/2.*permute([0 0 1],[1 3 2]);
sumgrating = Rgrating + Ggrating + Bgrating;
montage({Rgrating, Ggrating, Bgrating, sumgrating})
Or if you didn't need the individual gratings for anything else, you could simplify everything:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% create the final grating image without the individual colored gratings
sumgrating = (cat(3,sinusoid1,sinusoid2,sinusoid3)+1)/2;
imshow(sumgrating)
LALITHA SREE
LALITHA SREE 2023년 3월 18일
@DGM Thank you, It is very helpful.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by