Loading the projection to conebeam geometry

stat = imf.execute_algorithm('CT.loadProjectionMatrices',[matrix[0],matrix[1]])
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: sequence item 0: Unable to cast Python instance of type <class ‘numpy.ndarray’> to C++ type ‘?’ (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
how can i load two projection matrix to a cone beam data

Hi Minhas,

It looks like CT.loadProjectionMatrices doesn’t correspond to any existing CT algorithm, and the matrix loading function is not exposed to the Python SDK yet.
But we have 2 alternative algorithms: CT.ProjectionMatrixIoAlgorithm and CT.CT.Load_projection_matrix_file, they should be available through the CT algorithm factory.
The later one should be more suited to load your matrices.
Please use the helper imfusion.available_algorithms() to check if an algorithm is supported.

Kind regards,
Van

mat_ap = np.array([[282.7221, -125.1971, -1868.2987, 134883.0415],
[301.7892, 1876.1042, -98.3304, -131400.1424],
[0.9967, -0.0309, 0.0752, -624.0998]
], dtype=np.float32)
mat_lt = np.array([[29.0441, 210.9549, -1890.5741, 152251.1058],
[-1902.1216, 199.9755, -24.8371, -161046.4005],
[-0.0228, 0.9991, 0.0371, -606.3542]
], dtype=np.float32)

imf.execute_algorithm(‘CT.CT.Load_projection_matrix_file’, [mat_ap,mat_lt ])

imf.execute_algorithm('CT.CT.Load_projection_matrix_file', [mat_ap,mat_lt ])

TypeError: sequence item 0: Unable to cast Python instance of type <class ‘numpy.ndarray’> to C++ type ‘?’ (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)

Hi,
I don’t think you’re using our Python SDK correctly:

  1. You’re passing two numpy arrays as the parameters for the algorithm execution, that is not correct. The parameters in this function call is supposed to be the parameter(s) of the corresponding C++ algorithm’s constructor. In this case, it is a SharedImageSet instance.
  2. The other missing parameter is an algorithm property object, which specifies the algorithm’s parameters. For this specific CT.CT.Load_projection_matrix_file algorithm, you need to configure the matrixFile and flipCameraDirection

Putting these together, we have an example below to load your matrices from a matrix file:

# cbData is a SharedImageSet instance holding the cone beam data you want to setup the geometry
algP = imfusion.algorithm_properties('CT.CT.Load_projection_matrix_file', [cbData])

algP.set_param('matrixFile', 'path-to-projection-mat'))

algP.set_param('flipCameraDirection', True)

imfusion.execute_algorithm('CT.CT.Load_projection_matrix_file', [cbData], algP)

Van

Thanks worked like a charm!
for setting target points in the image - is it in pixels??

Hi Minhas,

on a more general note: You can always get a template for how to invoke an algorithm in Python from the Workspace Editor (found in the “View” menu).
When you execute an algorithm in the Suite an entry for it with the matching configuration will be created in the Workspace Editor’s list of algorithms (left side of the window).

Regarding your question about points. Could you please elaborate what you are trying to do and what API you are using? In most cases Annotations like points are located in world space.

Cheers,
Ilja

To set the ROI for the Xray 2D3D registration what function can i use? I am able to perform it in the suite by cannot find the equivalent functions to perform in python.

file:///C:/Program%20Files/ImFusion/ImFusion%20Suite/doc/SDK/class_im_fusion_1_1_c_t_1_1_x_ray2_d3_d_registration_algorithm.html#
How can i get access to the maskEditor in the python SDK for 2D images. Looking forward to your response.

from PIL import Image, ImageDraw

from imfusion import ExplicitMask, AnnotationModel, Annotation,ExplicitIntensityMask

Image size

width, height = 480, 480

Rectangle coordinates: (left, top, right, bottom)

rect = (100, 100, 200, 200)

Create a black (0) mask image

mask_im = Image.new(‘L’, (width, height), 0)

Draw a white (255) rectangle on the mask

draw = ImageDraw.Draw(mask_im)

draw.rectangle(rect, fill=255)

mask_img = imf.SharedImageSet([np.array(mask_im),np.array(mask_im)])

mask1 = ExplicitIntensityMask(mask_img[0], cbData[0] )

mask2 = ExplicitIntensityMask(mask_img[1], cbData[1] )

i get the error
[CT.XRay2D3DRegistration.Algorithm] Unable to store masks in history
[CT.XRay2D3DRegistration.Algorithm] Unable to store masks in history
[CT.XRay2D3DRegistration.Algorithm] Unable to store masks in history
[CT.XRay2D3DRegistration.Algorithm] Unable to store masks in history