Skip to content

Commit

Permalink
Refs #114. fiddle with autocrop algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
yxqd committed Sep 21, 2018
1 parent df4efa2 commit f8eae90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 9 additions & 7 deletions python/imars3d/autocrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ def save(d, p):
# make sure all numbers are smaller than 1.
max = np.max(sm); sm/=max
# get background intensities
left = np.median(sm[:, :10])
top = np.median(sm[:10, :])
right = np.median(sm[:, -10:])
bottom = np.median(sm[-10:, :])
left = sm[:, :10]; left_median = np.median(left)
top = sm[:10, :]; top_medain = np.median(top)
right = sm[:, -10:]; right_median = np.median(right)
bottom = sm[-10:, :]; bottom_median = np.median(bottom)
#
background_int = np.median([left, top, right, bottom])
background_int = np.median([left_median, top_medain, right_median, bottom_median])
# if background is dark
if background_int < .05:
Y1, X1 = np.where(sm>0.1)
if background_int < .08:
max_bg = np.max(map(np.max, [left, top, right, bottom]))
max_bg = np.max( (max_bg, 0.1) )
Y1, X1 = np.where(sm>max_bg)
xmin = np.min(X1); xmax = np.max(X1)
ymin = np.min(Y1); ymax = np.max(Y1)
return xmin, xmax, ymin, ymax
Expand Down
18 changes: 18 additions & 0 deletions tests/imars3d/test_autocrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,34 @@ def test2():
dir = os.path.abspath(dir)
angles = np.arange(0., 10, 0.85)
series = io.ImageFileSeries(os.path.join(dir, "20180704_Transmission_CT_%s_0080.*"), ['0010'])
# print autocrop.calculateCropWindow(series)
assert np.allclose(
autocrop.calculateCropWindow(series),
(627, 1442, 648, 1468)
)
return


def test2a():
dir = os.path.join(here, "..", "iMars3D_data_set", "autocrop", "darkboundaries")
dir = os.path.abspath(dir)
series = io.ImageFileSeries(
os.path.join(dir, "20180918_A49_4_CT_afterStableCycling_normalized_%7.3f.tiff"),
[300.300],
decimal_mark_replacement='.',
)
assert np.allclose(
autocrop.calculateCropWindow(series),
(767, 1309, 566, 1163),
)
return


def test3():
dir = os.path.join(here, "..", "iMars3D_data_set", "autocrop", "dark-bottom")
dir = os.path.abspath(dir)
series = io.ImageFileSeries(os.path.join(dir, "sm-estimate-ave%s.tiff"), [''])
# print autocrop.calculateCropWindow(series)
assert np.allclose(
autocrop.calculateCropWindow(series),
(0, 2047, 1163, 2047)
Expand All @@ -45,6 +62,7 @@ def test3():
def main():
test()
test2()
test2a()
test3()
return

Expand Down

0 comments on commit f8eae90

Please sign in to comment.