IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 17 12:34:15 2018
@author: Rémi
"""
import os
import sys
import numpy as np
import time
import PyIPSDK
import PyIPSDK.IPSDKIPLUtility as util
import PyIPSDK.IPSDKUI as ui
# --------------------------------------------------------------------------- #
def main():
# [DocSampleAllocatedImagePath]
print("Default disk image directory :", PyIPSDK.getAllocatedDiskImagePath())
newDir = os.path.expanduser("~") # Change the directory to $HOME
PyIPSDK.setAllocatedDiskImagePath(newDir)
print("New disk image directory :", PyIPSDK.getAllocatedDiskImagePath())
# [DocSampleAllocatedImagePath]
# Saving the local processing policy with the new path will set it as the default path
# Uncomment this line to change the default directory where the disk image
# automatically created by IPSDK are saved
# PyIPSDK.saveLocalProcessingPolicy()
# Define the path to the input image
imagesSamplePath = PyIPSDK.getIPSDKDirectory(PyIPSDK.eInternalDirectory.eID_Images)
# [DocSampleOpenDiskImage]
# Uncomment to open a RAW file
# geometry = PyIPSDK.geometry2d(PyIPSDK.eIBT_UInt8, 510, 509)
# im = PyIPSDK.openRawImageFile(os.path.join(imagesSamplePath, "Lena_510x509_UInt8.raw"), geometry, 0)
# Open a TIFF file
im = PyIPSDK.openTiffImageFile(os.path.join(imagesSamplePath, "porosity_125x97x47_UInt16.tif"))
# [DocSampleOpenDiskImage]
# [DocSampleProcessDiskImage]
print("Processing a disk image...")
out = util.copyImg(im)
# [DocSampleProcessDiskImage]
# [DocSampleCheckIsDiskImage]
# Test if the image is a disk image
print("Is disk image", out.isDiskImage())
# [DocSampleCheckIsDiskImage]
# [DocSampleWritePixel]
# Change the value of the first pixel
print("Set the intensity of the first pixel to 255")
out.writePixel(255, 0, 0, 0, 0, 0)
# [DocSampleWritePixel]
# Load a subset of a plan
# In our case, we set up the ROI offset and stride
sizeX = im.getSizeX();
sizeY = im.getSizeY();
offsetX = 10;
offsetY = 10;
strideX = 5;
strideY = 5;
# We can now deduce the ROI size from the input image size, the ROI offset and stride
sx = sizeX - offsetX
sy = sizeY - offsetY
rangeSizeX = sx // strideX
rangeSizeY = sy // strideY
outSizeX = rangeSizeX + (sx > rangeSizeX*strideX)
outSizeY = rangeSizeY + (sy > rangeSizeY * strideY)
# [DocSampleExtractPlan]
# Load a sub-set of a slice in an IPSDK memory image instance
# The image can be used as any other IPSDK image
outMem = out.loadPlan(0, 0, 0, outSizeX, outSizeY, offsetX, offsetY, strideX, strideY)
# [DocSampleExtractPlan]
# [DocSampleAccessPlanData]
# Print the first values
print("First pixels in the extracted plan :", outMem.array[0, :4])
# Display the extracted sub-plan
ui.displayImg(outMem, "Plan subset")
# [DocSampleAccessPlanData]
# Wait to be able to see the automatically created disk image returned by the IPSDK algorithm
# in the file explorer
time.sleep(5)
# Uncomment to delete manually the disk image file
# out = None
print("End of main()")
# --------------------------------------------------------------------------- #
if __name__ == '__main__':
main()
# Properly clear IPSDK
try:
libraryInitializer = PyIPSDK.getLibraryInitializerInstance()
libraryInitializer.clear()
except Exception as e:
print("Exception raised")
print(e)
print("End of the program")