IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

Modules demonstrating how to mix PyIPSDK library features with SimpleItk features. More...

Modules demonstrating how to mix PyIPSDK library features with SimpleItk features.

SimpleItk images, see SimpleItk official web site, can easily be manipulated has PyIPSDK images and vice versa without memory penalty cost using numpy array. There is no reallocation exchanging data from SimpleItk images to PyIPSDK images and vice versa.

Prerequisite

SimpleItk library should be installed with used Python distribution (see SimpleItk official web site for more informations).

Usage

The following script illustrate how to handle usage of SimpleItk library with PyIPSDK library.

We start by importing all necessary libraries:

import os
import PyIPSDK
# specific SimpleItk library import
import SimpleITK as sitk
# specific numpy library import
import numpy as np

We can now mix PyIPSDK and SimpleItk features :

# opening of a 2d image with size 483x348 and with unsigned char data type
img2d1 = PyIPSDK.loadTiffImageFile(os.path.join(imagesSamplePath, "blobs_483x348_UInt8.tif"))
# threshold this image using SimpleITK function
sitkBinImg2d1 = sitk.BinaryThreshold(sitk.GetImageFromArray(img2d1.array), 127, 255, 0, 1)
# once done we can retrieve a PyIPSDK image
# note that sitkBinImg2d1 and binImg2d1 share memory
binImg2d1 = PyIPSDK.fromArray(sitk.GetArrayFromImage(sitkBinImg2d1))
# and finaly save resulting image
outputPath1 = os.path.join(tmpPath, "PyIPSDK_mix_with_SimpleITK_1.tif")
PyIPSDK.saveTiffImageFile(outputPath1, binImg2d1)
print("Image saved to " + outputPath1)
Note
For more informations on mixing PyIPSDK images with numpy array see Mix PyIPSDK with Numpy library.