Region

Description

A region is a set of pixel locations, or an optimized representation of a binary image.

Technically, a region is defined by its FrameWidth, FrameHeight and a run-length encoded list of (x, y) of type Location.

An image of a blade.

The region corresponding to the object of the blade.

Regions are typically used to identify sets of pixels corresponding to some objects within an image. This information can be used for high-level information retrieval (so called Region Analysis) or as a parameter of some further image processing operations constrained to this particular set of pixels.

Remarks

  • Connected components within regions are called blobs.
  • Most of image processing operations have an optional inRoi (Region of Interest) input.
  • Regions can be automatically converted to images without any loss of information.
  • Images can be manually converted to regions using the ThresholdToRegion filter.
  • Maximum region frame dimensions are 65536 x 65536.

Requirements

  • Technically, the compressed representation of a region is a list of so called point-runs. A point-run consist of three 16-bit unsigned integers: X, Y and Length, and represents a horizontal sequence of consecutive pixel locations.
  • Point-runs in a region must be sorted by Y and X coordinates (in this order), and must be guaranteed not to overlap and not to exceed the region frame dimensions (0..FrameWidth-1, 0..FrameHeight-1).
  • It is also not allowed to create a region with two point-runs that could be merged into a single one.

Excerpt from class defining a single PointRun in Region

// Single horizontal sequence of pixel locations
class PointRun
{
public:
	uint16      x, y; // PointRun begin location
	uint16      length;    

	Location    Begin()  const;
	Location    End()    const;
	int         Length() const;

	int         X()      const;
	int         Y()      const;
};

Excerpt from Region class listing:

 // Compressed binary mask.
class Region : public RegionFrame, public Array< PointRun >
{
public:
	int          FrameWidth() const;
	int          FrameHeight() const;
	Box          Frame() const;
	int          Size() const;
	void         Reserve( int newCapacity );
	PointRun*    Begin();
	PointRun*    End();
	const PointRun*    Begin()   const;
	const PointRun*    End()     const;

	PointRun     Run   ( int k ) const;
	Location     Begin ( int k ) const;
	Location     End   ( int k ) const;
	int          Length( int k ) const;

	void         SetFrameWidth ( int frameWidth_  );
	void         SetFrameHeight( int frameHeight_ );
	void         SetFrame( int frameWidth_, int frameHeight_ );
			
	void         Add( const PointRun& pr );
	void         Add( int x, int y, int len );
	void         Add( const Location& begin, int len );
};

Methods:

  • void Add( const PointRun& pr ) - adds specified PointRun to Region without additional sorting and location checking.
  • void Add( int x, int y, int len ) - adds new PointRun created from x, y and len to Region without additional sorting and location checking. All parameter values must be from [0, 65535] interval.
  • void Add( const Location& begin, int len ) - creation and adding of new a PointRun using its Location and length to Region without additional sorting and location checking.
  • SetFrameWidth, SetFrameHeight, SetFrame - changing Region's frame without invalidating internal PointRuns.