 Population Image processing library in C++
Some basic definitions

# Function definition

The idea of a function, , as a matrix, is that the input quantity completely determines the output quantity. The input quantity belongs to a space and the output to a space : with a subset of that is the domain of definition of the function.

# Matrix definition

A matrix (e.g. an image) is a special case of a Function:

• : a matrix is a regular tessellation of a domain of the n-dimensional euclidean space where each cell is a n-square (a square in 2-dimension called pixel, a cube in 3-dimension called voxel). A cell is located with n integers. In 2d, we have 2 integers representing the i-th row and the j-th column in the matrix convention (so ). In 3d, 3 integers representing the i-th row, the j-th column, and the k-th depth. The domain of definition is the number of rows and columns of a matrix.
• : To access the pixel value, we call the function f(i,j). For a grey-level matrix, this value is a grey-level. This grey-level is usually coded in one byte representing the range (0, 28 −1) = (0, 255) where the value 0 represents the black colour, 255 the white colour, and any value between (0, 255) a fraction between both colours. Left: 2D matrix with 6 rows and 5 columns with a pixel type coded in one byte, right: grey-level representation

# MatN data-structure

The templated matrix class, MatN<Dim,PixelType>, (see Mat{2,3}{UI8,RGBUI8}) is written in generic programming with template parameters. The first one is the dimension, the second one the pixel/voxel type. For a ready-to-use utilisation, we use some typedef declarations to define the usual types to allow coding in C-style as these ones:

• Mat2UI8: a 2d matrix with a pixel type coded in 1 byte for an unsigned integer between 0 and 255, (Mat2UI8=MatN<2,UI8>)
• Mat2RGBUI8: a 2d matrix with a pixel type coded with a RGB{UI8,F32} color with 1 byte per channel, (Mat2UI8=MatN<2,RGBUI8>)
• Mat2F32: a 2d matrix with a pixel type coded in float type,
• Mat2UI16: a 2d matrix with a pixel type coded in unsigned integer in 2 bytes,
• Mat3UI8: a 3d matrix with a pixel type coded in 1 byte for an unsigned integer between 0 and 255.

# Accessing pixel intensity values

The pixel intensity value is defined by its type. For instance a grey-image image (type Mat2UI8) we can the pixel coordinates i and j as follows:

Mat2UI8 m(10,10);//create a 2d matrix with 10-row and the 10-columns and with UI8 pixel type (0,1,2...,255)
int i=4;
int j=6;
UI8 intensity = 200;//set a value at 200
m(i,j) = intensity;//set a pixel value at 200
intensity = m(i,j);//access the pixel value at 4-row and the 6-column
std::cout<<m<<std::endl;

Alternatively, you can use the following notation with a 2-d vector (see Vec{2,3}{I32,F32}) to access the pixel value:

Mat2F64 m(4,3);//create a 2d matrix with 4-row and the 3-columns and with float pixel type
Vec2I32 x(2,1);
m(x) = 2.45;//set the pixel value at 2.45
std::cout<<m<<std::endl;

Now let us consider a color image with RGB color ordering:

Mat2RGBUI8 m(10,8);//create a 2d matrix with rgb pixel type
Vec2I32 x(4,6);
RGBUI8 value;
value.r()=200;//set the red channel at 200
value.g()=100;//set the green channel at 100
value.b()=210;//set the blue channel at 210
m(x) = value;//set the pixel value
m.display("test 2",false);

To generate the top figures, the code is :

