InsightSoftwareConsortium / ITKElastix

An ITK Python interface to elastix, a toolbox for rigid and nonrigid registration of images
Apache License 2.0
213 stars 23 forks source link

Extraction deformation field after 3D registration. #273

Open shloveya opened 8 months ago

shloveya commented 8 months ago

Hi, I recently tried to make a 3D image registration (x,y,z) by using ITKElastix (Reference: Example3 and Example5) reason For some reasons, I should get a deformation field in a specific z index. (to perform the same registration in different images) In 2D registration, I easily get the deformation by using

Load another image for same registration

moving_image_transformix = itk.imread("C:/python/Second_moving_object.tif", itk.F) transformix_object = itk.TransformixFilter.New(moving_image_transformix) transformix_object.SetTransformParameterObject(result_transform_parameters) transformix_object.UpdateLargestPossibleRegion()

Perform 2nd registration

result_image_transformix = transformix_object.GetOutput()

By using this code, I can visualize the deformation field by using deformation_field = itk.transformix_deformation_field(moving_image, result_transform_parameters) deformation_field.shape deformation_field = np.asarray(deformation_field).astype(np.float32) fig, axs = plt.subplots(1,2, sharey=True, figsize=[10,10]) plt.figsize=[10,10] axs[0].imshow(deformation_field[:,:,1]) axs[0].set_title('Deformation Field X', fontsize=30) axs[1].imshow(deformation_field[:,:,0]) axs[1].set_title('Deformation Field Y', fontsize=30)

I used the same code in 3D registration adding information of the z index. (At this time, the shape of the deformation field was (46, 512, 512, 3)

I extract the deformation field at z:10

deformation_field_ar = np.asarray(deformation_field).astype(np.float32)
DF_dimension = deformation_field.shape
print(DF_dimension)
fig, axs = plt.subplots(1,3, sharey=True, figsize=[10,10])
plt.figsize=[10,10]
axs[0].imshow(deformation_field[10,:,:,2])
axs[0].set_title('Deformation Field X', fontsize=10)
axs[1].imshow(deformation_field[10,:,:,1])
axs[1].set_title('Deformation Field Y', fontsize=10)
axs[2].imshow(deformation_field[10,:,:,0])
axs[2].set_title('Deformation Field Z', fontsize=10)
deformation_field_ar = np.asarray(deformation_field).astype(np.float32)
DF_dimension = deformation_field.shape
print(DF_dimension)
fig, axs = plt.subplots(1,3, sharey=True, figsize=[10,10])
plt.figsize=[10,10]
axs[0].imshow(deformation_field[10,:,:,2])
axs[0].set_title('Deformation Field X', fontsize=10)
axs[1].imshow(deformation_field[10,:,:,1])
axs[1].set_title('Deformation Field Y', fontsize=10)
axs[2].imshow(deformation_field[10,:,:,0])
axs[2].set_title('Deformation Field Z', fontsize=10)

z10 deform

But when I changed the deformation field at z 20, the Z-field did not change.

deformation_field_ar = np.asarray(deformation_field).astype(np.float32)
DF_dimension = deformation_field.shape
print(DF_dimension)
fig, axs = plt.subplots(1,3, sharey=True, figsize=[10,10])
plt.figsize=[10,10]
axs[0].imshow(deformation_field[20,:,:,2])
axs[0].set_title('Deformation Field X', fontsize=10)
axs[1].imshow(deformation_field[20,:,:,1])
axs[1].set_title('Deformation Field Y', fontsize=10)
axs[2].imshow(deformation_field[20,:,:,0])
axs[2].set_title('Deformation Field Z', fontsize=10)

z20 deform

I think the deformation field of Z should have a different dimension (because of dimension of z is smaller than x or y).

Could someone please help me?

Thanks.