"""
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
print("Default disk image directory :", PyIPSDK.getAllocatedDiskImagePath())
newDir = os.path.expanduser("~")
PyIPSDK.setAllocatedDiskImagePath(newDir)
print("New disk image directory :", PyIPSDK.getAllocatedDiskImagePath())
imagesSamplePath = PyIPSDK.getIPSDKDirectory(PyIPSDK.eInternalDirectory.eID_Images)
im = PyIPSDK.openTiffImageFile(os.path.join(imagesSamplePath, "porosity_125x97x47_UInt16.tif"))
print("Processing a disk image...")
out = util.copyImg(im)
print("Is disk image", out.isDiskImage())
print("Set the intensity of the first pixel to 255")
out.writePixel(255, 0, 0, 0, 0, 0)
sizeX = im.getSizeX();
sizeY = im.getSizeY();
offsetX = 10;
offsetY = 10;
strideX = 5;
strideY = 5;
sx = sizeX - offsetX
sy = sizeY - offsetY
rangeSizeX = sx // strideX
rangeSizeY = sy // strideY
outSizeX = rangeSizeX + (sx > rangeSizeX*strideX)
outSizeY = rangeSizeY + (sy > rangeSizeY * strideY)
outMem = out.loadPlan(0, 0, 0, outSizeX, outSizeY, offsetX, offsetY, strideX, strideY)
print("First pixels in the extracted plan :", outMem.array[0, :4])
ui.displayImg(outMem, "Plan subset")
time.sleep(5)
print("End of main()")
if __name__ == '__main__':
try:
libraryInitializer = PyIPSDK.getLibraryInitializerInstance()
libraryInitializer.clear()
except Exception as e:
print("Exception raised")
print(e)
print("End of the program")