def test_patchify(self): array = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) patches = sr_image_util.patchify(array, [3, 3], 1) expected_patches = np.array([[6, 5, 6, 2, 1, 2, 6, 5, 6], [5, 6, 7, 1, 2, 3, 5, 6, 7], [6, 7, 8, 2, 3, 4, 6, 7, 8], [7, 8, 7, 3, 4, 3, 7, 8, 7], [8, 7, 6, 4, 3, 2, 8, 7, 6], [2, 1, 2, 6, 5, 6, 10, 9, 10], [1, 2, 3, 5, 6, 7, 9, 10, 11], [2, 3, 4, 6, 7, 8, 10, 11, 12], [3, 4, 3, 7, 8, 7, 11, 12, 11], [4, 3, 2, 8, 7, 6, 12, 11, 10], [6, 5, 6, 10, 9, 10, 14, 13, 14], [5, 6, 7, 9, 10, 11, 13, 14, 15], [6, 7, 8, 10, 11, 12, 14, 15, 16], [7, 8, 7, 11, 12, 11, 15, 16, 15], [8, 7, 6, 12, 11, 10, 16, 15, 14], [10, 9, 10, 14, 13, 14, 10, 9, 10], [9, 10, 11, 13, 14, 15, 9, 10, 11], [10, 11, 12, 14, 15, 16, 10, 11, 12], [11, 12, 11, 15, 16, 15, 11, 12, 11], [12, 11, 10, 16, 15, 14, 12, 11, 10], [14, 13, 14, 10, 9, 10, 6, 5, 6], [13, 14, 15, 9, 10, 11, 5, 6, 7], [14, 15, 16, 10, 11, 12, 6, 7, 8], [15, 16, 15, 11, 12, 11, 7, 8, 7], [16, 15, 14, 12, 11, 10, 8, 7, 6]]) self.assertTrue(np.array_equal(expected_patches, patches)) with self.assertRaises(SRException): sr_image_util.patchify(array, [3, 4])
def test_patchify(self): array = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) patches = sr_image_util.patchify(array, [3, 3], 1) expected_patches = np.array( [ [6, 5, 6, 2, 1, 2, 6, 5, 6], [5, 6, 7, 1, 2, 3, 5, 6, 7], [6, 7, 8, 2, 3, 4, 6, 7, 8], [7, 8, 7, 3, 4, 3, 7, 8, 7], [8, 7, 6, 4, 3, 2, 8, 7, 6], [2, 1, 2, 6, 5, 6, 10, 9, 10], [1, 2, 3, 5, 6, 7, 9, 10, 11], [2, 3, 4, 6, 7, 8, 10, 11, 12], [3, 4, 3, 7, 8, 7, 11, 12, 11], [4, 3, 2, 8, 7, 6, 12, 11, 10], [6, 5, 6, 10, 9, 10, 14, 13, 14], [5, 6, 7, 9, 10, 11, 13, 14, 15], [6, 7, 8, 10, 11, 12, 14, 15, 16], [7, 8, 7, 11, 12, 11, 15, 16, 15], [8, 7, 6, 12, 11, 10, 16, 15, 14], [10, 9, 10, 14, 13, 14, 10, 9, 10], [9, 10, 11, 13, 14, 15, 9, 10, 11], [10, 11, 12, 14, 15, 16, 10, 11, 12], [11, 12, 11, 15, 16, 15, 11, 12, 11], [12, 11, 10, 16, 15, 14, 12, 11, 10], [14, 13, 14, 10, 9, 10, 6, 5, 6], [13, 14, 15, 9, 10, 11, 5, 6, 7], [14, 15, 16, 10, 11, 12, 6, 7, 8], [15, 16, 15, 11, 12, 11, 7, 8, 7], [16, 15, 14, 12, 11, 10, 8, 7, 6], ] ) self.assertTrue(np.array_equal(expected_patches, patches)) with self.assertRaises(SRException): sr_image_util.patchify(array, [3, 4])
def patchify(self, patch_size, interval=1): """Create an array of image patches with the given patch size. @param patch_size: size of the patch @type patch_size: two dimensional list of the patch size @return: an array contains all the patches from the image @rtype: L{numpy.array} """ image_array = self._y_data return sr_image_util.patchify(image_array, patch_size, interval)
def patchify(self, patch_size): """Create an array of image patches with the given patch size. @param patch_size: size of the patch @type patch_size: two dimensional list of the patch size @return: an array contains all the patches from the image @rtype: L{numpy.array} """ image_array = np.reshape(np.array(list(self._image.getdata())), self._size) return sr_image_util.patchify(image_array, patch_size)