Reputation: 93
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
Upvotes: 4
Views: 3297
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 -
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