Read and write an image from a TIFF file in C++
First, the header to include to load and save an image from a TIFF file is :
#include <IPSDKImageFile/Tiff/TiffImageFileUtils.h>
To save an image in a TIFF file, only the following instruction is needed :
saveTiffImageFile(imageFilePath, pImg);
In the same way, these following instruction allows to load an image from a TIFF file :
ImagePtr pImg = loadTiffImageFile(imageFilePath);
- Note
- In the case of images saved by another environment than IPSDK, some flags must be missing in the header. In this case, it is necessary to specify the flags ipsdk::image::file::eTiffDirectoryMode and ipsdk::image::file::eTiffBufferMode to correctly read the image.
-
Tiff format allows to associate a resolution to image file. This resolution is defined by three flags :
- TIFFTAG_RESOLUTIONUNIT which allows to associate a unit string ('cm' or 'inch') to image
- TIFFTAG_XRESOLUTION and TIFFTAG_YRESOLUTION which define number of pixels per measure unit.
If these information are provided with tiff image, the library will automatically associate a geometric calibration to image (see Basic image manipulation).
Read and write an image from a TIFF file in Python
In Python, an image can then be saved (or loaded) to (from) a TIFF file with the following instructions :
PyIPSDK.saveTiffImageFile(inputImgPath, img)
img = PyIPSDK.loadTiffImageFile(inputImgPath)
Read an image from several TIFF files
Because the large size of images, some acquisition devices store the images in several files (one slice or frame per file). IPSDK is able to load several TIFF image files and concatenate them into a single image, along the Z-axis or the temporal dimension. This is done by the function ipsdk::image::file::loadTiffImageFiles :
ImagePtr pImg = loadTiffImageFiles(dirPath);
In Python, this is done by the following command :
img = PyIPSDK.loadTiffImageFiles(dirPath);