This example notebook is translated from ImageJ macro.
When dealing with three dimensional point coordinates, it is mandatory to take the voxel size into account, e.g. for measuring distances between points. This example shows how to multiply a list of coordinates by a given voxel size.
import pyclesperanto_prototype as cle
import numpy as np
voxel_size = np.asarray([[0.2], [0.2], [0.5]])
print("Array shape:" + str(voxel_size.shape))
gpu_voxel_size = cle.push(voxel_size)
print("GPU array shape:" + str(voxel_size.shape))
Array shape:(3, 1) GPU array shape:(3, 1)
pointlist = np.asarray(
[
[1, 3, 5, 11], # X
[0, 6, 1, 2 ], # Y
[9, 11, 6, 2 ] # Z
]
)
print("Array shape:" + str(pointlist.shape))
gpu_pointlist = cle.push(pointlist)
print("GPU array shape:" + str(gpu_pointlist.shape))
Array shape:(3, 4) GPU array shape:(3, 4)
print(gpu_voxel_size)
[[0.2] [0.2] [0.5]]
print(gpu_pointlist)
[[ 1. 3. 5. 11.] [ 0. 6. 1. 2.] [ 9. 11. 6. 2.]]
gpu_updated_pointlist = cle.multiply_images(gpu_pointlist, gpu_voxel_size)
print(gpu_updated_pointlist)
[[0.2 0.6 1. 2.2] [0. 1.2 0.2 0.4] [4.5 5.5 3. 1. ]]
Note: If the resulting image does not exist in first place, clesperanto has to guess its size. Thus, it takes the input size of the first image to operate. So, if you permute the input parameters, the resulting matrix size will be ‘wrong’:
gpu_updated_pointlist = cle.multiply_images(gpu_voxel_size, gpu_pointlist)
print(gpu_updated_pointlist)
[[0.2] [0. ] [4.5]]