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

Average patterns with adjacent patterns to reduce noise #13

Closed
hakonanes opened this issue Jan 23, 2019 · 4 comments
Closed

Average patterns with adjacent patterns to reduce noise #13

hakonanes opened this issue Jan 23, 2019 · 4 comments
Labels
discussion Discussion enhancement New feature or request

Comments

@hakonanes
Copy link
Member

hakonanes commented Jan 23, 2019

Another way of reducing noise in patterns than creating model patterns from decomposition factors is by simply averaging a pattern with the adjacent patterns. This can be done by e.g. using scipy.ndimage.filters.generic_filter and passing numpy.mean as the function to apply to each pattern. There are (at least) two problems to address:

  1. We cannot naively use HyperSpy's map() since we have to also access the adjacent patterns
  2. If adjacent patterns are too different from the pattern to average we will increase the noise! This could be tackled by only averaging with patterns that have a low 'pattern difference', as is explained by Wright et al. (https://www.sciencedirect.com/science/article/pii/S0304399114001946). (Implementing this might be a lot of work? I don't know. Should speak to de Graef in May, since it's his work they refer to in the article.)

A s.average_patterns(num_neighbours=1) function would be nice!

@hakonanes hakonanes added enhancement New feature or request discussion Discussion labels Jan 23, 2019
@hakonanes hakonanes self-assigned this Jan 23, 2019
@tinabe
Copy link
Collaborator

tinabe commented Jan 23, 2019

Comment to 2): Are you thinking about solving that by adding a conditional statement: only use pixel for averaging if the difference between them (abs of subtract) is lower than some threshold?

@hakonanes
Copy link
Member Author

Yes, a suggested value should be default, however I should be able to overwrite this.

The 'pattern difference' procedure as explained by Wright et al. in the article referenced above:

  1. Convert each pattern to a column vector.
  2. Subtract the average intensity of each pattern from each vector component.
  3. Normalise the column vector.
  4. Calculate difference between two patterns by calculating the dot product between the two normalised column vectors.
  5. Subtract the resulting difference value from 1 so that 0 indicates no difference and 1 represents the maximum difference.
  6. Average the resulting eight difference values for each pattern to its eight adjacent patterns to obtain final difference value

@hakonanes
Copy link
Member Author

Should use dask.map_overlap for this: https://docs.dask.org/en/latest/array-overlap.html#dask.array.map_overlap.

@hakonanes
Copy link
Member Author

This is now possible with kikuchipy.signals.ebsd.EBSD.average_neighbour_patterns().

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

No branches or pull requests

2 participants