This is a good example of the integer midpoint circle algorithm. No pixels are missed or repeated.
Peter Bone (2019). Draw a circle in a matrix / image (https://www.mathworks.com/matlabcentral/fileexchange/14331-draw-a-circle-in-a-matrix-image), MATLAB Central File Exchange. Retrieved .
how could i define 'i'? Thanks
Add the following at the bottom of the MidPoint Circle function to created filled circles
for ii = xc-int16(radius):xc+(int16(radius))
for jj = yc-int16(radius):yc+(int16(radius))
tempR = sqrt((double(ii) - double(xc)).^2 + (double(jj) - double(yc)).^2);
if(tempR <= double(int16(radius)))
This code is extremely useful.
I'm not particularly good in using matlab but i had no trouble understanding how to use it (although it took me a good FIVE minutes).
So Five stars for sure for doing EXACTLY what it says on the box, nothing more and nothing less. You guys should be ashamed for rating less then 5 stars.
For others, to get rid of the gaps I used
FilteredResult=medfilt2(Result, [3 3])
This is how I used this code
(you will now notice i'm no good at matlab)
GGG=medfilt2(GGG, [3 3])
this is a coding to draw a circle.
i using the same code but i looping it with reduce the radius.
let say, my radius is 7, I try looping it by draw radius with 7, and then 6, and then 5 and so on until it become 0. It really fill in a lot of space but the problem is still got some space is empty.
My problem now is I want to fill in all the area inside the circle. So, any idea to solve this problem? Thank you
what value i have to give for the parameter 'value'?
got it working.
i = the pixel value for coordinate (1,1).
radius = radius of the circle.
xc and yc = center coordinate of the circle.
value = the pixel value for the circle.
extra note: the value for xc and yc must be larger than radius.
thanks author, i've been searching for this kind of function.
Can someone fill me in as to how this code works. Also, can it be altered to make an annulus as opposed to just a circle?
It is simple to modify this function to allow circles of both odd & even size (currently the algorithm cannot produce even sized e.g. 8x8 circles). Maybe I'll post up a modified version if that's OK with you?
Excellent, clean implementation. This is the first of over a dozen submissions I've seen that actually uses this algorithm (and they all should). Very nice. Commenting your code would be a nice touch, however...
I need to draw circles in each cell in an intensity matrix that I'm printing. How do I use your code to do so?
Also, I don't understand the parameters that need to be put in the function. Please explain?
When I ran the code, there were some skipped pixels in the drawn circle.
Comments in your code isnt just for coding class, it helps others understand your code
i hope if one till me how to use it, can one tell us i, value stand for what....
agreed! every little tool like this can find its place. very helpful, just what i was looking for
Just what I was looking for and not "boring" at all.
the fact that the reviewer below finds the submission boring is not substantial and certainly does not warrant a poor rating by itself. please, be more considerate.
to the author: the function could be spruced up a bit, eg, an x/y-offset option
no updates. Resubnmitting for license