How do I change from Square to CIrcle?

This fresnel diffraction simulation for a square aperture. I need to change it to work with a circle aperture. I need to help to change this step:
u0(257-w*20:256+w*20,257-w*20:256+w*20)=1; % setup aperture
This for a square and how i convert it to a circle?
Thank you.
The code is:
2d propagation from square apertures
ii=sqrt(-1) lambda= .365; % wavelenght [µm] z=1; % distance [µm] w=1; % width of slit is 2*w [µm]
x=-12.75:0.05:12.8; % setup spatial axis [µm] freqx=-10:20/512:10-1/512; % setup frequency axis [1/µm] freqy=freqx;
u0=zeros(512); % field at z=0 a0=zeros(512); % angular spectrum at z=0 H=zeros(512); % transfer function az=zeros(512); % angular spectrum at z=z uz=zeros(512); % field at z=z
for nx=1:512 % setup transfer function for ny=1:512 H(nx,ny)=exp(ii*2*pi*(z/lambda)*... sqrt(1-(lambda*freqx(nx))^2-(lambda*freqy(ny))^2)); end end
u0(257-w*20:256+w*20,257-w*20:256+w*20)=1; % setup aperture a0=(fftshift(fft2(u0))); % fourier transform az=a0.*H; % multiply with transfer function uz=ifft2(fftshift(az)); % inverse fourier transform p=uz.*conj(uz);
figure(1) plot(x, p(:,256)); % plot of cross-section of intensity at z xlabel('x'); ylabel('I');
figure(2) imagesc(x, x, p); %diffraction pattern at z xlabel('x'); ylabel('y'); colormap(gray); colorbar;

 Risposta accettata

Image Analyst
Image Analyst il 3 Mag 2014
See code examples for creating a circle in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F. You can adapt them as needed.

8 Commenti

Dina Abd El-twab
Dina Abd El-twab il 14 Mar 2020
Modificato: Dina Abd El-twab il 14 Mar 2020
Can I convert this rectangle to be a circle and show the circle on the image ?
Start a new question on this if you still have questions after looking at the documentation for viscircles(). And say what you know, like did you know the (x, y, width, height) of the rectangle.
viscircles([x+width/2, y+height/2], mean([width, height]));
Dina's "Answer" moved here since it's a reply to me, not an Answer to the original question:
How can I calculate the width and height of the rectangle in this image automatically?
Well how did you draw the rectangle on there in the first place? If you didn't do it, then who did? And could you get the coordinates from them? If not, you can get it from the image by taking a mask of the rectangle.
I didn't understand ,how can i make a mask to the rectangle ? could you clarify please
Where is your new question (so we don't keep sending Maitham emails)? Your link above no longer works.
yellowMask = rgbImage(:,:,1) == 255 & rgbImage(:,:,2) == 255 & rgbImage(:,:,3) == 0;
yellowMask = imfill(yellowMask, 'holes');
yellowMask = bwareafilt(yellowMask, 1);
props = regionprops(yellowMask, 'Centroid', 'EquivDiameter');
viscircles(props.Centroid, props.EquivDiameter/2);
this code didn't give me what i want ,could you please open this link , Iam gonna attach what happened in this link now to contact there

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by