Plot a circle of desired intensity.

2 次查看(过去 30 天)
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.

采纳的回答

Image Analyst
Image Analyst 2020-6-12
Adapt as needed (center location, radius, intensity, etc.).
  2 个评论
Jose Aroca
Jose Aroca 2020-6-12
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by