Documentation‎ > ‎

1. Image Type


    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<unsigned char,2>  image3;

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

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

Image size

You may assign the image size with the object declaration

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

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

or change it later on.

tipl::image<unsigned char,2>  image1();

Pointer image

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

const float* ptr = ... ; // any image memory block
tipl::point_image<float,3> I = tipl::make_image(tipl::geometry<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<tipl::vector<3>, 3> gradient_field_3d;

Access image size

tipl::image<float,3> I(tipl::geometry<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<unsigned char,2>  image3(tipl::geometry<2>(100,100));
unsigned char pixel_value =,50);

Iterate all pixels

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

tipl::image<float,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()];