Skip to content

Commit

Permalink
Fixed overflow issue (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbestak authored Jan 20, 2023
1 parent 51de882 commit 42eb6ad
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions background_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def process_metadata(metadata, markers):
def isNaN(x):
return x != x


def subtract_channel(image, markers, channel, background_marker, output):
scalar = markers[markers.ind == channel].exposure.values / background_marker.exposure.values

Expand All @@ -117,14 +116,14 @@ def subtract_channel(image, markers, channel, background_marker, output):
back = copy.copy(image[background_marker.ind])[0]
# subtract background from processed channel and if the background intensity for a certain pixel was larger than
# the processed channel, set intensity to 0 (no negative values)
back = np.rint(ne.evaluate("back * scalar")).astype(np.uint16)
back = np.rint(ne.evaluate("back * scalar"))
back = np.where(back>65535,65535,back.astype(np.uint16))
# set the pixel value to 0 if the image channel value is lower than the scaled background channel value
# otherwise, subtract.
output[channel] = np.where(image[channel]<back, 0, image[channel]-back)
del back
back = None
return output[channel]


def subtract(img, markers, output):
# iterating over channels
for channel in range(len(markers)):
Expand Down

0 comments on commit 42eb6ad

Please sign in to comment.