10.14. region#

class itom.region#
class itom.region(otherRegion) region
class itom.region(x, y, w, h, type=region.RECTANGLE) region

Creates a rectangular or elliptical region.

This class is a wrapper for the class QRegion of Qt. It provides possibilities for creating pixel-based regions. Furtherone you can calculate new regions based on the intersection, union or subtraction of other regions. Based on the region it is possible to get a uint8 masked dataObject, where every point within the entire region has the value 255 and all other values 0

If the constructor is called without argument, an empty region is created.

Parameters:
otherRegionregion

Pass this object of region to create a copied object of it.

xint

x-coordinate of the reference corner of the region

yint

y-coordinate of the reference corner of the region

wint

width of the region

hint

height of the region

typeint, optional

region.RECTANGLE creates a rectangular region (default). region.ELLIPSE creates an elliptical region, which is placed inside of the given boundaries.

contains(x, y, w=-1, h=-1) bool#

This method returns True, if the given point (x,y) or rectangle (x,y,w,h) is fully contained in this region. Otherwise returns False.

Parameters:
xint

x-coordinate of one corner of the new rectangular region

yint

y-coordinate of one corner of the new rectangular region

wint, optional

width of the new rectangular region. If not given, point is assumed.

hint, optional

height of the new rectangular region. If not given, point is assumed.

Returns:
bool

True if point or rectangle is contained in region, otherwise False.

createMask(boundingRegion=None) dataObject#

Returns a dataObject with dtype uint8 whose shape corresponds to the width and height of the bounding rectangle. All pixels contained in the region have a value of 255 while the rest is set to 0. The offset value of the dataObject is set such that it fits to the real position of the region, since the first element in the dataObject corresponds to the left upper corner of the bounding rectangle.

Indicate a boundingRegion in order to increase the size of the returned data object. Its size will have the size of the union between the boundingRegion and the region.

Parameters:
boundingRegionregion, optional

If a region object is given, the shape of the returned dataObject is the maximum (union) between this boundingRegion and this region.

Returns:
maskdataObject
intersected(x, y, w, h) region#
intersected(region) region

Returns a new region which is the intersection of the given region and this region.

The intersection only contains points that are part of both regions. The given region can either by a region object or a rectangular region, defined by its corner points (x, y) and its width w and height h.

Parameters:
xint

x-coordinate of one corner of the new rectangular region

yint

y-coordinate of one corner of the new rectangular region

wint

width of the new rectangular region

hint

height of the new rectangular region

regionregion

another instance of region

Returns:
region

new intersected region.

intersects(x, y, w, h) bool#
intersects(region) bool

Returns True if this region intersects with the given region, otherwise False.

The given region can either by a region object or a rectangular region, defined by its corner points (x, y) and its width w and height h.

Parameters:
xint

x-coordinate of one corner of the new rectangular region

yint

y-coordinate of one corner of the new rectangular region

wint

width of the new rectangular region

hint

height of the new rectangular region

regionregion

another instance of region

Returns:
bool

True if both regions intersect, otherwise False.

subtracted(x, y, w, h) region#
subtracted(region) region

This method returns a new region, which is the given, new region subtracted from this region.

The given region can either by a region object or a rectangular region, defined by its corner points (x, y) and its width w and height h.

Parameters:
xint

x-coordinate of one corner of the new rectangular region

yint

y-coordinate of one corner of the new rectangular region

wint

width of the new rectangular region

hint

height of the new rectangular region

regionregion

another instance of region

Returns:
region

new, subtraced region.

translate(x, y)#

This method translates this region by the given translation values.

Parameters:
xint

translation in x-direction

yint

translation in y-direction

See also

translated
translated(x, y) region#

This method returns a new region, which is translated by the given distances in x and y direction.

Parameters:
xint

translation in x-direction

yint

translation in y-direction

Returns:
region

new translated region.

See also

translate
united(x, y, w, h) region#
united(region) region

returns a region which is the union of the given region with this region.

This method returns a new region, which is the union of this region with the given region. The union contains all areas, that are contained in any of both regions.

The given region can either by a region object or a rectangular region, defined by its corner points (x, y) and its width w and height h.

Parameters:
xint

x-coordinate of one corner of a rectangular region

yint

y-coordinate of one corner of a rectangular region

wint

width of the new rectangular region

hint

height of the new rectangular region

regionregion

another instance of region

Returns:
region

new united region.

xored(x, y, w, h) region#
xored(region) region

returns a region which is an xor combination of the given region with this region.

This method returns a new region, which is defined by an xor-combination of this region with the given region.

The given region can either by a region object or a rectangular region, defined by its corner points (x, y) and its width w and height h.

Parameters:
xint

x-coordinate of one corner of a rectangular region

yint

y-coordinate of one corner of a rectangular region

wint

width of the new rectangular region

hint

height of the new rectangular region

regionregion

another instance of region

Returns:
region

new xored region.

ELLIPSE = 1#
RECTANGLE = 0#
boundingRect#

list of int or None : Returns the bounding rectangle of this region or None if it is empty.

The bounding rectangle is given by a list (x, y, width, height).

empty#

bool : Returns True if this region is empty, otherwise False

rectCount#

int : Returns the number of rectangles in this region

rects#

list of list of int : Returns list of rectangles, whose union defines this region.

Each rectangle is given by a list of (x, y, width, height).