std::cout<<"\ntest3"<<std::endl;
Mat2UI8 m(6,5);//construct a 2d matrix with 1 byte pixel type with 6 rows and 5 columns
m(0,0)= 20;m(0,1)= 20;m(0,2)= 20;m(0,3)= 20;m(0,4)= 20;//set the pixel values of the first row
m(1,0)= 20;m(1,1)=255;m(1,2)= 20;m(1,3)=255;m(1,4)= 20;//set the pixel values of the second row
m(2,0)= 20;m(2,1)= 20;m(2,2)=255;m(2,3)= 20;m(2,4)= 20;//set the pixel values of the third row
m(3,0)= 20;m(3,1)= 20;m(3,2)= 20;m(3,3)= 20;m(3,4)= 20;//set the pixel values of the fourth row
m(4,0)= 20;m(4,1)=150;m(4,2)=150;m(4,3)=150;m(4,4)= 20;//set the pixel values of the fifth row
m(5,0)= 20;m(5,1)= 20;m(5,2)= 20;m(5,3)= 20;m(5,4)= 20;//set the pixel values of the sixth row
std::cout<<m<<std::endl;//display the array (left figure)
m.display("test 3");//display the image (right figure)

You can see also First step and the also the documentation of the class Mat{2,3}{UI8,RGBUI8}

Finally, you can start to work with 3d matrix (as tomography, IRM images)

Mat3UI8 m(3,3,4);//create a 3d matrix with 3-row, 3-columns and 4-depth and UI8 voxel type
Vec3I32 x(1,0,1);
m(x) = 200;//set the pixel value
std::cout<<m<<std::endl;

C++ code:

using namespace pop;//Population namespace
void test0(){
std::cout<<"test0"<<std::endl;
Mat2UI8 m(10,10);//create a 2d matrix with 10-row and the 10-columns and with UI8 pixel type (0,1,2...,255)
int i=4;
int j=6;
UI8 intensity = 200;//set the intensity at 200
m(i,j) = intensity;//set the pixel value at 200
intensity = m(i,j);//access the pixel value at 4-row and the 6-column
std::cout<<m<<std::endl;
}
void test1(){
std::cout<<"\ntest1"<<std::endl;
Mat2F32 m(4,3);//create a 2d matrix with 4-row and the 3-columns and with float pixel type
Vec2I32 x(2,1);
m(x) = 2.45f;//set the pixel value at 2.45
std::cout<<m<<std::endl;
}
void test2(){
std::cout<<"\ntest2"<<std::endl;
Mat2RGBUI8 m(10,8);//create a 2d matrix with rgb pixel type
Vec2I32 x(4,6);
RGBUI8 value;
value.r()=200;//set the red channel at 200
value.g()=100;//set the green channel at 100
value.b()=210;//set the blue channel at 210
m(x) = value;//set the pixel value
m.display("test 2",false);
}
void test3(){
std::cout<<"\ntest3"<<std::endl;
Mat2UI8 m(6,5);//construct a 2d matrix with 1 byte pixel type with 6 rows and 5 columns
m(0,0)= 20;m(0,1)= 20;m(0,2)= 20;m(0,3)= 20;m(0,4)= 20;//set the pixel values of the first row
m(1,0)= 20;m(1,1)=255;m(1,2)= 20;m(1,3)=255;m(1,4)= 20;//set the pixel values of the second row
m(2,0)= 20;m(2,1)= 20;m(2,2)=255;m(2,3)= 20;m(2,4)= 20;//set the pixel values of the third row
m(3,0)= 20;m(3,1)= 20;m(3,2)= 20;m(3,3)= 20;m(3,4)= 20;//set the pixel values of the fourth row
m(4,0)= 20;m(4,1)=150;m(4,2)=150;m(4,3)=150;m(4,4)= 20;//set the pixel values of the fifth row
m(5,0)= 20;m(5,1)= 20;m(5,2)= 20;m(5,3)= 20;m(5,4)= 20;//set the pixel values of the sixth row
std::cout<<m<<std::endl;//display the array (left figure)
m.display("test 3");//display the image (right figure)
}
void test4(){
std::cout<<"\n test4"<<std::endl;
Mat3UI8 m(3,3,4);//create a 3d matrix with 3-row, 3-columns and 4-depth and UI8 voxel type
Vec3I32 x(1,0,1);
m(x) = 200;//set the pixel value
std::cout<<m<<std::endl;
}
int main()
{
test0();
test1();
test2();
test4();
test3();
}