Algorithm allowing to resize a 3d image.
This algorithm allows to resize a 3d image using one of the available interpolation methods
The user can resize a 3d image either to the expected output image size or by specifying the scale factors along the x, y and z axis.
If the user provides the buffer of the output image, he has to initialize its dimensions with the correct values. If the user requests a resize operation by specifying the scale factors, for instance, the dimensions of the output image must equal to:
- xOutImgSize = integer part of (xInImgSize * xScaleFactor + .5)
- yOutImgSize = integer part of (yInImgSize * yScaleFactor + .5)
- zOutImgSize = integer part of (zInImgSize * zScaleFactor + .5) The user can call the utility function ipsdk::imaproc::util::getZoom3dOutputImageSize to automatically compute the dimensions of his output image from the dimensions of the input image and from the scale factors.
The enumerate ipsdk::attr::eZoomInterpolationMethod permits to specify the interpolation method to use to resize the image. The following interpolation methods are available:
- eZoomInterpolationMethod::eZIM_NearestNeighbour: the voxel value of the output image at position (xOut, yOut, zOut) equals to the value of the voxel nearest to the associated position in the input image. More precisely: ImgOut(xOut, yOut, zOut) = ImgIn(integer_part(xOut/xScaleFactor), integer_part(yOut/yScaleFactor), integer_part(zOut/zScaleFactor)) This is the certainly one of the fastest methods, but it generates a coarse image, with aliasing.
- eZoomInterpolationMethod::eZIM_Linear: for each voxel of output image, voxel value is computed by doing a trilinear interpolation on the 8 nearest neighbours. It gives satisfying results, and it is a good compromise between speed and quality.
- eZoomInterpolationMethod::eZIM_Cubic: for each voxel of output image, voxel value is computed by doing a tricubic interpolation on the 64 nearest neighbours. This method is slower than the trilinear interpolation, but it usually gives better results, generating sharper edges than trilinear interpolation.
- eZoomInterpolationMethod::eZIM_VolumeWeightedMean: this method must be prefered if the scale factors are lower than 1.0 (in other words, if the user wants to shrink his input image). For each output voxel, it computes the mean of associated voxel values in the input image, weighted by the surface of these voxels "covered" by the associated output voxel.
An example of image resizing is illustrated in 2d case : see 2d zoom.
Example of Python code :
Example imports
import PyIPSDK
import PyIPSDK.IPSDKIPLGeometricTransform as gtrans
Code Example
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
xScaleFactor = 2.1
yScaleFactor = 1.2
zScaleFactor = 1.3
outImg3dSize = gtrans.getZoom3dOutputImageSize(PyIPSDK.createImg3dSize(inImg.getSizeX(), inImg.getSizeY(), inImg.getSizeZ()), PyIPSDK.createScaleFactor3d(xScaleFactor, yScaleFactor, zScaleFactor))
outImg3dSizeX = outImg3dSize.xSz
outImg3dSizeY = outImg3dSize.ySz
outImg3dSizeZ = outImg3dSize.zSz
outGeometry = PyIPSDK.geometry3d(inImg.getBufferType(), outImg3dSizeX, outImg3dSizeY, outImg3dSizeZ)
outImg = PyIPSDK.createImage(outGeometry)
gtrans.zoom3dImg(inImg, xScaleFactor, yScaleFactor, zScaleFactor, PyIPSDK.eZoomInterpolationMethod.eZIM_NearestNeighbour, outImg)
Example of C++ code :
Example informations
Header file
#include <IPSDKIPL/IPSDKIPLGeometricTransform/Processor/Zoom3dImg/Zoom3dImg.h>
Code Example
if(inImageBufferType != pInImg->getBufferType())
ImagePtr pOutImg = zoom3dImg(pInImg, xScaleFactor, yScaleFactor, zScaleFactor, interpolationMethod);