LaurentRDC / scikit-ued

Collection of algorithms and routines for (ultrafast) electron diffraction and scattering
http://scikit-ued.readthedocs.io
GNU General Public License v3.0
134 stars 20 forks source link

added mask of ones, if no mask is given #41

Closed kremeyer closed 2 years ago

kremeyer commented 2 years ago

if mask is None, you will get an IndexError from scikit-image. This is because arr1 and arr2 will have different shapes than m1 and m2.

def cross_correlate_masked(arr1, arr2, m1, m2, mode='full', axes=(-2, -1),
                           overlap_ratio=0.3):
    """
    Masked normalized cross-correlation between arrays.

    Parameters
    ----------
    arr1 : ndarray
        First array.
    arr2 : ndarray
        Seconds array. The dimensions of `arr2` along axes that are not
        transformed should be equal to that of `arr1`.
    m1 : ndarray
        Mask of `arr1`. The mask should evaluate to `True`
        (or 1) on valid pixels. `m1` should have the same shape as `arr1`.
    m2 : ndarray
        Mask of `arr2`. The mask should evaluate to `True`
        (or 1) on valid pixels. `m2` should have the same shape as `arr2`.
    mode : {'full', 'same'}, optional
        'full':
            This returns the convolution at each point of overlap. At
            the end-points of the convolution, the signals do not overlap
            completely, and boundary effects may be seen.
        'same':
            The output is the same size as `arr1`, centered with respect
            to the `‘full’` output. Boundary effects are less prominent.
    axes : tuple of ints, optional
        Axes along which to compute the cross-correlation.
    overlap_ratio : float, optional
        Minimum allowed overlap ratio between images. The correlation for
        translations corresponding with an overlap ratio lower than this
        threshold will be ignored. A lower `overlap_ratio` leads to smaller
        maximum translation, while a higher `overlap_ratio` leads to greater
        robustness against spurious matches due to small overlap between
        masked images.

    Returns
    -------
    out : ndarray
        Masked normalized cross-correlation.

    Raises
    ------
    ValueError : if correlation `mode` is not valid, or array dimensions along
        non-transformation axes are not equal.

    References
    ----------
    .. [1] Dirk Padfield. Masked Object Registration in the Fourier Domain.
           IEEE Transactions on Image Processing, vol. 21(5),
           pp. 2706-2718 (2012). :DOI:`10.1109/TIP.2011.2181402`
    .. [2] D. Padfield. "Masked FFT registration". In Proc. Computer Vision and
           Pattern Recognition, pp. 2918-2925 (2010).
           :DOI:`10.1109/CVPR.2010.5540032`
    """

source

LaurentRDC commented 2 years ago

@kremeyer Can you add a test case where the test fails without your patch? Thanks

LaurentRDC commented 2 years ago

Also, the lint test won't work until you run the formatter black over the code base

kremeyer commented 2 years ago

Totally unrelated thing I stumbled upon: In the README.md you put python -m pip install git+git://github.com/LaurentRDC/scikit-ued.git as installation instructions. The git protocol fails for on my machine. Is there a good reason to use git instead of https or ssh?

LaurentRDC commented 2 years ago

Totally unrelated thing I stumbled upon: In the README.md you put python -m pip install git+git://github.com/LaurentRDC/scikit-ued.git as installation instructions. The git protocol fails for on my machine. Is there a good reason to use git instead of https or ssh?

Hmm I haven't use this for a while. Maybe it does not work anymore. I'll update it.

LaurentRDC commented 2 years ago

Release 2.1.10 is underway with this change