IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Mix PyIPSDK images with numpy array
# [DocSampleImports]
import os
import PyIPSDK
import PyIPSDK.IPSDKIPLUtility as util
# specific numpy library import
import numpy as np
# [DocSampleImports]
# [DocSampleFromPyIPSDKToNumpy]
# creation of a 2d image with size 5x7 and with unsigned short data type
img2d1 = PyIPSDK.createImage(PyIPSDK.eImageBufferType.eIBT_UInt16, 5, 7)
# fill this image with random values in range [3, 11]
util.randomImg(PyIPSDK.createRange(3, 11), img2d1)
# access and print of associated numpy array
print("img2d1.array = ")
print(img2d1.array)
# we can then directly modify array data and by the way image data
# note that numpy 2d array uses a y,x ordering
img2d1.array[2, 3] = 25
print("img2d1.array = ")
print(img2d1.array)
# [DocSampleFromPyIPSDKToNumpy]
# [DocSampleFromNumpyToPyIPSDK]
# creation of a 3d numpy array
# note that numpy 3d array uses a z,y,x ordering
array3d1 = np.empty([3, 5, 2], np.int16)
array3d1.fill(5)
print("array3d1 = ")
print(array3d1)
# create a PyIPSDK image from this array
# note that array and image share memory
img3d1 = PyIPSDK.fromArray(array3d1)
# fill this image with random values in range [0, 4]
util.randomImg(PyIPSDK.createRange(0, 4), img3d1)
print("array3d1 = ")
print(array3d1)
print("img3d1.array = ")
print(img3d1.array)
# [DocSampleFromNumpyToPyIPSDK]