[iacomb] [Up] [iaroi] Image Creation

iarectangle
Create a binary rectangle image.

Synopsis

g = iarectangle( s, r, c )

Implemented in Python.

Input

s Image. Gray-scale (uint8 or uint16) or binary image (logical).

[rows cols], output image dimensions.

r Double. Non-negative integer.

[rrows ccols], rectangle image dimensions.

c Image. Gray-scale (uint8 or uint16) or binary image (logical).

[row0 col0], center of the rectangle.

Output

g Image. Binary image (logical).

Description

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

Examples

>>> F = iarectangle([7,9], [3,2], [3,4])

              
>>> print F
[[0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0]
 [0 0 0 1 1 0 0 0 0]
 [0 0 0 1 1 0 0 0 0]
 [0 0 0 1 1 0 0 0 0]
 [0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0]]

>>> F = iarectangle([200,300], [90,120], [70,120])

              
>>> iashow(F)
(200, 300) Min= 0 Max= 1 Mean=0.180 Std=0.38
F

Equation

Source Code

def iarectangle(s, r, c):
    rows,  cols  = s[0], s[1]
    rrows, rcols = r[0], r[1]
    y0,    x0    = c[0], c[1]
    x, y = iameshgrid(range(cols), range(rows))
    min_row, max_row = y0-rrows/2.0, y0+rrows/2.0
    min_col, max_col = x0-rcols/2.0, x0+rcols/2.0
    g1 = (min_row <= y) & (max_row > y)
    g2 = (min_col <= x) & (max_col > x)
    g = g1 & g2
    return g
    

See also

iacircle Create a binary circle image.
[iacomb] [Up] [iaroi] http://www.python.org