Last active
December 12, 2015 08:08
-
-
Save tjlane/4741729 to your computer and use it in GitHub Desktop.
Simple filter for noise for CSPAD data. Good for finding the center.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.ndimage import filters | |
def find_edges(image, threshold=0.01, minf_size=3, medf_size=10): | |
""" | |
Applies an edge filter followed by a noise reduction filter. Very good | |
at locating powder rings and filtering everything else out. | |
Parameters | |
---------- | |
image : ndarray | |
An image to find the edges of | |
Returns | |
------- | |
binary_image : ndarray, np.bool | |
A binary image, with "1" where there are powder rings/strong edges | |
""" | |
image = np.abs(filters.sobel(image, 0)) + np.abs(filters.sobel(image, 1)) | |
image -= image.min() | |
assert image.min() == 0 | |
assert image.max() > 0 | |
# print 'threshold value: %d' % (image.max() * self.threshold) | |
image = (image > (image.max() * threshold)).astype(np.bool) | |
image = filters.minimum_filter(image, size=minf_size) | |
image = filters.median_filter(image, size=medf_size) | |
return image.astype(np.bool) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment