def test_crop_center(self): I = np.ones([9, 9, 3]) I[4, 4, 1] = 0 # should grab the center pixel. self.assertEqual(np.sum(bmt.crop_center(I, 1)), 2) # test exceptions self.assertRaises(ValueError, bmt.crop_center, I, 0) self.assertRaises(TypeError, bmt.crop_center, I, 'sdf') # For an even size input image, grab the upper left of the four potential center-pixels I = np.ones([10, 10, 3]) I[4, 4, 1] = 0 self.assertEqual(np.sum(bmt.crop_center(I, 1)), 2) # Now, try grabbing a 2 x 2 of an odd size image I = np.ones([9, 9, 3]) I[3, 3, 1] = 0 I[4, 4, 1] = 0 # grabs the upper left 2x2 patch. self.assertEqual(np.sum(bmt.crop_center(I, 2)), 10) # Now, try grabbing a 2 x 2 of an even size image. I = np.ones([10, 10, 3]) I[4, 4, 1] = 0 I[5, 5, 1] = 0 # grabs the center 2x2 patch. self.assertEqual(np.sum(bmt.crop_center(I, 2)), 10) # Now, try grabbing a 3 x 3 of an even size image. I = np.ones([10, 10, 3]) I[3, 3, 1] = 0 # grabs the upper-left 3x3 patch. self.assertEqual(np.sum(bmt.crop_center(I, 3)), 26)
def test_crop_center(self): I = np.ones([9, 9, 3]) I[4, 4, 1] = 0 # should grab the center pixel. self.assertEqual(np.sum(bmt.crop_center(I, 1)), 2) # test exceptions self.assertRaises(ValueError, bmt.crop_center, I, 0) self.assertRaises(TypeError, bmt.crop_center, I, 'sdf') # For an even size input image, grab the upper left of the four potential center-pixels I = np.ones([10, 10, 3]) I[4, 4, 1] = 0 self.assertEqual(np.sum(bmt.crop_center(I, 1)), 2) # Now, try grabbing a 2 x 2 of an odd size image I = np.ones([9, 9, 3]) I[3, 3, 1] = 0 I[4, 4, 1] = 0 # grabs the upper left 2x2 patch. self.assertEqual(np.sum(bmt.crop_center(I, 2)), 10) # Now, try grabbing a 2 x 2 of an even size image. I = np.ones([10, 10, 3]) I[4, 4, 1] = 0 I[5, 5, 1] = 0 # grabs the center 2x2 patch. self.assertEqual(np.sum(bmt.crop_center(I, 2)), 10) # Now, try grabbing a 3 x 3 of an even size image. I = np.ones([10, 10, 3]) I[3, 3, 1] = 0 # grabs the upper-left 3x3 patch. self.assertEqual(np.sum(bmt.crop_center(I, 3)), 26)
def test_crop_center_rectangular(self): I = np.ones([9, 99, 3]) I[4, 49, 1] = 0 self.assertEqual(np.sum(bmt.crop_center(I, 1)), 2)
def test_crop_center_rectangular(self): I = np.ones([9, 99, 3]) I[4, 49, 1] = 0 self.assertEqual(np.sum(bmt.crop_center(I, 1)), 2)