Skip to content
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

Masked image translation registration #3330

Closed
LaurentRDC opened this issue Aug 8, 2018 · 5 comments
Closed

Masked image translation registration #3330

LaurentRDC opened this issue Aug 8, 2018 · 5 comments

Comments

@LaurentRDC
Copy link
Contributor

I'd like to gauge interest in masked image translation registration.

I often have to register translation between diffraction patterns. However, there are static image elements that throw off standard approaches based on normalized cross-correlation, like skimage.feature.register_translation.

I have implemented a normalized cross-correlation function that can take image masks as well, based on the following publication: D. Padfield. Masked object registration in the Fourier domain. IEEE Transactions on Image Processing (2012). The working principle is essentially the same as skimage.feature.register_translation, with the cross-correlation not taking into account the masked parts of images.

You can find a successful registration example here.

I have already written a Python implementation that mimics skimage.feature.register_translation as much as possible:

The function masked_register_translation above passes the exact same tests as the MATLAB implementation from the original author. It also gives the same results as skimage.feature.register_translation in the case of trivial masks.

I'd like to get some feedback regarding including this functionality directly in Scikit-image. The source code linked above provides a working starting point.

@jni
Copy link
Member

jni commented Aug 9, 2018

@LaurentRDC cool package! You should present it at a SciPy conference!

I would support inclusion of this if:

  1. You could make it n-dimensional (seems doable from a cursory look at the code)
  2. You could include it with minimal intrusion to both the API (adding src_mask and target_mask keyword arguments at the end) and the code (not too many additional branching if/elses inside the code). (Again, I think this seems doable.)

What do you think?

@jni
Copy link
Member

jni commented Aug 9, 2018

Oh, another point: at scikit-image we use True values in the mask to point to valid locations. I think that's the opposite of what your API does? Again, trivial fix.

@LaurentRDC
Copy link
Contributor Author

@jni Thank you for the feedback!

I understand the need for n-dimensional operations and consistent mask definition. However, it seems you are advocating for including the masked image registration functionality inside of register_translation.

How would you feed about having a separate function? The masked normalized cross-correlation requires 6 FFTs and 6 IFFTs, while normalized cross-correlation requires 2 FFTs and 1 IFFTs. The performance difference is very noticeable, especially in my use case. I typically want to register ~3000 images to a reference, sometimes with masks and sometimes without.

@jni
Copy link
Member

jni commented Aug 10, 2018

@LaurentRDC note that this is an API question, not an implementation question (though I would like to see as much code sharing as possible). But in the worst case you can do:

def register_translation(src, target, ..., src_mask=None, target_mask=None):
    if src_mask is None and target_mask is None):
        result = register_translation_classic(src, target, ...)
    else:
        result = register_translation_masked(src, target, ..., 
                                             src_mask=src_mask, target_mask=target_mask)
    return result

@LaurentRDC
Copy link
Contributor Author

Since #3334 has been merged, I'm closing this.

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

No branches or pull requests

4 participants