Ejemplo n.º 1
0
 def test_edgeBackgroundYBelow0_stretch(self):
     roi = [0, 40, 10, 60]
     # Compare patches.
     actual_patch, transform = utilBoxes.cropPatch(self.image,
                                                   roi,
                                                   'background',
                                                   target_height=40,
                                                   target_width=40)
     expected_patch = TestCropPatch.makeGradientImage(height=30,
                                                      width=40,
                                                      min_y=0,
                                                      min_x=40,
                                                      max_y=15,
                                                      max_x=60)
     expected_patch = np.pad(expected_patch,
                             pad_width=((10, 0), (0, 0), (0, 0)),
                             mode='constant')
     norm = (actual_patch.mean() + expected_patch.mean()) / 2.
     actual_patch = actual_patch / norm
     expected_patch = expected_patch / norm
     np.testing.assert_array_almost_equal(actual_patch,
                                          expected_patch,
                                          decimal=0)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = [10, 0, 30, 40]
     self.assertEqual(actual_roi, expected_roi)
Ejemplo n.º 2
0
 def test_edgeOriginal_float(self):
     roi = [40.6, 30, 60, 70.6]
     # Compare patches.
     actual_patch, transform = utilBoxes.cropPatch(self.image, roi,
                                                   'original', None, None)
     expected_patch = TestCropPatch.makeGradientImage(height=19,
                                                      width=41,
                                                      min_y=41,
                                                      min_x=30)
     np.testing.assert_array_equal(actual_patch, expected_patch)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = [0, 0, 19, 41]
     self.assertEqual(actual_roi, expected_roi)
Ejemplo n.º 3
0
 def test_edgeOriginal_identity(self):
     roi = [0, 0, self.HEIGHT, self.WIDTH]
     # Compare patches.
     actual_patch, transform = utilBoxes.cropPatch(self.image, roi,
                                                   'original', None, None)
     expected_patch = TestCropPatch.makeGradientImage(
         self.HEIGHT, self.WIDTH)
     np.testing.assert_array_equal(actual_patch, expected_patch)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = roi
     self.assertEqual(actual_roi, expected_roi)
     # Make sure transform matches.
     np.testing.assert_array_equal(transform, np.eye(3, 3, dtype=float))
Ejemplo n.º 4
0
 def test_edgeOriginal_outOfBoundary4(self):
     roi = [40, 170, 60, 210]
     # Compare patches.
     actual_patch, transform = utilBoxes.cropPatch(self.image, roi,
                                                   'original', None, None)
     expected_patch = TestCropPatch.makeGradientImage(height=20,
                                                      width=30,
                                                      min_y=40,
                                                      min_x=170)
     expected_patch = np.pad(expected_patch, ((0, 0), (0, 10), (0, 0)))
     self.assertEqual(actual_patch.shape, expected_patch.shape)
     np.testing.assert_array_equal(actual_patch, expected_patch)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = [0, 0, 20, 40]
     self.assertEqual(actual_roi, expected_roi)
Ejemplo n.º 5
0
 def test_edgeBackgroundX_noStretch(self):
     roi = [40, 45, 60, 55]
     # Compare patches.
     actual_patch, transform = utilBoxes.cropPatch(self.image,
                                                   roi,
                                                   'background',
                                                   target_height=20,
                                                   target_width=20)
     expected_patch = TestCropPatch.makeGradientImage(height=20,
                                                      width=20,
                                                      min_y=40,
                                                      min_x=40)
     np.testing.assert_array_equal(actual_patch, expected_patch)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = [0, 5, 20, 15]
     self.assertEqual(actual_roi, expected_roi)
Ejemplo n.º 6
0
 def test_edgeDistortY(self):
     roi = [45, 40, 55, 60]
     # Compare patches.
     actual_patch, transform = utilBoxes.cropPatch(self.image,
                                                   roi,
                                                   'distort',
                                                   target_height=20,
                                                   target_width=20)
     expected_patch = TestCropPatch.makeGradientImage(height=20,
                                                      width=20,
                                                      min_y=45,
                                                      min_x=40,
                                                      max_y=55)
     np.testing.assert_array_equal(actual_patch, expected_patch)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = [0, 0, 20, 20]
     self.assertEqual(actual_roi, expected_roi)
Ejemplo n.º 7
0
 def test_edgeBackgroundXBelow0_noStretch(self):
     roi = [40, 0, 60, 10]
     # Compare patches.
     actual_patch, transform = utilBoxes.cropPatch(self.image,
                                                   roi,
                                                   'background',
                                                   target_height=20,
                                                   target_width=20)
     expected_patch = TestCropPatch.makeGradientImage(height=20,
                                                      width=15,
                                                      min_y=40)
     expected_patch = np.pad(expected_patch,
                             pad_width=((0, 0), (5, 0), (0, 0)),
                             mode='constant')
     np.testing.assert_array_equal(actual_patch, expected_patch)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = [0, 5, 20, 15]
     self.assertEqual(actual_roi, expected_roi)
Ejemplo n.º 8
0
 def test_edgeConstant_noStretch(self):
     roi = [40, 30, 60, 70]
     # Compare patches.
     actual_patch, transform = utilBoxes.cropPatch(self.image,
                                                   roi,
                                                   'constant',
                                                   target_height=40,
                                                   target_width=40)
     expected_patch = TestCropPatch.makeGradientImage(height=20,
                                                      width=40,
                                                      min_y=40,
                                                      min_x=30)
     expected_patch = np.pad(expected_patch,
                             pad_width=((10, 10), (0, 0), (0, 0)),
                             mode='constant')
     np.testing.assert_array_equal(actual_patch, expected_patch)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = [10, 0, 30, 40]
     self.assertEqual(actual_roi, expected_roi)
Ejemplo n.º 9
0
 def test_edgeConstant_allImage_noPad(self):
     HEIGHT = 4
     WIDTH = 10
     roi = [0, 0, HEIGHT, WIDTH]
     actual_patch, transform = utilBoxes.cropPatch(self.image[0:HEIGHT,
                                                              0:WIDTH],
                                                   roi,
                                                   'constant',
                                                   target_height=HEIGHT * 2,
                                                   target_width=WIDTH)
     expected_patch = TestCropPatch.makeGradientImage(height=HEIGHT,
                                                      width=WIDTH,
                                                      min_y=0,
                                                      min_x=0)
     expected_patch = np.pad(expected_patch,
                             pad_width=((HEIGHT // 2, HEIGHT // 2), (0, 0),
                                        (0, 0)),
                             mode='constant')
     self.assertEqual(actual_patch.shape, expected_patch.shape)
     np.testing.assert_array_equal(actual_patch, expected_patch)
     # Compare roi.
     actual_roi = TestCropPatch.transformRoi(transform, roi)
     expected_roi = [HEIGHT // 2, 0, HEIGHT * 3 // 2, WIDTH]
     self.assertEqual(actual_roi, expected_roi)
Ejemplo n.º 10
0
 def test_edgeConstant_targetSizeNone(self):
     roi = [40, 30, 60, 70]
     with self.assertRaises(RuntimeError):
         utilBoxes.cropPatch(self.image, roi, 'constant', None, None)