Plot a circle of desired intensity.

2 vues (au cours des 30 derniers jours)
Jose Aroca
Jose Aroca le 11 Juin 2020
Commenté : Image Analyst le 12 Juin 2020
I have the following code to draw a white square on a black background. The intensity of the square can be varied from 0 to 256 from black to white.
backg = uint8(zeros(500,500,3));%produce 500x500 px background
for x = 200:1:300; %define x limits of square
for y = 200:1:300; %define y limits of square
backg(x,y,:) = 256; %choose intensity
end;
end;
image(backg);
I would like to use the same code to plot a circle, but I get errors related to array indices.
Many thanks.
  1 commentaire
darova
darova le 12 Juin 2020
Do you know how to draw a circle?

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 12 Juin 2020
Adapt as needed (center location, radius, intensity, etc.).
  2 commentaires
Jose Aroca
Jose Aroca le 12 Juin 2020
Yeah, I saw that before. However, I want a circle in which the intensity can be varied. I developed this code in which the intensity can be varied according to the radius.
imagelength=100;
middle=(imagelength+1)/2;
radius=20;
dimmerRadius=15;
brightness=256;
dimmerBrightness=150;
image=ones(imagelength);
for i=1:imagelength
x=-imagelength+middle+i; %change y coordinate by adding term
for j=1:imagelength
y=-imagelength+middle+j; %change x coordinate by adding term
if(x^2+y^2<=radius^2) %equation of desired shape
image(i,j)=brightness;
end
if(x^2+y^2<=dimmerRadius^2)
image(i,j)=dimmerBrightness;
end
end
end
imagesc(image)
axis square
axis off
colormap gray
caxis([1 256])
However, I want the intensity to vary as a Gaussian, ie. to be maximum at the centre and tail off as r is increased. Any ideas?
Image Analyst
Image Analyst le 12 Juin 2020
See my attached demo. Adapt as needed.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Orange dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by