ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
625 stars 161 forks source link

ants.resample_image_to_target() giving empty/blank image output. #468

Closed Sam291998 closed 1 year ago

Sam291998 commented 1 year ago

Problem I tried to resample 3D ct moving image to 3D ct target image but got empty/blank 3d image as output.

Code

import ants

# Load images
fixed = ants.image_read('img/LUNG0_00032_0000.nii.gz')
moving = ants.image_read('img/LUNG1_00032_0000.nii.gz')

resampled = ants.resample_image_to_target(moving, fixed, verbose=True,imagetype=0)
ants.image_write(resampled, f'z_m.nii.gz')

Output explanation The output image had same dimension,direction and spacing of the target image but image was empty which in turn let to another error which is as follows:-

reg = ants.registration(fixed=fixed, moving=resampled, type_of_transform='SyN')

Exception Object caught: 

itk::ExceptionObject (0x172634b0)
Location: "unknown" 
File: [/project/itksource/Modules/Filtering/ImageStatistics/include/itkImageMomentsCalculator.hxx](https://file+.vscode-resource.vscode-cdn.net/project/itksource/Modules/Filtering/ImageStatistics/include/itkImageMomentsCalculator.hxx)
Line: 123
Description: ITK ERROR: ImageMomentsCalculator(0x1642a4e0): Compute(): Total Mass of the image was zero. Aborting here to prevent division by zero later on.

Screenshots image

Desktop :

stnava commented 1 year ago

resample_image_to_target does not do registration - it just does resampling based on physical space. so if images dont overlap - then you will get a blank image out.

just run the registration without doing resample_image_to_target first ... also - start with a translation registration just to make sure you dont have any other issues.

Sam291998 commented 1 year ago

Okay understood. I thought it was necessary to resample the moving image first and then apply registration . Thanks for clarifying!