Last active
February 26, 2019 21:21
-
-
Save skuschel/4823d53067263507a04c07ff7f84255f to your computer and use it in GitHub Desktop.
Single photon counting
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
def findsinglephotons(image, thresupper, threslower, maxsize=2): | |
''' | |
identifies single photons in the image and returns the for each photon the integrated counts on the image | |
* a photon need to be above the thresupper in order to be found | |
* surrounding regions of a photon will be added as long as they are above the threslower value | |
* maxsize=2 controlls over how many pixels a photon may spread | |
Stephan Kuschel, 2019 | |
https://gist.github.com/skuschel/4823d53067263507a04c07ff7f84255f | |
''' | |
import skimage.measure as skm | |
import numpy as np | |
up = skm.label(image > thresupper, connectivity=1) | |
N = np.max(up) | |
print('{} possible events found'.format(N)) | |
upNs = np.bincount(up.flatten()) | |
low = skm.label(image > threslower, connectivity=1) | |
lowNs = np.bincount(low.flatten()) | |
photons = [] | |
#finalmask = np.zeros_like(image) | |
for iup, upN in enumerate(upNs): | |
if upN > maxsize: | |
continue | |
# find index of value iup in up | |
upmask = up==iup | |
ilow = np.max(low[upmask]) | |
if lowNs[ilow] > maxsize: | |
continue | |
mask = low==ilow | |
photons.append(np.sum(image[mask])) | |
#finalmask[mask] += 1 | |
return np.asarray(photons)#, finalmask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment