How to generate sinusoidal color fringes in MATLAB??
17 views (last 30 days)
Show older comments
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 want to generate sinusoidal fringes each with a single color like Red, Green, and Blue with different phases. And add these different patterns to form a single fringe pattern.
i tried the below code, but i don't want to use colormap here. If i use colormap, while adding i am unable to get colored fringes as Red, Blue, Green. can you please check the below code, it would be helpful.
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.
if i add three fringes, i want to get output like this......

Thanks....
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);
figure(1)
imagesc(sinusoid1)
mymap1 = [1 0 0
1 1 1
1 0 0
1 1 1
1 0 0];
colormap(mymap1);
axis off;axis equal ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
phase2 = pi/2;
sinusoid2= contrast*sin(spatialFrequency*ramp-phase2);
figure(2)
imagesc(sinusoid2)
mymap2 = [0 1 0
1 1 1
0 1 0
1 1 1
0 1 0];
colormap(mymap2);
axis off; axis equal;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
phase3 = 2*pi;
sinusoid3= contrast*sin(spatialFrequency*ramp-phase3);
figure(3)
imagesc(sinusoid3)
mymap3 = [0 0 1
1 1 1
0 0 1
1 1 1
0 0 1];
colormap(mymap3)
axis off; axis equal;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% adding all three color fringes
addedgrating= sinusoid1+sinusoid2+sinusoid3;
figure(4);
imagesc(addedgrating);
axis off; axis equal;
Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


