Effacer les filtres
Effacer les filtres

How can I change this gabor patch so that the color of the outer circles fade away

1 vue (au cours des 30 derniers jours)
% Animates sinusoidal concentric grating
clear all;
n=100;
M=moviein(n); % for Matlab movie animation
f=1000; % frequency
w=2*pi*f;
t=linspace(pi/15/w,2*pi/w,100); %30 time steps per period
c=800;
k=w/c;
a=0.1; % sphere radius
x=linspace(-2,2,100); % 4 m x 4 m area, with 100 points
y=linspace(-2,2,100);
for m=1:100
for l=1:100
r(m,l)=sqrt((x(m)^2)+(y(l)^2));
if r(m,l)>=a
pt(m,l)=exp(1i*k*(r(m,l)-a))/r(m,l);
else
pt(m,l)=1/a; % for visualization purposes
%if r(m,l)>=1
end
end
end
pmag=sqrt((abs(pt))); % 1/4 power of amplitude for better contrast
pphase=angle(pt);
clim=max(max(pmag));
V=[-clim clim]; % sets color scheme
pt=pmag.*exp(1i*pphase); % red: maximum positive
% blue: minimum negative pressure
figure(1)
axis equal % to eliminate distortion
axis([-2 2 -2 2])
for l=1:100
pt2=real(pt*exp(-1i*w*t(l)));
h=pcolor(x,y,pt2);
colormap(gray(100))
axis equal
xlabel('x');
ylabel('y');
shading interp;
%caxis(V);
axis([-2 2 -2 2])
M(:,l)=getframe;
%
% filnme=strcat('spher',int2str(l));
% eval(['print -dbitmap ' filnme ' -f']);
end
Hello,
I am currently working on my bachelor thesis and I need to modify this code in order to get the color of the outer circles fade away.
Maybe someone got an idea on how to tackle this problem.
Thanks in advance!

Réponses (1)

Abhinaya Kennedy
Abhinaya Kennedy le 9 Oct 2023
Hello Denis,
I understand that you need to modify your code to get the colour of the outer circles to fade away.
The 'Alpha' property allows you to add transparency to objects in axes. Here is the modified code.
clear all;
n = 100;
M = moviein(n); % for Matlab movie animation
f = 1000; % frequency
w = 2 * pi * f;
t = linspace(pi / 15 / w, 2 * pi / w, 100); % 30 time steps per period
c = 800;
k = w / c;
a = 0.1; % sphere radius
x = linspace(-2, 2, 100); % 4 m x 4 m area, with 100 points
y = linspace(-2, 2, 100);
for m = 1:100
for l = 1:100
r(m, l) = sqrt((x(m)^2) + (y(l)^2));
if r(m, l) >= a
pt(m, l) = exp(1i * k * (r(m, l) - a)) / r(m, l);
else
pt(m, l) = 1 / a; % for visualization purposes
end
end
end
pmag = sqrt((abs(pt))); % 1/4 power of amplitude for better contrast
pphase = angle(pt);
clim = max(max(pmag));
V = [-clim clim]; % sets color scheme
pt = pmag .* exp(1i * pphase); % red: maximum positive
% blue: minimum negative pressure
figure(1)
axis equal % to eliminate distortion
axis([-2 2 -2 2])
for l = 1:100
pt2 = real(pt * exp(-1i * w * t(l)));
% Fade the color of outer circles
colorFade = 1 - r / max(max(r));
h = pcolor(x, y, pt2);
colormap(gray(100))
axis equal
xlabel('x');
ylabel('y');
shading interp;
%caxis(V);
axis([-2 2 -2 2])
% Apply color fade to the plot
set(h, 'FaceAlpha', 'interp', 'AlphaData', colorFade);
M(:, l) = getframe;
end
In this modified code, the 'colorFade' variable is introduced to control the fading of color based on the distance from the center. The color fade is calculated as 1 - r / max(max(r)), where 'r' represents the distance from the center of the circles. The 'AlphaData' property of the plot is then set to 'colorFade' to apply the fading effect.
Adjust the code according to your specific requirements and preferences to achieve the desired fading effect on the outer circles of the Gabor patch.
Here is a link to find out more about the 'Alpha' property: https://www.mathworks.com/help/releases/R2023a/matlab/ref/alpha.html?s_tid=doc_srchtitle
Hope this answers your queries.

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by