Merge pull request #406 from blink1073/bug-adapthist-py3k

BUG: Adapthist 3.x fixes.
This commit is contained in:
Stefan van der Walt
2013-01-10 02:56:38 -08:00
2 changed files with 13 additions and 11 deletions
+5 -5
View File
@@ -158,11 +158,11 @@ def _clahe(image, ntiles_x, ntiles_y, clip_limit, nbins=128):
for y in range(ntiles_y + 1):
xstart = 0
if y == 0: # special case: top row
ystep = y_size / 2
ystep = y_size / 2.0
yU = 0
yB = 0
elif y == ntiles_y: # special case: bottom row
ystep = y_size / 2
ystep = y_size / 2.0
yU = ntiles_y - 1
yB = yU
else: # default values
@@ -172,11 +172,11 @@ def _clahe(image, ntiles_x, ntiles_y, clip_limit, nbins=128):
for x in range(ntiles_x + 1):
if x == 0: # special case: left column
xstep = x_size / 2
xstep = x_size / 2.0
xL = 0
xR = 0
elif x == ntiles_x: # special case: right column
xstep = x_size / 2
xstep = x_size / 2.0
xL = ntiles_x - 1
xR = xL
else: # default values
@@ -226,7 +226,7 @@ def clip_histogram(hist, clip_limit):
n_excess = excess.sum() - excess.size * clip_limit
# Second part: clip histogram and redistribute excess pixels in each bin
bin_incr = n_excess / hist.size # average binincrement
bin_incr = int(n_excess / hist.size) # average binincrement
upper = clip_limit - bin_incr # Bins larger than upper set to cliplimit
hist[excess_mask] = clip_limit
+8 -6
View File
@@ -87,8 +87,9 @@ def test_adapthist_scalar():
full_scale = skimage.exposure.rescale_intensity(skimage.img_as_uint(img))
assert_almost_equal = np.testing.assert_almost_equal
assert peak_snr(full_scale, adapted) > 95.0
assert norm_brightness_err(full_scale, adapted) < 0.05
assert_almost_equal(peak_snr(full_scale, adapted), 101.231, 3)
assert_almost_equal(norm_brightness_err(full_scale, adapted),
0.041, 3)
return img, adapted
@@ -102,8 +103,8 @@ def test_adapthist_grayscale():
nbins=128)
assert_almost_equal = np.testing.assert_almost_equal
assert img.shape == adapted.shape
assert peak_snr(img, adapted) > 95.0
assert norm_brightness_err(img, adapted) < 0.05
assert_almost_equal(peak_snr(img, adapted), 97.531, 3)
assert_almost_equal(norm_brightness_err(img, adapted), 0.0313, 3)
return data, adapted
@@ -117,8 +118,9 @@ def test_adapthist_color():
assert adapted.max() == 1.0
assert img.shape == adapted.shape
full_scale = skimage.exposure.rescale_intensity(img)
assert peak_snr(img, adapted) > 95.0
assert norm_brightness_err(img, adapted) < 0.05
assert_almost_equal(peak_snr(full_scale, adapted), 102.940, 3)
assert_almost_equal(norm_brightness_err(full_scale, adapted),
0.0110, 3)
return data, adapted