The class Imx2duc.
Im+[g,c,x]+[1d,2d,3d]+[uc,sl,sf]
Im
and each properties of the image with the following conventions: For example:
Imx2duc:
multispectral, 2D image of tiny integers;Img3dsf:
gray level, 3D image of reals;Imc2dsl:
color, 2D image of long signed integer.
Imx2d<Uchar>
: multispectral, 2D image of tiny integers;Img3d<Float>
: gray level, 3D image of reals;Imc2d<Long>
: color, 2D image of long signed integer.Imx3duc
or Imx3d<Uchar>
;Imx3dsl
or Imx3d<Long>
;Imx3dsf
or Imx3d<Float>
.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);
Long Width()
: returns the number of columns;Long Height()
: returns the number of rows;Long Depth()
: returns the number of planes;Dimension2d Size()
: returns the size as a dimension;Long Bands()
: returns the number of bands (eg. 3 for color image, 1 for gray level image);int VectorSize()
: returns the size of the data vector for one band (ie. the number of pixels per bands);PColorSpace ColorSpace([x])
: returns (if x is omitted) or set (if x is given) the color space of a color image among: {RGB, XYZ, LUV, LAB, HSL, AST, I1I2I3, LCH, WRY, RNGNBN, YCBCR, YCH1CH2, YIQ, YUV}.PobjectProps Props()
: returns a structure with the image attribute values.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.
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());
Img2duc ims(256,256); ims=0;
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; } }
Delete()
. For example: Img2duc ims3(512,512);
ims3.Delete();
ims3.New(512,245);
Img2duc *ims5=new Img2duc;
ims5->New(512,512);
ims5->Delete();
ims1(i,j)=15; (*ims4)(i,j)=15; Point2d pt(10,20); ims1[pt]=15;
Imx2duc ims8, *ims9;
ims8(b,i,j)=15; // b the band number.
(*ims9)(b,i,j)=15;
Point2d pt; ims8(b,pt)=15;
ims6.X(i,j)=15; ims6.Y(i,j)=10; ims6.Z(i,j)=14; ims7->X(i,j)=15; ims7->Y(i,j)=10; ims7->Z(i,j)=14; Point2d pt; ims6.X[pt]=15; ims6.Y[pt]=10; ims6.Z[pt]=14;
Img2dsl ims(256,512);
for (Ulong *p=ims.Vector(); p<ims.Vector()+ims.VectorSize();)
*p++ = 15;
Imx2dsl imx(ims.Size()); for (int b=0; b<imx.Bands(); b++) { for (Long *ps=imx.Vector(b); ps<imx.Vector(b)+imx.VectorSize();) *ps++= 127;
Imc2dsl imc(ims.Size()); Long *q=imc.VectorX(); Long *r=imc.VectorY(); Long *t=imc.VectorZ(); for (int i=0; i< imc.VectorSize();i++) *q++ = *r++ = *t++ = 127;
=
. 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
Img2duc *imd1 = new Img2duc(256,512) *imd1 = 127; Img2duc imd2(256,512) imd2 = 127.5; // Use 127
Img2duc img;
img.SaveFile("foobar.pan");
To load an image from a file, just use:
Img2duc img;
img.LoadFile("foobar.pan");
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.