Skip to content

Commit

Permalink
Refs #114. autocrop: discard influence of the borders.
Browse files Browse the repository at this point in the history
This problem arises when a particular scan of CT has some stripes at the
bottom left of the images. Hassina said it is the table.
That stripes throw the autocrop off.
This hack just remove the borders from the consideration of autocropping.
  • Loading branch information
yxqd committed Oct 4, 2018
1 parent ec03bf2 commit 4908d8d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions python/imars3d/autocrop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

def calculateCropWindow(series):
def calculateCropWindow(series, normalize=False):
# estimate average
ave = estimateAverage(series)
from . import io
Expand All @@ -12,7 +12,10 @@ def save(d, p):
sm = ndimage.median_filter(ave, 9) # 21)
save(sm, "sm-estimate-ave.tiff")
# make sure all numbers are smaller than 1.
max = np.max(sm); sm/=max
if normalize:
max = np.max(sm); sm/=max
else:
sm[sm>1] = 1
# get background intensities
left = sm[:, :10]; left_median = np.median(left)
top = sm[:10, :]; top_medain = np.median(top)
Expand All @@ -28,6 +31,9 @@ def save(d, p):
xmin = np.min(X1); xmax = np.max(X1)
ymin = np.min(Y1); ymax = np.max(Y1)
return xmin, xmax, ymin, ymax
# there might be outliers in borders, just clear the borders out
sm[:, :25] = background_int; sm[:25, :] = background_int
sm[:, -25:] = background_int; sm[-25:, :] = background_int
# find rectangle for real data
Y, X = np.where(sm < background_int*0.95)
ymax = Y.max(); ymin = Y.min()
Expand Down

0 comments on commit 4908d8d

Please sign in to comment.