airlab-unibas / airlab

Image registration laboratory for 2D and 3D image data
Apache License 2.0
408 stars 92 forks source link

Registration fails for signed images #10

Closed soupault closed 11 months ago

soupault commented 5 years ago

Hi,

I've discovered that the registration doesn't work if the images are preliminarily normalized by mean-std. MSE loss immediately falls to nan, NCC - to 0, and they do not ever change.

I'm not sure how you see the intended use of the library, but I'd say that working with mean-std normalized images is quite common.

To reproduce, in https://github.com/airlab-unibas/airlab/blob/master/examples/affine_registration_3d.py change https://github.com/airlab-unibas/airlab/blob/master/examples/affine_registration_3d.py#L41-L43 to

    fixed_image = th.zeros(64, 64, 64).to(device=device)
    fixed_image[16:32, 16:32, 16:32] = 1.0
    fixed_image = fixed_image - fixed_image.mean()
    fixed_image = fixed_image / fixed_image.std()
    fixed_image = al.Image(fixed_image, [64, 64, 64], [1, 1, 1], [0, 0, 0])

and https://github.com/airlab-unibas/airlab/blob/master/examples/affine_registration_3d.py#L45-L48 to

    moving_image = th.zeros(64, 64, 64).to(device=device)
    moving_image[16 - object_shift:32 - object_shift, 16 - object_shift:32 - object_shift,
    16 - object_shift:32 - object_shift] = 1.0
    moving_image = moving_image - moving_image.mean()
    moving_image = moving_image / moving_image.std()
    moving_image = al.Image(moving_image, [64, 64, 64], [1, 1, 1], [0, 0, 0])
RobinSandkuehler commented 5 years ago

Hi, thank you very much for your report. The problem here is in the center of mass calculation, with negative intensity values. This should not affect other registration methods. We will try to fix this issue.