Amir Ehsan
Amir Ehsan

Reputation: 93

plot circle with gradient gray scale color in matlab

I want to draw a circle with gradient color in matlab, but I can't. Is there any one that can help me?

the sample image can be found here

enter image description here

Upvotes: 4

Views: 3297

Answers (1)

Divakar
Divakar

Reputation: 221574

Here's one approach -

N = 200; %// this decides the size of image
[X,Y] = meshgrid(-1:1/N:1, -1:1/N:1) ;
nrm = sqrt(X.^2 + Y.^2);
out = uint8(255*(nrm/min(nrm(:,1)))); %// output image

figure, imshow(out) %// show image

Output -

enter image description here


If you would like to pad the output with white boundary as shown in the expect output image, you can do so with padarray -

padsize = 50; %// decides the boundary width
out = padarray(out,[padsize padsize],255);

Upvotes: 6

Related Questions