diff --git a/scikits/image/transform/__init__.py b/scikits/image/transform/__init__.py index 407ab0d4..341671d1 100644 --- a/scikits/image/transform/__init__.py +++ b/scikits/image/transform/__init__.py @@ -1,4 +1,4 @@ from .hough_transform import * from .finite_radon_transform import * from .project import * -from .sum_area_table import * +from .integral import * diff --git a/scikits/image/transform/sum_area_table.py b/scikits/image/transform/integral.py similarity index 65% rename from scikits/image/transform/sum_area_table.py rename to scikits/image/transform/integral.py index 6496d7d3..440d10e6 100644 --- a/scikits/image/transform/sum_area_table.py +++ b/scikits/image/transform/integral.py @@ -1,5 +1,5 @@ -def sat(x): - """Summed area table / integral image. +def integral_image(x): + """Integral image / summed area table. The integral image contains the sum of all elements above and to the left of it, i.e.: @@ -10,13 +10,13 @@ def sat(x): Parameters ---------- - X : ndarray + x : ndarray Input image. Returns ------- S : ndarray - Summed area table. + Integral image / summed area table. References ---------- @@ -26,13 +26,13 @@ def sat(x): """ return x.cumsum(1).cumsum(0) -def sat_sum(sat, r0, c0, r1, c1): - """Use a summed area table / integral image to sum over a given window. +def integrate(ii, r0, c0, r1, c1): + """Use an integral image to integrate over a given window. Parameters ---------- - sat : ndarray - Summed area table / integral image. + ii : ndarray + Integral image. r0, c0 : int Top-left corner of block to be summed. r1, c1 : int @@ -41,20 +41,20 @@ def sat_sum(sat, r0, c0, r1, c1): Returns ------- S : int - Sum over the given window. + Integral (sum) over the given window. """ S = 0 - S += sat[r1, c1] + S += ii[r1, c1] if (r0 - 1 >= 0) and (c0 - 1 >= 0): - S += sat[r0 - 1, c0 - 1] + S += ii[r0 - 1, c0 - 1] if (r0 - 1 >= 0): - S -= sat[r0 - 1, c1] + S -= ii[r0 - 1, c1] if (c0 - 1 >= 0): - S -= sat[r1, c0 - 1] + S -= ii[r1, c0 - 1] return S diff --git a/scikits/image/transform/tests/test_integral.py b/scikits/image/transform/tests/test_integral.py new file mode 100644 index 00000000..65cdd632 --- /dev/null +++ b/scikits/image/transform/tests/test_integral.py @@ -0,0 +1,28 @@ +import numpy as np +from numpy.testing import * + +from scikits.image.transform import integral_image, integrate + +x = (np.random.random((50, 50)) * 255).astype(np.uint8) +s = integral_image(x) + +def test_validity(): + y = np.arange(12).reshape((4,3)) + + y = (np.random.random((50, 50)) * 255).astype(np.uint8) + assert_equal(integral_image(y)[-1, -1], + y.sum()) + +def test_basic(): + assert_equal(x[12:24, 10:20].sum(), integrate(s, 12, 10, 23, 19)) + assert_equal(x[:20, :20].sum(), integrate(s, 0, 0, 19, 19)) + assert_equal(x[:20, 10:20].sum(), integrate(s, 0, 10, 19, 19)) + assert_equal(x[10:20, :20].sum(), integrate(s, 10, 0, 19, 19)) + +def test_single(): + assert_equal(x[0, 0], integrate(s, 0, 0, 0, 0)) + assert_equal(x[10, 10], integrate(s, 10, 10, 10, 10)) + + +if __name__ == '__main__': + run_module_suite() diff --git a/scikits/image/transform/tests/test_sat.py b/scikits/image/transform/tests/test_sat.py deleted file mode 100644 index 481d8e28..00000000 --- a/scikits/image/transform/tests/test_sat.py +++ /dev/null @@ -1,28 +0,0 @@ -import numpy as np -from numpy.testing import * - -from scikits.image.transform import sat, sat_sum - -x = (np.random.random((50, 50)) * 255).astype(np.uint8) -s = sat(x) - -def test_validity(): - y = np.arange(12).reshape((4,3)) - - y = (np.random.random((50, 50)) * 255).astype(np.uint8) - assert_equal(sat(y)[-1, -1], - y.sum()) - -def test_basic(): - assert_equal(x[12:24, 10:20].sum(), sat_sum(s, 12, 10, 23, 19)) - assert_equal(x[:20, :20].sum(), sat_sum(s, 0, 0, 19, 19)) - assert_equal(x[:20, 10:20].sum(), sat_sum(s, 0, 10, 19, 19)) - assert_equal(x[10:20, :20].sum(), sat_sum(s, 10, 0, 19, 19)) - -def test_single(): - assert_equal(x[0, 0], sat_sum(s, 0, 0, 0, 0)) - assert_equal(x[10, 10], sat_sum(s, 10, 10, 10, 10)) - - -if __name__ == '__main__': - run_module_suite()