1

I am fairly new to image registration by SimpleITK , and I have installed from sources the SimpleITK package on Python3.

here is my code:


import SimpleITK as sitk

FIXED_IMAGE_NAME = '/data/fixedImage.nii'
MOVING_IMAGE_NAME = '/data/movingImage.nii'
THIRD_IMAGE_NAME = '/data/thirdImage.nii'
FIXED_IMAGE_MASK_NAME = '/data/fixedImage_roi.nii'
OUTPUT_IMG_NAME = '/data/moving_registered.nii'
OUTPUT_THRID_IMG_NAME = '/data/third_registered.nii'

OUTPUT_LOG_NAME = '/data/MR_CT_thirdPET_LOG.txt'


## Load fixed and moving image data
fixedImage = sitk.ReadImage(FIXED_IMAGE_NAME,sitk.sitkInt16)
movingImage = sitk.ReadImage(MOVING_IMAGE_NAME,sitk.sitkInt16)

 
# Execute elastix registration
elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(fixedImage)
elastixImageFilter.SetMovingImage(movingImage)
try:
    if FIXED_IMAGE_MASK_NAME != None and FIXED_IMAGE_MASK_NAME != "":
        elastixImageFilter.SetFixedMask(sitk.ReadImage(FIXED_IMAGE_MASK_NAME,sitk.sitkInt16))
except:
    print("NO FIXED_IMAGE_MASK: there is no fixedImage_roi.nii in the /data folder.") 
elastixImageFilter.SetParameterMap(parameterMap_rigid)


elastixImageFilter.AddParameterMap(parameterMap_bslpine) 


print("Performing registration using SimpleElastix...")
elastixImageFilter.LogToFileOn() 
#elastixImageFilter.SetLogFileName(OUTPUT_LOG_NAME)
elastixImageFilter.LogToConsoleOn()
elastixImageFilter.Execute()

resultImage = elastixImageFilter.GetResultImage()
sitk.WriteImage(resultImage, OUTPUT_IMG_NAME)

#    Get transform parameter map
transformParameterMap = elastixImageFilter.GetTransformParameterMap()

try:
    thirdImage = sitk.ReadImage(THIRD_IMAGE_NAME,sitk.sitkInt16)

    transformix = sitk.TransformixImageFilter()
    transformix.SetTransformParameterMap(transformParameterMap)
    transformix.SetMovingImage(thirdImage)

    transformix.Execute()

    resultThird = transformix.GetResultImage()
    sitk.WriteImage(resultThird, OUTPUT_THRID_IMG_NAME)
except:
    print("NO THIRD_IMAGE: there is no thirdImage.nii in the /data folder.") 


sitk::ERROR: Fixed mask must be of pixel type sitkUInt8 but fixed mask 0 is of type "16-bit signed integer". Cast with SimpleITK.Cast(mask, sitk.sitkUInt8).

Can you direct me where is my problem here?

1 Answers1

0

It looks like the mask image for elastixImageFilter.SetFixedMask must be of type sitkUInt8, but your call to sitk.ReadImage is telling it to use type sitkInt16. Change that to line to the following and it ought to work:

    elastixImageFilter.SetFixedMask(sitk.ReadImage(FIXED_IMAGE_MASK_NAME,sitk.sitkUInt8))
Dave Chen
  • 1,905
  • 1
  • 12
  • 18
  • unfortunately it dose to work even I changed the code to sitk.sitkUInt8 .the size of the input images is 512, 512 , 950) , any suggestions? – Ahmad Alajmi Dec 24 '20 at 00:19
  • RuntimeError: Exception thrown in SimpleITK ElastixImageFilter_Execute: /SimpleElastix/Code/Elastix/src/sitkElastixImageFilterImpl.cxx:111: the same error – Ahmad Alajmi Dec 24 '20 at 09:33