New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demon registration, unstable? #1541

Closed
Borda opened this Issue May 30, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@Borda
Copy link
Contributor

Borda commented May 30, 2018

Description

I am wondering why the demon registration tens to be unstable for small images with simple objects. I have a case where I register the fuzzy image to binary images of the same objects, but the SSD turns to be worse after registration (92) than before (72). Any idea what can be the issue?

input fuzzy image fuzzyinput & reference binary image reference

import numpy as np
import matplotlib.pyplot as plt

img_ref = plt.imread('reference.png')[:, :, 0]
img_in = plt.imread('fuzzyInput.png')[:, :, 0]

plt.figure(figsize=(12, 5))
plt.subplot(121), plt.imshow(img_in), plt.contour(img_ref, colors='r')
plt.subplot(122), plt.imshow(img_in - img_ref), plt.colorbar()
print ('input SSD:', np.sum((img_in - img_ref) ** 2))

from dipy.align.imwarp import SymmetricDiffeomorphicRegistration, DiffeomorphicMap
from dipy.align.metrics import SSDMetric

sdr = SymmetricDiffeomorphicRegistration(metric=SSDMetric(img_ref.ndim),
                                         step_length=0.5,
                                         level_iters=[50, 100],
                                         inv_iter=50,
                                         ss_sigma_factor=0.1,
                                         opt_tol=1.e-3)

mapping = sdr.optimize(img_ref.astype(float), img_in.astype(float))

img_warp = mapping.transform(img_in, 'linear')

plt.figure(figsize=(12, 5))
plt.subplot(121), plt.imshow(img_warp), plt.contour(img_ref, colors='r')
plt.subplot(122), plt.imshow(img_warp - img_ref), plt.colorbar()
print ('warped SSD:', np.sum((img_warp - img_ref) ** 2))

visual_warped

Way to reproduce

  • Code example
  • Relevant images (if any)
  • Operating system and version (Linux-4.9.0-6-amd64-x86_64-with-debian-9.4)
  • Python version ('Python', '2.7.13 (default, Nov 24 2017, 17:33:09) \n[GCC 6.3.0 20170516]')
  • dipy version (0.13.0)
  • dependency version ('NumPy', '1.12.1'), ('SciPy', '0.18.1'), ('Nibabel', '2.2.1'), ('H5py', '2.7.1')
@Borda

This comment has been minimized.

Copy link
Contributor

Borda commented Jun 6, 2018

It seems that decreasing the learning rate helps and also certain impact has the multiresolution...
My expectation was that with learning rate 1, the move should be in the range one pixel, so I tried also 0.5 but no improvement... then I noticed that the multiresolution may scale my interpretation of the learning rate and values about 0.1 seems to converge to the expected state.

@Garyfallidis

This comment has been minimized.

Copy link
Member

Garyfallidis commented Jun 8, 2018

Hi @Borda thank you for this issue. It is expected that with change of metrics (here the SSD) and resolution some of the parameters need to change. If I understand correctly you did manage to resolve this issue by yourself. However, this can be useful information to many others. Is it okay with you to make this code into an example and share it with the dipy community? Let me know what you think. And also should we consider this issue as resolved?

@Borda

This comment has been minimized.

Copy link
Contributor

Borda commented Jun 8, 2018

sure, I can add it into examples, just may you give a guide what can I find it and what is a recommendation for writing an example, like using sample image or generate it on the fly?

@Garyfallidis

This comment has been minimized.

Copy link
Member

Garyfallidis commented Jun 9, 2018

Thank you @Borda. Please generate it on the fly if you can. Otherwise you need to make a fetcher to download the datasets. See fetcher examples here https://github.com/nipy/dipy/blob/master/dipy/data/fetcher.py
Let us know if you have more questions.

@Borda

This comment has been minimized.

Copy link
Contributor

Borda commented Jun 11, 2018

@Garyfallidis I have created #1561 may you have look if it is something similar you had in mind?

@skoudoro

This comment has been minimized.

Copy link
Member

skoudoro commented Jun 29, 2018

Example merged so I think we can close this issue. Feel free to reopen it if needed.
Thank you again!

@skoudoro skoudoro closed this Jun 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment