Code covered by the BSD License  

Highlights from
imcircle

4.57143

4.6 | 7 ratings Rate this file 15 Downloads (last 30 days) File Size: 1.66 KB File ID: #128

imcircle

by John T. McCarthy

 

04 Sep 1998 (Updated 29 Jan 2008)

The file develops an "n by n" matrix containing a solid circle of ones of diameter "n" pixels.

| Watch this File

File Information
Description

The file develops an 'n by n' matrix containing a solid circle of ones of diameter 'n' pixels, over a background of zero pixels.
 
Pixel positions are calculated on a nearest-fit basis, using trigonometry.
 
Such a circle can be an image, or part of an image, or an image mask.

A hollow circle (line circle) is also possible.

Acknowledgements
This submission has inspired the following:
Pattern generator for MATLAB, Synthetic Microstructure Generator
MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
15 Dec 2001 Tom McMurray

Thank you for saving me the trouble of coding this deceptively complex function myself.

08 Dec 2002 Michael Bach

A bit shorter and faster:

function [c_mask]=circle(ix,iy,cx,cy,r)
[x,y]=meshgrid(-(cx-1):(ix-cx),-(cy-1):(iy-cy));
c_mask=((x.^2+y.^2)<=r^2);

Mike.

10 Jul 2003 Hamed Zahedi

The other day I spent close to an hour trying to create a circular kernel for a convolution. This function is significantly faster.

08 Dec 2004 Deepak Bijalwan

Thanks for saving my time.

20 Apr 2005 Aaron Mancil

Looks Beautiful

23 Aug 2005 Pratik Kamdar

Thnx..works great

22 Aug 2006 Siyi Deng

Look at the comment Michael Bach left.
I was about to submit my own code before I see Mike already has posted exactly the same codes.

16 Feb 2011 Jason Zhang

Try it

Please login to add a comment or rating.
Updates

modifying description

29 Jan 2008

Up to now, this file generated only a solid circle (disk).

I wish to include an option to have a hollow circle (line circle).

Tag Activity for this File
Tag Applied By Date/Time
image generation John T. McCarthy 22 Oct 2008 06:32:36
image processing John T. McCarthy 22 Oct 2008 06:32:36
imcircle John T. McCarthy 22 Oct 2008 06:32:36
solid circle John T. McCarthy 22 Oct 2008 06:32:36
matrix John T. McCarthy 22 Oct 2008 06:32:36
circle John T. McCarthy 04 Nov 2008 04:45:17

Contact us at files@mathworks.com