def test_int(self): # test for uint8 im = np.zeros((2, 2), np.float) im = Image(im) nt.assert_array_almost_equal(im.int().image, np.zeros((2, 2), np.uint8)) im = np.ones((2, 2), np.float) im = Image(im) nt.assert_array_almost_equal(im.int().image, 255 * np.ones( (2, 2)).astype(np.uint8)) # tests for shape im = np.random.randint(1, 255, (3, 5), int) im = Image(im) imi = im.int() nt.assert_array_almost_equal(imi.shape, im.shape) im = np.random.randint(1, 255, (3, 5, 3), int) im = Image(im) imi = im.int() nt.assert_array_almost_equal(imi.shape, im.shape) im = np.random.randint(1, 255, (3, 5, 3, 10), int) im = Image(im) imi = im.int() nt.assert_array_almost_equal(imi.shape, im.shape)
def test_window(self): im = np.array([[3, 5, 8, 10, 9], [7, 10, 3, 6, 3], [7, 4, 6, 2, 9], [2, 6, 7, 2, 3], [2, 3, 9, 3, 10]]) im = Image(im) se = np.ones((1, 1)) # se must be same number of dimensions as input image for scipy # TODO maybe detect this in im.window and perform this line? # test with different input formats nt.assert_array_almost_equal(im.window(se, np.sum).image, im.image) nt.assert_array_almost_equal( im.int('uint8').window(se, np.sum).image, im.image) nt.assert_array_almost_equal( im.int('uint16').window(se, np.sum).image, im.image) se = np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]]) out = np.array([[43, 47, 57, 56, 59], [46, 43, 51, 50, 57], [45, 48, 40, 39, 31], [33, 40, 35, 49, 48], [22, 40, 36, 53, 44]]) nt.assert_array_almost_equal(im.window(se, np.sum).image, out)
def test_morph1(self): # test simple case im = Image(np.array([[1, 2], [3, 4]])) se = 1 nt.assert_array_almost_equal(im.morph(se, 'min').image, im.image) nt.assert_array_almost_equal(im.morph(se, 'max').image, im.image) nt.assert_array_almost_equal( im.morph(se, oper='min', opt='replicate').image, im.image) nt.assert_array_almost_equal( im.morph(se, oper='min', opt='none').image, im.image) # test different input formats nt.assert_array_almost_equal( im.int('uint8').morph(se, 'min').image, im.image) nt.assert_array_almost_equal( im.int('uint16').morph(se, 'min').image, im.image) nt.assert_array_almost_equal(im.float().morph(se, 'min').image * 255, im.image) im = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0]]) im = Image(im.astype(bool)) nt.assert_array_almost_equal(im.morph(se, 'min').image, im.image)