Function iacircle

Synopse

Create a binary circle image.

  • g = iacircle(s, r, c)
    • g: Image.
    • s: Image. [rows cols], output image dimensions.
    • r: Double. radius.
    • c: Image. [row0 col0], center of the circle.
1. from numpy import *
2. 
3. def iacircle(s, r, c):
4. 
5.     rows, cols = s[0], s[1]
6.     rr0,  cc0  = c[0], c[1]
7.     rr, cc = meshgrid(range(rows), range(cols), indexing='ij')
8.     g = (rr - rr0)**2 + (cc - cc0)**2 <= r**2
9.     return g

Description

Creates a binary image with dimensions given by s, radius given by r and center given by c. The pixels inside the circle are one and outside zero.

Examples

Example 1

1. from ia636 import iacircle
2. 
3. F = iacircle([5,7], 2, [2,3])
4. print F.astype(int)
[[0 0 0 1 0 0 0]
 [0 0 1 1 1 0 0]
 [0 1 1 1 1 1 0]
 [0 0 1 1 1 0 0]
 [0 0 0 1 0 0 0]]

Example 2

1. F = iacircle([200,300], 90, [100,150])
2. adshow(F)

Equation