9.14. region

class itom.region([x, y, w, h[, type=region.RECTANGLE]]) → creates a rectangular or elliptical region.

Bases: object

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

Parameters

x : {int}

x-coordinate of the reference corner of the region

y : {int}

y-coordinate of the reference corner of the region

w : {int}

width of the region

h : {int}

height of the region

type : {int}, optional

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

Notes

It is also possible to create an empty instance of the region.

contains(x, y, w=- 1, h=- 1) → returns True if the given point or rectangle is fully contained in this region, otherwise returns False.

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

Parameters

x : {int}

x-coordinate of one corner of the new rectangular region

y : {int}

y-coordinate of one corner of the new rectangular region

w : {int}, optional

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

h : {int}, optional

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

Returns

True or False :

createMask(boundingRegion=None) → creates mask data object based on this region and the optional boundingRegion.

Returns a uint8-dataObject whose size 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.

intersected(x, y, w, h | region) → returns a region which is the intersection of a new region and this region.

This method returns a new region, which is the intersection of this region and the given, new region. The intersection only contains points that are part of both given regions.

Parameters

x : {int}

x-coordinate of one corner of the new rectangular region

y : {int}

y-coordinate of one corner of the new rectangular region

w : {int}

width of the new rectangular region

h : {int}

height of the new rectangular region

region : {region-object}

another instance of region

Returns

new intersected region. :

Notes

You can either use the parameters ‘x’,’y’,’w’,’h’ OR ‘region’.

intersects(x, y, w, h | region) → returns True if this region intersects with the given region, else False.

This method returns True, if this region intersects with the new region, otherwise returns False.

Parameters

x : {int}

x-coordinate of one corner of the new rectangular region

y : {int}

y-coordinate of one corner of the new rectangular region

w : {int}

width of the new rectangular region

h : {int}

height of the new rectangular region

region : {region-object}

another instance of region

Returns

True or False :

Notes

You can either use the parameters ‘x’,’y’,’w’,’h’ OR ‘region’.

subtracted(x, y, w, h | region) → returns a region which is the new region subtracted from this region.

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

Parameters

x : {int}

x-coordinate of one corner of the new rectangular region

y : {int}

y-coordinate of one corner of the new rectangular region

w : {int}

width of the new rectangular region

h : {int}

height of the new rectangular region

region : {region-object}

another instance of region

Returns

new subtracted region. :

Notes

You can either use the parameters ‘x’,’y’,’w’,’h’ OR ‘region’.

translate(x, y) → translateds this region by the given coordinates.

This method translates this region by the given coordinates.

Parameters

x : {int}

translation in x-direction

y : {int}

translation in y-direction

See also

translated

translated(x, y) → returns a region, translated by the given coordinates.

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

Parameters

x : {int}

translation in x-direction

y : {int}

translation in y-direction

Returns

new translated region. :

See also

translate

united(x, y, w, h | 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 region given as parameters. Union means that all values, that are contained in any of both regions is part of the overall region, too.

Parameters

x : {int}

x-coordinate of one corner of a rectangular region

y : {int}

y-coordinate of one corner of a rectangular region

w : {int}

width of the new rectangular region

h : {int}

height of the new rectangular region

region : {region-object}

another instance of region

Returns

new united region. :

Notes

You can either use the parameters ‘x’,’y’,’w’,’h’ OR ‘region’.

xored(x, y, w, h | 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 region given as parameters.

Parameters

x : {int}

x-coordinate of one corner of a rectangular region

y : {int}

y-coordinate of one corner of a rectangular region

w : {int}

width of the new rectangular region

h : {int}

height of the new rectangular region

region : {region-object}

another instance of region

Returns

new xored region. :

Notes

You can either use the parameters ‘x’,’y’,’w’,’h’ OR ‘region’.

boundingRect

Returns (x,y,w,h) of the bounding rectangle of this region. An empty region returns None.

empty

Returns True if region is empty, else False

rectCount

Returns True if region is empty, else False

rects

Returns list of rectangles