The Images

Definition

An image is considered as an array of pixels. A pixel stores a value or a vector of values at specified coordinates. The various types of image depend on the pixel type and the array dimension.

image.gif

The class Imx2duc.

Types

There are 27 different types of images depending on the spectrum, the dimension and the pixel type. The name of a class is built from the following template:
Im+[g,c,x]+[1d,2d,3d]+[uc,sl,sf]
It results from the concatenation of the prefix Im and each properties of the image with the following conventions:
  1. the spectrum: [g,c,x]
  2. the dimension: [1d,2d,3d]
  3. the type of pixel: [uc,sl,sf]

For example:

Note:
These images can also be named using the C++ template notation:

Hierarchy

Concretely, there are only three types of image:

It means that all the other types are just a rewriting of these actual types. For example:

The major interest is that hierarchy can be used to write generic operator function, Instead of writing one function per Pandore type composition, only one template function had to be written. Such a function looks like the following example:

template <typename T>
Errc function( Imx3d<T> &ims, Imx3d<T> &imd, Float p1 ) {

   return SUCCESS;
}

This unique function can then be called with any image type. For example:

Errc result1, result2;
Img2duc ims1(256,256);
Img2duc ims2(256,256);
Img2dsf ims3(256,256);
Img2dsf ims4(256,256);

result1=function(ims1,ims2,5.0F);
result2=function(ims3,ims4,4.0F);

Public Attributes

Images are characterized by the dimension, the number of bands and the color space. These attribute values are accessible by the way of member functions:

Construction

An image 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, the creation of a 2D gray level image of bytes:

Img2duc ims1(256,512);      // Data: array 256 rows x 512 columns.
Img2duc ims2(ims1.Size());  // Data: array size = ims1 array size.
Img2duc ims3(ims1.Props()); // Data: array size = ims1 array size.
Img2duc ims4;               // No data.
Img2duc *ims5=new Img2duc(256,512); // Data: array size 256x512.
Img2duc *ims6=new Img2duc;  // No data.

For example, the creation of a 2D color image of Float:

Imc2dsf ims7(256,512);  // 256 rows x 512 columns.
im7.ColorSpace(RGB);    // Set the color space to RGB
Imc2dsf *ims8=new Imc2dsf(256,512);
im8->ColorSpace(YUV);   // Set the color space to YUV

For example, the creation of a 3D multispectral image (5 bands) of Long:

Imx2dsl ims9(5,256,512); // 5 bands, 256 rows and 512 columns.
Imx2dsl ims10;           // No data.

Allocation

If the image has been created without data, the member function New() creates the data array -if data already exist they are first deleted. For example:
Img2duc  ims1; ims1.New(256,512);
Img2duc *ims5; ims5->New(256,512);
Img2duc  ims3; ims3.New(ims1.Size());

Warning:
The creation of the data does not initialize pixel values to 0. However, this can simply be done using:
Img2duc ims(256,256);
ims=0;

Allocation from a predefined array

It is possible to allocate the data from a predefined vector. In this case, the destruction is not done with the object. This assumes that the predefined vector have the correct size (eg., number of bands * depth * height * width *sizeof(item) items); For example:

Float *d = (Float*)malloc(3*256*512*sizeof(Float));
Imx2dsf ims1(3,256,512,d);
Imx2dsf *ims2 = new Imx2dsf(3,256,512,d);
ims1.delete();
delete ims2;
free(d);

For example, to process a multispectral image as several gray level images, use:

Imc2duc *ims = new Imc2duc(256,256);
for(b=0;b<ims->Bands();b++){
  Img2duc *imii = new Img2duc(ims.Height(),ims.Width(),ims->Vector(b));
  Img2duc *imio = new Img2duc(imii->Props());
  gauss:PGaussianFiltering(*imii,*imio,2.0F);
  *imii=*imio;
  delete imii;
  delete imio;
}

For example, to process a 3D multispectral image as several 2D grayscale images, use:

Imx3duc *ims= new Imx3duc(3,12,200,256);
for(b=0;b<ims->Bands();b++){
  for(d=0;d<ims->Depth();d++){
    Img2duc *imii = new Img2duc(ims->Height(),ims->Width(),&(*ims)(b,d,0,0));
    Img2duc *imio = new Img2duc(imii->Props());
    gauss:PGaussianFiltering(*imii,*imio,2.0F);
    *imii=*imio;
    delete imii;
    delete imio;
  }
}

Warning:
Unfortunately, it is not possible to process directly a 3D multispectral image as several multispectral images since a 3D multipsctral image is not coded as several 2D multispectral 2D images. It is necessary to copy the required pixel from the 3D image to the 2D images and vice versa with the processed pixels.

Destruction

To delete the data without deleting the object itself, use the member function Delete(). For example:
Img2duc ims3(512,512);
ims3.Delete();
ims3.New(512,245);

Img2duc *ims5=new Img2duc;
ims5->New(512,512);
ims5->Delete();

Consultation

Access to pixel value can be done in three ways:
  1. As a multidimensional array:

  2. As a unique vector:

Setting Data Values

To copy the value of an image into an other image already allocated and with the same size, use operator =. For example:
Img2duc ims1(256,512)
Img2duc *imd1 = new Img2duc(256,512)
ims1=*imd1;

To set a constant to all the pixel values use operator =. For example:

Imx3duc ims(3,12,123,245);
ims=127; // Set 127 to all the pixel values

Warning:
The pixel are directly copied. If the type of the source pixel is different from the destination, the values are casted using the C casting convention. For example:
Img2duc *imd1 = new Img2duc(256,512)
*imd1 = 127;
Img2duc imd2(256,512)
imd2 = 127.5; // Use 127

File Transfer

To save an image in a file, just use:
Img2duc img;
img.SaveFile("foobar.pan");

To load an image from a file, just use:

Img2duc img;
img.LoadFile("foobar.pan");

Miscellaneous

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

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

ims2.Frame(127,5);      // set the border (5x5) with the value 127.
ims2.Frame(ims1,5,6);   // set the border (5x6) with the pixel of the image ims1.

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