Documentation‎ > ‎

1. Image Type

Introduction

    The image type used in TIPL is a template class named image, which is a general container for pixel type and dimension. The data structure of image is just a one dimension array with default implementation by std::vector.

Declare a 2D/3D image

You may declare a 2d or 3d image using the following example.


// a 2d RGB image
tipl::color_image image1;

// a 2d grayscale image
tipl::gray_image image2;

// a 2d image with 8-bit pixel
tipl::image<2,unsigned char>  image3;

// a 2d image with 16-bit pixel
tipl::image<2,short>  image4;

// a 3d image with 16-bit pixel
tipl::image<3,short>  image5;

// a 3d image with single floating point precision (float)
tipl::image<3>  image6;


Image size

You may assign the image size with the object declaration

// a 100-by-100 image
tipl::image<2>  image1(tipl::shape<2>(100,100));

// a 100-by-100-by-100 3d image
tipl::image<3>  image2(tipl::shape<3>(100,100,100));

or change it later on.

tipl::image<2>  image1;
image1.resize(tipl::shape<2>(100,100));

Pointer image

An external memory block can be capsulated using by an image interface. 


const float* ptr = ... ; // any image memory block
tipl::point_image<3> I = tipl::make_image(tipl::shape<3>(100,100,100),ptr);
// .. perform further operations

More complicated image type

Example: declare a 3d gradient field. Each pixel is a gradient vector

tipl::image<3,tipl::vector<3> > gradient_field_3d;

Access image size

tipl::image<3> I(tipl::shape<3>(20,30,40));
int width = I.width();
int height = I.height();
int depth = I.depth();
int total_pixel = I.size();

Access a pixel

You may randomly access a pixel using the "at" function, but note that the design paradigm of image does not favor the usage of random access. Use iterator instead, such as image3.begin() and image3.end()

tipl::image<2> image3(tipl::shape<2>(100,100));
auto pixel_value = image3.at(50,50);

Iterate all pixels

The following codes iterate all pixels in an image. This is a recommended way over the "at" function approach.

tipl::image<3> I;
for(tipl::pixel_index<3> pos(I.geometry());i < I.size();++i)
{
    int x = pos[0];
    int y = pos[1];
    int z = pos[2];
    float pixel_value = I[pos.index()];
}



Comments