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

A framework for computing similarity between 2D gray-tone images #231

Merged
merged 28 commits into from
Oct 16, 2020

Conversation

onatlandsmyr
Copy link
Collaborator

@onatlandsmyr onatlandsmyr commented Oct 12, 2020

Similarity Metrics for 2D gray-tone images of equal size

A framework for computing similarity metrics between 2D gray-tone images of equal size. Provides a wrapper for user-defined metrics for use in, soon to be pull requested, template matching and dictionary indexing.

Zero-mean Normalized Cross-Correlation and Normalized Dot Product are implemented for inputs being dask arrays.

Progress of the PR

Minimal example of the bug fix or new feature

>>> import numpy as np
>>> import kikuchipy as kp
>>> from kikuchipy.indexation import make_similiarity_metric
>>> s = kp.signals.EBSD(np.zeros((100, 200, 96, 96)),lazy=True)
>>> def sum_absolute_difference(p,t):
...     return np.sum(np.abs(p - t), axis=(2, 3))
>>> sad_metric = make_similarity_metric(sum_absolute_difference,scope=MetricScope.MANY_TO_ONE)
>>> sad = sad_metric(s.data, np.zeros((96, 96)))
array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    the unreleased section in doc/changelog.rst.

@hakonanes
Copy link
Member

This will be great additions, thank you @onatlandsmyr!

Do you wan't a review right away? If yes, I'll get to it today.

Also, do you want help with tests? And documentation? For this PR, I envision a module entry in the API reference documentation with all public classes/methods/functions fully documented from nice docstrings.

@hakonanes hakonanes added documentation This relates to the documentation tests This relates to the tests enhancement New feature or request ⌚ work in progress labels Oct 13, 2020
@hakonanes hakonanes added this to the v0.3.0 milestone Oct 13, 2020
@onatlandsmyr
Copy link
Collaborator Author

A review would be good, sooner the better. Two more PRs are coming soon and they depend on this PR. I'll try to contribute more to the tests and docs, but any help is much appreciated.

@hakonanes
Copy link
Member

A review would be good, sooner the better. Two more PRs are coming soon and they depend on this PR. I'll try to contribute more to the tests and docs, but any help is much appreciated.

Okay, great, will review soon and mention wherever I plan to contribute.

Copy link
Member

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, the general approach looks easily extendable and customizable, which is very nice to have.

There are many comments, some questions, some proposals for changes. Many of the comments are related to docstring formatting... Do you wan't to tackle these, or should I? I will add the indexing module to the API reference and see that all docstrings behave nicely, if that's okay with you.

kikuchipy/indexation/__init__.py Outdated Show resolved Hide resolved
kikuchipy/indexation/_util.py Outdated Show resolved Hide resolved
kikuchipy/indexation/similarity_metrics.py Outdated Show resolved Hide resolved
kikuchipy/indexation/similarity_metrics.py Outdated Show resolved Hide resolved
kikuchipy/indexation/similarity_metrics.py Outdated Show resolved Hide resolved
kikuchipy/indexation/similarity_metrics.py Outdated Show resolved Hide resolved
kikuchipy/indexation/similarity_metrics.py Outdated Show resolved Hide resolved
kikuchipy/indexation/similarity_metrics.py Outdated Show resolved Hide resolved
kikuchipy/indexation/similarity_metrics.py Outdated Show resolved Hide resolved
kikuchipy/indexation/similarity_metrics.py Outdated Show resolved Hide resolved
@hakonanes
Copy link
Member

Yeah, the tests will fail since I didn't change the normalize() call in _ndp_einsum() to _normalize().

@hakonanes hakonanes removed documentation This relates to the documentation tests This relates to the tests labels Oct 13, 2020
@hakonanes hakonanes changed the title Similarity Metrics A framework for computing similarity between 2D gray-tone images Oct 14, 2020
onatlandsmyr and others added 9 commits October 16, 2020 13:53
Change data shape from (N,nm) to (nm,N) to correspond better with cdist in scipy and general logic.
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes
Copy link
Member

Will merge after tests pass. Great work, @onatlandsmyr!

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Copy link
Member

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this in and move on to the next PR! Let's change the SimilarityMetric class and related functions if necessary in that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants