-
Notifications
You must be signed in to change notification settings - Fork 1
/
image_processor.py
73 lines (61 loc) · 1.9 KB
/
image_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This module processes the raw images according to J. Ortega Arroyo, D. Cole,
and P. Kukura, “Interferometric scattering microscopy and its combination with
single-molecule fluorescence imaging,” Nat. Protoc. 11, 617–633 (2016)
"""
import numpy as np
from scipy.ndimage import gaussian_filter
def process_all_images(raws, dark, subt_median=True, sig1=6, sig2=15):
"""
Process a full stack of raw images.
Parameters
----------
raws : ndarray
images to be processed
dark : ndarray
dark counts to be subtracted
subt_median : bool
boolean to indicate whether a median subtraction should be performed
sig1 : float
std of the gaussian filter for reference beam subtraction
sig2 : float
std of the gaussian filter for reference beam division
Returns
-------
stack : ndarray
processed images
"""
stack = np.array([
process_single_image(raws[i,:,:],dark,sig1=sig1,sig2=sig2) for i in range(raws.shape[0])])
if subt_median:
noise = np.median(stack,axis=0)
stack = stack - noise[np.newaxis,:,:]
return stack
def process_single_image(raw, dark, sig1=6, sig2=15):
"""
Process a single raw images.
Parameters
----------
raw : ndarray
image to be processed
dark : ndarray
dark counts to be subtracted
sig1 : float
std of the gaussian filter for reference beam subtraction
sig2 : float
std of the gaussian filter for reference beam division
Returns
-------
divided : ndarray
processed image
"""
#subtract the dark count
raw = raw - dark
#subtract the reference beem
subtracted = raw - gaussian_filter(raw, sigma=sig1)
#divide the reference beam
divided = subtracted / gaussian_filter(raw, sigma=sig2)
#return subtracted
return divided