SuperElastix / SimpleElastix

Multi-lingual medical image registration library
http://simpleelastix.github.io
Apache License 2.0
513 stars 149 forks source link

The registration is not working properly for 3d binary images #368

Open sahar-mahmoudi opened 4 years ago

sahar-mahmoudi commented 4 years ago

Hi!

I have tried to register two 3d binary volume which both include one sphere but the result is not aligned with the fixed volume at all. Am I using the SimpleElastix incorrectly? I could not find any example for 3d image registration in the documentation.

img_a = sitk.GetImageFromArray(vol1)
img_b = sitk.GetImageFromArray(vol2)

parameterMap = sitk.GetDefaultParameterMap('translation')

itk_filter = sitk.ElastixImageFilter()
itk_filter.LogToConsoleOn()
itk_filter.SetFixedImage(img_a)
itk_filter.SetMovingImage(img_b)
itk_filter.SetParameterMap(parameterMap)
itk_filter.Execute()

result_vol = sitk.GetArrayFromImage(itk_filter.GetResultImage())
sorenchr2011 commented 4 years ago

Hi, What is the dimension ordering of your vol1 and vol2? What is slices, rows and columns? Most of the examples in the manual are 3D images: https://simpleelastix.readthedocs.io/ParameterMaps.html

Soren

On Thu, Apr 9, 2020 at 2:05 PM sahar-mahmoudi notifications@github.com wrote:

Hi!

I have tried to register two 3d binary volume which both include one sphere but the result is not aligned with the fixed volume at all. Am I using the SimpleElastix incorrectly? I could not find any example for 3d image registration in the documentation.

img_a = sitk.GetImageFromArray(vol1) img_b = sitk.GetImageFromArray(vol2)

parameterMap = sitk.GetDefaultParameterMap('translation')

itk_filter = sitk.ElastixImageFilter() itk_filter.LogToConsoleOn() itk_filter.SetFixedImage(img_a) itk_filter.SetMovingImage(img_b) itk_filter.SetParameterMap(parameterMap) itk_filter.Execute()

result_vol = sitk.GetArrayFromImage(itk_filter.GetResultImage())



—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/SuperElastix/SimpleElastix/issues/368>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHBDDID7PBZYJHNQZ4L6XLRLW2Z3ANCNFSM4MEVWRWA>
.
sahar-mahmoudi commented 4 years ago

Hi, What is the dimension ordering of your vol1 and vol2? What is slices, rows and columns? Most of the examples in the manual are 3D images: https://simpleelastix.readthedocs.io/ParameterMaps.html Soren On Thu, Apr 9, 2020 at 2:05 PM sahar-mahmoudi @.***> wrote: Hi! I have tried to register two 3d binary volume which both include one sphere but the result is not aligned with the fixed volume at all. Am I using the SimpleElastix incorrectly? I could not find any example for 3d image registration in the documentation. img_a = sitk.GetImageFromArray(vol1) img_b = sitk.GetImageFromArray(vol2) parameterMap = sitk.GetDefaultParameterMap('translation') itk_filter = sitk.ElastixImageFilter() itk_filter.LogToConsoleOn() itk_filter.SetFixedImage(img_a) itk_filter.SetMovingImage(img_b) itk_filter.SetParameterMap(parameterMap) itk_filter.Execute() result_vol = sitk.GetArrayFromImage(itk_filter.GetResultImage()) ``` — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#368>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHBDDID7PBZYJHNQZ4L6XLRLW2Z3ANCNFSM4MEVWRWA .

it is (50,50,50)

sorenchr2011 commented 4 years ago

Sorry, I meant what dimension (0,1,2) is your image rows, columns and slices. GetImageFromArray expects slice,column,row. So one explanation could be your dimensions are permuted if you expect row,colum,slice ordering. Maybe this is more a question for elastix-imageregistration@googlegroups.com since you have issues with use and don't expect this to be an issue with the software at this point.

Soren

On Thu, Apr 9, 2020 at 2:30 PM sahar-mahmoudi notifications@github.com wrote:

Hi, What is the dimension ordering of your vol1 and vol2? What is slices, rows and columns? Most of the examples in the manual are 3D images: https://simpleelastix.readthedocs.io/ParameterMaps.html Soren … <#m7329319549774840556> On Thu, Apr 9, 2020 at 2:05 PM sahar-mahmoudi @.***> wrote: Hi! I have tried to register two 3d binary volume which both include one sphere but the result is not aligned with the fixed volume at all. Am I using the SimpleElastix incorrectly? I could not find any example for 3d image registration in the documentation. img_a = sitk.GetImageFromArray(vol1) img_b = sitk.GetImageFromArray(vol2) parameterMap = sitk.GetDefaultParameterMap('translation') itk_filter = sitk.ElastixImageFilter() itk_filter.LogToConsoleOn() itk_filter.SetFixedImage(img_a) itk_filter.SetMovingImage(img_b) itk_filter.SetParameterMap(parameterMap) itk_filter.Execute() result_vol = sitk.GetArrayFromImage(itk_filter.GetResultImage()) ``` — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#368 https://github.com/SuperElastix/SimpleElastix/issues/368>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHBDDID7PBZYJHNQZ4L6XLRLW2Z3ANCNFSM4MEVWRWA .

it is (50,50,50)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SuperElastix/SimpleElastix/issues/368#issuecomment-611501703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHBDDOFZHDRC7QCOADKOODRLW5X5ANCNFSM4MEVWRWA .

sahar-mahmoudi commented 4 years ago
vol1 = np.zeros((50, 50, 50))
for x in range(vol1.shape[0]):
    for y in range(vol1.shape[1]):
        for z in range(vol1.shape[2]):
            vol1[x, y, z] = np.linalg.norm(np.subtract([x, y, z], [5, 3, 2])) < 4

vol2 = np.zeros((50, 50, 50))
for x in range(vol2.shape[0]):
    for y in range(vol2.shape[1]):
        for z in range(vol2.shape[2]):
            vol2[x, y, z] = np.linalg.norm(np.subtract([x, y, z], [20, 30, 10])) < 4

img_a = sitk.GetImageFromArray(vol1)
img_b = sitk.GetImageFromArray(vol2)
sorenchr2011 commented 4 years ago

Ok I don't think the axis are the problem. I guess you have binary images with no overlap? In this case you should be initializing with center of mass. Check the manual or Google automatictransforminitialization.

On Thu, Apr 9, 2020, 14:46 sahar-mahmoudi notifications@github.com wrote:

vol1 = np.zeros((50, 50, 50)) for x in range(vol1.shape[0]): for y in range(vol1.shape[1]): for z in range(vol1.shape[2]): vol1[x, y, z] = np.linalg.norm(np.subtract([x, y, z], [5, 3, 2])) < 4

vol2 = np.zeros((50, 50, 50)) for x in range(vol2.shape[0]): for y in range(vol2.shape[1]): for z in range(vol2.shape[2]): vol2[x, y, z] = np.linalg.norm(np.subtract([x, y, z], [20, 30, 10])) < 4

img_a = sitk.GetImageFromArray(vol1) img_b = sitk.GetImageFromArray(vol2)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SuperElastix/SimpleElastix/issues/368#issuecomment-611508227, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHBDDN3HKICXOVMKATIXFTRLW7TJANCNFSM4MEVWRWA .

kaspermarstal commented 4 years ago

Try to convert the binary images to distance maps using e.g. DanielssonDistanceMap() and register the distance maps instead. There is very little gradient information available for the registration algorithm (only a little bit along the edges of the blobs) when registering binary images directly.