Plot a circle of desired intensity.

조회 수: 3 (최근 30일)
Jose Aroca
Jose Aroca 2020년 6월 11일
댓글: Image Analyst 2020년 6월 12일
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
darova
darova 2020년 6월 12일
Do you know how to draw a circle?

댓글을 달려면 로그인하십시오.

채택된 답변

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?
Image Analyst
Image Analyst 2020년 6월 12일
See my attached demo. Adapt as needed.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by