IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
# [DocSampleImports]
# import of standard python os library which allows basic interactions with operating system
import os
# import of PyIPSDK which is the core module for IPSDK library python wrapping
import PyIPSDK
# import of PyIPSDK.IPSDKIPLBasicMorphology sub module which allows to use morphological algorithm familly included in IPSDK
import PyIPSDK.IPSDKIPLBasicMorphology as morpho
# [DocSampleImports]
# definition of used directories for images
imagesSamplePath = PyIPSDK.getIPSDKDirectory(PyIPSDK.eInternalDirectory.eID_Images)
tmpPath = PyIPSDK.getIPSDKDefaultDirectory(PyIPSDK.eDefaultExternalDirectory.eDED_Tmp)
# [DocSampleHandleImageCreation]
# creation of a 2d image with size 487x532 and with unsigned short data type
img2d1 = PyIPSDK.createImage(PyIPSDK.eImageBufferType.eIBT_UInt16, 487, 532)
# once image define, user can query for image complete geometry
geometry2d1 = img2d1.getGeometry()
# or to basic image informations
sizeX2d1 = img2d1.getSizeX()
sizeY2d1 = img2d1.getSizeY()
bufferType2d1 = img2d1.getBufferType()
# creation of a 3d image with size 150x125x97 and with binary data type
img3d1 = PyIPSDK.createImage(PyIPSDK.eImageBufferType.eIBT_Binary, 150, 125, 97)
sizeZ3d1 = img3d1.getSizeZ()
# creation of a RGB image with size 512x480 and with unsigned char data type
imgRgb1 = PyIPSDK.createImageRgb(PyIPSDK.eImageBufferType.eIBT_UInt8, 512, 480)
sizeCRgb1 = imgRgb1.getSizeC()
# creation of a sequence image with size 100x120x150 and with floating point data type
imgSeq1 = PyIPSDK.createImageSeq(PyIPSDK.eImageBufferType.eIBT_Real32, 100, 120, 150)
sizeTSeq1 = imgSeq1.getSizeT()
# previous images can also be created using a predefined geometry
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)
# [DocSampleHandleImageCreation]
# [DocSampleHandleTiffImage]
# in 2d or 3d standard case, user can simply call following function to open image
tiffImg2d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "blobs_483x348_UInt8.tif"))
tiffImg3d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "porosity_125x97x47_UInt16.tif"))
# if input multi directory Tiff image file should be interpreted as a sequence rather then a 3d volume
# user can add following instructions
# (Note that on write IPSDK add custom tags allowing to retrieve complete image geometry and type
# so once saved with IPSDK additional load instructions are no more needed and interpreted)
tiffImgSeq1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "porosity_125x97x47_UInt16.tif"),
PyIPSDK.eTiffDirectoryMode.eTDM_Temporal)
# if input Tiff data should be interpreted has binary data, user can add following instructions
# (Note that on write IPSDK add custom tags allowing to retrieve complete image geometry and type
# so once saved with IPSDK additional load instructions are no more needed and interpreted)
tiffImgBin2d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "blobs3d_483x348x31_Binary.tif"),
PyIPSDK.eTiffDirectoryMode.eTDM_Volume,
PyIPSDK.eTiffBufferMode.eTBM_Binary)
# if input Tiff data should be interpreted has label data (connected components tagged data),
# user can add following instructions
# (Note that on write IPSDK add custom tags allowing to retrieve complete image geometry and type
# so once saved with IPSDK additional load instructions are no more needed and interpreted)
tiffImgBin2d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "blobs3d_483x348x31_Label.tif"),
PyIPSDK.eTiffDirectoryMode.eTDM_Volume,
PyIPSDK.eTiffBufferMode.eTBM_Label)
# save existing image to a Tiff image file
tiffOutputPath3d1 = os.path.join(tmpPath, "new_name_for_tiffImg3d1.tif")
PyIPSDK.saveTiffImageFile(tiffOutputPath3d1, tiffImg3d1)
print("Image tiffImg3d1 saved to path : " + tiffOutputPath3d1)
# [DocSampleHandleTiffImage]
# [DocSampleHandleTiffImageSet]
# load 3d tiff image file from multi files and a file pattern
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()))
# [DocSampleHandleTiffImageSet]
# [DocSampleHandleRawImage]
# Load of raw image file need to define used image geometry
rawGeometry1 = PyIPSDK.geometry2d(PyIPSDK.eImageBufferType.eIBT_Binary, 256, 256)
rawImg1 = PyIPSDK.loadRawImageFile(os.path.join(imagesSamplePath, "MorphoBin2d1.raw"), rawGeometry1)
# save existing image to a Raw image file
rawOutputPath1 = os.path.join(tmpPath, "new_name_for_imgRaw1.raw")
PyIPSDK.saveRawImageFile(rawOutputPath1, rawImg1)
print("Image imgRaw1 saved to path : " + rawOutputPath1)
# [DocSampleHandleRawImage]
# [DocSampleIPL]
# definition of used circular structuring element
inSE = PyIPSDK.circularSEXYInfo(8)
# erosion 2d image computation
outImg1 = morpho.erode2dImg(tiffImg2d1, inSE)
# [DocSampleIPL]