Skip to content

Commit 818a85e

Browse files
committed
adding badPixelCorrection to preprocessing algorithms
1 parent 91ca3ec commit 818a85e

File tree

4 files changed

+61
-11
lines changed

4 files changed

+61
-11
lines changed

demo_leapctype/d14_outlierCorrection.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from leap_preprocessing_algorithms import *
88

99
'''
10-
The script demonstrates two different methods to handle outliers (zingers) in your projection data
10+
The script demonstrates two different methods to handle outliers (zingers) and bad pixels in your projection data
1111
'''
1212

1313
# Specify the number of detector columns which is used below
@@ -48,24 +48,44 @@
4848
I_0 = 50000.0
4949
g[:] = -np.log(np.random.poisson(I_0*np.exp(-g))/I_0)
5050

51-
# Make some of the detector pixels have zero value
52-
ind = np.abs(np.random.normal(0,1,g.shape)) > 3.0
53-
g[ind] = 0.0
54-
5551
# Choose which method you'd like to test
56-
whichMethod = 1
57-
#whichMethod = 2
52+
#whichMethod = 1
53+
whichMethod = 2
54+
#whichMethod = 3
5855

5956
if whichMethod == 1:
57+
58+
# Make some of the detector pixels have zero value
59+
ind = np.abs(np.random.normal(0,1,g.shape)) > 3.0
60+
g[ind] = 0.0
61+
6062
# Perform median filter based outlier correction
6163
# This is a very fast method which is good for isolated bad pixels
6264
outlierCorrection(leapct,g)
6365

66+
# Reconstruct the data
67+
f = leapct.allocateVolume()
68+
leapct.FBP(g,f)
69+
elif whichMethod == 2:
6470

71+
# Make some detector pixels dead for all projections
72+
ind = np.abs(np.random.normal(0,1,(g.shape[1], g.shape[2]))) > 3.0
73+
g[:,ind] = 0.0
74+
75+
# Correct for bad pixels
76+
badPixelMap = np.zeros((g.shape[1], g.shape[2]), dtype=np.float32)
77+
badPixelMap[ind] = 1.0
78+
badPixelCorrection(leapct, g, badPixelMap)
79+
6580
# Reconstruct the data
6681
f = leapct.allocateVolume()
6782
leapct.FBP(g,f)
6883
else:
84+
85+
# Make some of the detector pixels have zero value
86+
ind = np.abs(np.random.normal(0,1,g.shape)) > 3.0
87+
g[ind] = 0.0
88+
6989
# Perform RWLS reconstruction where we set the weights to be zero where there are bad pixels
7090
# This method is computationally expensive, but is good when you have large regions of bad pixels
7191
# or want to perform so-called Metal Artifact Reduction (MAR)

docs/source/preprocessing_algorithms.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Preprocessing Algorithms
22
========================
33

44
.. autofunction:: leap_preprocessing_algorithms.makeAttenuationRadiographs
5+
.. autofunction:: leap_preprocessing_algorithms.badPixelCorrection
56
.. autofunction:: leap_preprocessing_algorithms.outlierCorrection
67
.. autofunction:: leap_preprocessing_algorithms.outlierCorrection_highEnergy
78
.. autofunction:: leap_preprocessing_algorithms.detectorDeblur_FourierDeconv

src/leap_preprocessing_algorithms.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,39 @@ def makeAttenuationRadiographs(leapct, g, air_scan=None, dark_scan=None, ROI=Non
8787

8888
return True
8989

90+
def badPixelCorrection(leapct, g, badPixelMap, windowSize=3, isAttenuationData=True):
91+
r"""Removes bad pixels from CT projections
92+
93+
LEAP CT geometry parameters must be set prior to running this function
94+
and can be applied to any CT geometry type.
95+
This algorithm processes each projection independently
96+
and removes bad pixels specified by the user using a median filter
97+
98+
Args:
99+
leapct (tomographicModels object): This is just needed to access LEAP algorithms
100+
g (contiguous float32 numpy array or torch tensor): attenuation or transmission projection data
101+
badPixelMap (C contiguous float32 numpy array or torch tensor): 2D bad pixel map (numRows x numCols) where a value of 1.0 marks a pixel as bad
102+
windowSize (int): the window size; can be 3, 5, or 7
103+
isAttenuationData (bool): True if g is attenuation data, False otherwise
104+
105+
Returns:
106+
True if successful, False otherwise
107+
"""
108+
109+
if g is None or badPixelMap is None:
110+
return False
111+
112+
# This algorithm processes each transmission
113+
if isAttenuationData:
114+
leapct.expNeg(g)
115+
leapct.badPixelCorrection(g, badPixelMap, windowSize)
116+
if isAttenuationData:
117+
leapct.negLog(g)
118+
return True
119+
90120
def outlierCorrection(leapct, g, threshold=0.03, windowSize=3, isAttenuationData=True):
91121
r"""Removes outliers (zingers) from CT projections
92122
93-
Assumes the input data is in attenuation space.
94123
No LEAP parameters need to be set for this function to work
95124
and can be applied to any CT geometry type.
96125
This algorithm processes each projection independently
@@ -121,7 +150,6 @@ def outlierCorrection(leapct, g, threshold=0.03, windowSize=3, isAttenuationData
121150
def outlierCorrection_highEnergy(leapct, g, isAttenuationData=True):
122151
"""Removes outliers (zingers) from CT projections
123152
124-
Assumes the input data is in attenuation space.
125153
No LEAP parameters need to be set for this function to work
126154
and can be applied to any CT geometry type.
127155
This algorithm processes each projection independently
@@ -152,7 +180,6 @@ def outlierCorrection_highEnergy(leapct, g, isAttenuationData=True):
152180
def LowSignalCorrection(leapct, g, threshold=0.03, windowSize=3, signalThreshold=0.001, isAttenuationData=True):
153181
r"""Corrects detector pixels that have very low transmission (photon starvation)
154182
155-
Assumes the input data is in attenuation space.
156183
No LEAP parameters need to be set for this function to work
157184
and can be applied to any CT geometry type.
158185
This algorithm processes each projection independently

src/leapctype.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4543,10 +4543,12 @@ def badPixelCorrection(self, g, badPixelMap, windowSize=3):
45434543
r"""Bad Pixel Correction
45444544
45454545
The provided input must be projection data and the CT geometry parameters must be set.
4546+
This algorithm processes each projection independently
4547+
and removes bad pixels specified by the user using a median filter.
45464548
45474549
Args:
45484550
g (C contiguous float32 numpy array or torch tensor): 3D projection data array
4549-
badPixelMap (C contiguous float32 numpy array or torch tensor): 2D bad pixel map
4551+
badPixelMap (C contiguous float32 numpy array or torch tensor): 2D bad pixel map (numRows x numCols)
45504552
windowSize (int): the window size; can be 3, 5, or 7
45514553
45524554
Returns:

0 commit comments

Comments
 (0)