uncbiag / mermaid

Image registration using pytorch
Other
177 stars 28 forks source link

LNCC similarity result is out of range of [0,1] when images have large portion of zero valued area #132

Open lintian-a opened 4 years ago

lintian-a commented 4 years ago

LNCC output will be out of the range [0,1] when the images have large area with zero value.

Steps to reproduce:

  1. Generate Data:
    params = pars.ParameterDict()
    params['square_example_images']['len_s'] = 10
    params['square_example_images']['len_l'] = 30
    I0,I1,spacing = EG.CreateSquares(dim=3, add_noise_to_bg=False).create_image_pair(np.array([64, 64, 64]),params=params)
  2. Register with LNCC similarity.
    params['model']['registration_model']['type'] = "svf_vector_momentum_map" 
    params['model']['registration_model']['similarity_measure']['type'] = "lncc"
    opt = MO.SimpleSingleScaleRegistration(I0,
                                       I1,
                                       spacing,
                                       sz,
                                       params,
                                       compute_inverse_map=False)
    opt.register()

The log shows as follows: 0-Tot: E=099.4140 | simE=099.4140 | regE=000.0000 | optParE=000.0000 | relF= n/a | 0-Img: E=099.4140 | simE=099.4140 | regE=000.0000 |

xhs400 commented 4 years ago

I am pretty sure this is caused by the floating-precision, although I didn't run your case. Issues are with some background area, you will have a division between two small values. This would not happen in NCC unless the entire image is a constant.

To workaround, you can try: 1.use double instead of float in the LNCC. (may fix the problem perfectly)

  1. Clamp the value to (0,1) in the similarity measure. for example: image add "torch.clamp(lncc, min=0.0, max=1.0) " before "1-lncc.mean()"

Of course, if others have better solution, welcome to share.