def test_get_patches_from(self): sr_image = mock.Mock() sr_image.patchify.return_value = np.array([[1, 2, 3], [4, 5, 6]]) patches_without_dc, patches_dc = sr_image_util.get_patches_from(sr_image) expected_patches_without_dc = np.array([[-1, 0, 1], [-1, 0, 1]]) expected_patches_dc = np.array([[2, 2, 2], [5, 5, 5]]) self.assertTrue(np.array_equal(expected_patches_without_dc, patches_without_dc)) self.assertTrue(np.array_equal(expected_patches_dc, patches_dc))
def test_get_patches_from(self): sr_image = mock.Mock() sr_image.patchify.return_value = np.array([[1, 2, 3], [4, 5, 6]]) patches_without_dc, patches_dc = sr_image_util.get_patches_from( sr_image) expected_patches_without_dc = np.array([[-1, 0, 1], [-1, 0, 1]]) expected_patches_dc = np.array([[2, 2, 2], [5, 5, 5]]) self.assertTrue( np.array_equal(expected_patches_without_dc, patches_without_dc)) self.assertTrue(np.array_equal(expected_patches_dc, patches_dc))
def _reconstruct(self, ratio, sr_image, sr_dataset): """Reconstruct a SRImage using the given SRDataset by the given ratio. @param ratio: reconstruct ratio @type ratio: float @param sr_image: original SRImage @type sr_image: L{sr_image.SRImage} @param sr_dataset: @type sr_dataset: L{sr_dataset.SRDataset} @return: reconstructed SRImage @rtype: L{sr_image.SRImage} """ resized_sr_image = sr_image.resize(ratio) patches_without_dc, patches_dc = sr_image_util.get_patches_from(resized_sr_image, interval=4) high_res_patches_without_dc = sr_dataset.parallel_query(patches_without_dc) high_res_patches = high_res_patches_without_dc + patches_dc high_res_data = sr_image_util.unpatchify(high_res_patches, resized_sr_image.size, self._kernel) resized_sr_image.putdata(high_res_data) return resized_sr_image
def _reconstruct(self, ratio, sr_image, sr_dataset): """Reconstruct a SRImage using the given SRDataset by the given ratio. @param ratio: reconstruct ratio @type ratio: float @param sr_image: original SRImage @type sr_image: L{sr_image.SRImage} @param sr_dataset: @type sr_dataset: L{sr_dataset.SRDataset} @return: reconstructed SRImage @rtype: L{sr_image.SRImage} """ resized_sr_image = sr_image.resize(ratio) patches_without_dc, patches_dc = sr_image_util.get_patches_from( resized_sr_image, interval=4) high_res_patches_without_dc = sr_dataset.parallel_query( patches_without_dc) high_res_patches = high_res_patches_without_dc + patches_dc high_res_data = sr_image_util.unpatchify(high_res_patches, resized_sr_image.size, self._kernel) resized_sr_image.putdata(high_res_data) return resized_sr_image