The Region Maps

Definition

A region map is an image of labels. A region is defined by a set of connected labels with the same value. Each pixel in a region map stores a label which is a Ulong value (long unsigned integer). This means that a region map can store 4294967294 different regions.
Note:
By pure convention, label 0 is considered as a non region.
Concretely, a region map is represented by an Img2dul image (image with Ulong pixels). It implies that all image member functions are applicable to a region map.

region.gif

The class Reg2d.

Types

There are 3 different types of region map according to the dimension:

Public Attributes

A region map is first of all a Ulong image plus an attribute that indicates the value of the higher label. These attribute values are accessible by the way of member functions:

Construction

A region map can be created with or without the related data. If the dimension is not given with the constructor, then the data is not allocated. For example, creation of a 2D region map can be done as follows:
Reg2d rgs1(256,512);      // Data: 256 rows, 512 columns
Reg2d rgs2(rgs1.Size()); // Data: same size than rgs1
Reg2d rgs3;               // No data
Reg2d *rgs4=new Reg2d;    // No data 

The creation of a region map from the properties of an other Pandore object can be done by using:

Reg2d rgs1(ims2.Props()); // same size than ims1

Allocation

If the region map has been created without data, the member function New() creates the data array -if data already exist they are first deleted. For example:
Reg2d  rgs3; rgs3.New(256,512);
Reg2d *rgs4; rgs4->New(256,512);

Warning:
The creation of the data does not initialized pixel values to 0. However, this can simply be done using:
Reg2d rgs(256,256);
rgs = 0;        // This also sets Labels(0).
rgs = 127;      // This also sets Labels(127).

Allocation from a predefined array

It is possible to allocate the data from a predefined vector:
Ulong *d = (Ulong*)malloc(128*256*sizeof(Ulong));
Reg2d rgs1(256,128,d);
Reg2 *rgs2 = new Reg2(256,128,d);
rgs1.delete();
delete rgs2;
free(d);

Warning:
In this case, the destruction is not done with the object.
For example, to process a 3D region map as several 2D region maps:
Reg3d *rgs= new Reg3d(12,200,256);
for(d=0;d<rgs->Depth();d++) {
 Reg2d *regii=new Reg2d(rgs->Height(),rgs->Width(),&(*rgs)(d,0,0));
 Reg2d *regio = new Reg2d(regii->Props());
 gauss:Gauss(*regii,*regio,2.0F);
 *regii=*regio;
 delete regii;
 delete regio;
}

Destruction

To delete the data of a region map without deleting the region map itself, use the member function Delete(). For example:
Reg2d rgs1(120,245);
rgs1.Delete();
Reg2d rgs4 = new Reg2d(120,245);
rgs4->Delete();
rgs4->New(400,200);

Consultation

Access to label value can be done in three ways:
  1. As a multidimensional array (depth,row,column):
    rgs1(i,j)=15;
    (*rgs4)(i,j)=15;
    Point2d pt(10,20);
    rgs1[pt]=15;
    
  2. As a unique vector: Vector()
    Reg2d rgs(256,512);
    for (Ulong *p=rgs.Vector(); *p< rgs.Vector()+rgs.VectorSize();)
       *p++ = 15;
    

  3. As a separate multidimensional array: X()
    Reg2d reg1(10,20);
    Reg3d reg2(123,124,120);
    ULong **d=reg1.X();
    Ulong ***d1=reg2.X();
    

File Transfer

To save a region map in a file, just use:
Reg2d reg;
reg.SaveFile("foobar.pan");

To load an region map from a file, just use:

Reg2d reg;
reg.LoadFile("foobar.pan");

Miscellaneous

The member function Hold() tests whether a point is in or out of the region map boundary. For example:
Reg2d rgs(100,200);
Point2d p(-1,-1);
rgs.Hold(p);            // returns false;
rgs.Hold(5,10);         // returns true;
rgs.Hold(10,199);       // returns true;
rgs.Hold(10,200);       // returns false;

The member function Frame() sets the border of the region with a given value or with the pixel of a given region. For example:

rgs2.Frame(127,5);      // set the border (5x5) with the value 127.
rgs2.Frame(rgs1,5,6);   // set the border (5x6) with the pixel of the region rgs1.

The Pantheon project
Image Team GREYC Laboratory
UMR CNRS 6072 - ENSICAEN - University of Caen, France
This page was last modified on 19 June 2015