Module demonstrating basics of PyIPSDK libraries.
More...
Module demonstrating basics of PyIPSDK libraries.
Prerequisite
A minimal knowledge of python language is necessary to manipulate PyIPSDK Python binding.
Some python tutorials can be found at python official web site.
Overview
This scripts introduce IPSDK python wrappers basic manipulations.
Step by step tutorial
Used library imports
We start by importing all necessary libraries:
import os
import PyIPSDK
import PyIPSDK.IPSDKIPLBasicMorphology as morpho
- Note
- See Image processing algorithms for a complete list of IPSDK image processing algorithm family.
Handle image creation
New images can be created using following :
img2d1 = PyIPSDK.createImage(PyIPSDK.eImageBufferType.eIBT_UInt16, 487, 532)
geometry2d1 = img2d1.getGeometry()
sizeX2d1 = img2d1.getSizeX()
sizeY2d1 = img2d1.getSizeY()
bufferType2d1 = img2d1.getBufferType()
img3d1 = PyIPSDK.createImage(PyIPSDK.eImageBufferType.eIBT_Binary, 150, 125, 97)
sizeZ3d1 = img3d1.getSizeZ()
imgRgb1 = PyIPSDK.createImageRgb(PyIPSDK.eImageBufferType.eIBT_UInt8, 512, 480)
sizeCRgb1 = imgRgb1.getSizeC()
imgSeq1 = PyIPSDK.createImageSeq(PyIPSDK.eImageBufferType.eIBT_Real32, 100, 120, 150)
sizeTSeq1 = imgSeq1.getSizeT()
geometry2d2 = PyIPSDK.geometry2d(PyIPSDK.eImageBufferType.eIBT_UInt16, 487, 532)
img2d2 = PyIPSDK.createImage(geometry2d2)
geometry3d2 = PyIPSDK.geometry3d(PyIPSDK.eImageBufferType.eIBT_Binary, 150, 125, 97)
img3d2 = PyIPSDK.createImage(geometry3d2)
geometryRgb2 = PyIPSDK.geometryRgb2d(PyIPSDK.eImageBufferType.eIBT_UInt8, 512, 480)
imgRgb2 = PyIPSDK.createImage(geometryRgb2)
geometrySeq2 = PyIPSDK.geometrySeq2d(PyIPSDK.eImageBufferType.eIBT_Binary, 100, 120, 150)
imgSeq2 = PyIPSDK.createImage(geometrySeq2)
- Note
- See ipsdk::image::eImageBufferType for a complete list of supported image buffer types.
Handle image files
Once imported PyIPSDK, user can start using library to :
- load and save Tiff image files :
tiffImg2d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "blobs_483x348_UInt8.tif"))
tiffImg3d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "porosity_125x97x47_UInt16.tif"))
tiffImgSeq1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "porosity_125x97x47_UInt16.tif"),
PyIPSDK.eTiffDirectoryMode.eTDM_Temporal)
tiffImgBin2d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "blobs3d_483x348x31_Binary.tif"),
PyIPSDK.eTiffDirectoryMode.eTDM_Volume,
PyIPSDK.eTiffBufferMode.eTBM_Binary)
tiffImgBin2d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "blobs3d_483x348x31_Label.tif"),
PyIPSDK.eTiffDirectoryMode.eTDM_Volume,
PyIPSDK.eTiffBufferMode.eTBM_Label)
tiffOutputPath3d1 = os.path.join(tmpPath, "new_name_for_tiffImg3d1.tif")
PyIPSDK.saveTiffImageFile(tiffOutputPath3d1, tiffImg3d1)
print("Image tiffImg3d1 saved to path : " + tiffOutputPath3d1)
- load set of tiff image file contained in a directory :
multiTiffImg3d1 = PyIPSDK.loadTiffImageFiles(os.path.join(imagesSamplePath, "sequence1"),
"porosity_125x97x47_UInt16_page_*.tif",
PyIPSDK.eTiffDirectoryMode.eTDM_Volume)
print("Multi tiff image file resulting z size : " + str(multiTiffImg3d1.getSizeZ()))
- Note
- PyIPSDK.loadTiffImageFiles function accepts additional parameters, see ipsdk::image::file::loadTiffImageFiles for more informations.
-
used file pattern could be simply "*" if no other files are present into directory.
- load and save Raw image files :
rawGeometry1 = PyIPSDK.geometry2d(PyIPSDK.eImageBufferType.eIBT_Binary, 256, 256)
rawImg1 = PyIPSDK.loadRawImageFile(os.path.join(imagesSamplePath, "MorphoBin2d1.raw"), rawGeometry1)
rawOutputPath1 = os.path.join(tmpPath, "new_name_for_imgRaw1.raw")
PyIPSDK.saveRawImageFile(rawOutputPath1, rawImg1)
print("Image imgRaw1 saved to path : " + rawOutputPath1)
- Note
- ipsdk::image::file::loadRawImageFile function accepts an additional parameter allowing to define starting offset for data in file.
Call of image processing algorithm
Once an input image loaded, user can apply processing algorithm on it :
inSE = PyIPSDK.circularSEXYInfo(8)
outImg1 = morpho.erode2dImg(tiffImg2d1, inSE)
A detail description of each algorithm can be found in section Image processing algorithms.
For instance, used algorithm morpho.erode2dImg is described here : Erosion 2d.