def from_sr_image(cls, sr_image): """Create a SRDataset object from a SRImage object. @param sr_image: @type sr_image: L{sr_image.SRImage} @return: SRDataset object @rtype: L{sr_dataset.SRDataset} """ high_res_patches = sr_image_util.get_patches_without_dc(sr_image) sr_dataset = SRDataSet(high_res_patches, high_res_patches) for downgraded_sr_image in sr_image.get_pyramid(DEFAULT_PYRAMID_LEVEL, DEFAULT_DOWNGRADE_RATIO): low_res_patches = sr_image_util.get_patches_without_dc(downgraded_sr_image) sr_dataset.add(low_res_patches, high_res_patches) return sr_dataset
def test_get_patches_without_dc(self): sr_image = mock.Mock() sr_image.patchify.return_value = np.array([[1, 2, 3], [4, 5, 6]]) patches_without_dc = sr_image_util.get_patches_without_dc(sr_image) expected_patches_without_dc = np.array([[-1, 0, 1], [-1, 0, 1]]) self.assertTrue( np.array_equal(expected_patches_without_dc, patches_without_dc))
def from_sr_image(cls, sr_image, pyramid_level=DEFAULT_PYRAMID_LEVEL, downgrade_ratio=DEFAULT_DOWNGRADE_RATIO): """Create a SRDataset object from a SRImage object. @param sr_image: @type sr_image: L{sr_image.SRImage} @return: SRDataset object @rtype: L{sr_dataset.SRDataset} """ high_res_patches = sr_image_util.get_patches_without_dc(sr_image) sr_dataset = None for downgraded_sr_image in sr_image.get_pyramid(pyramid_level, downgrade_ratio): low_res_patches = sr_image_util.get_patches_without_dc(downgraded_sr_image) if sr_dataset is None: sr_dataset = SRDataSet(low_res_patches, high_res_patches) else: sr_dataset.add(low_res_patches, high_res_patches) return sr_dataset
def test_get_patches_without_dc(self): sr_image = mock.Mock() sr_image.patchify.return_value = np.array([[1, 2, 3], [4, 5, 6]]) patches_without_dc = sr_image_util.get_patches_without_dc(sr_image) expected_patches_without_dc = np.array([[-1, 0, 1], [-1, 0, 1]]) self.assertTrue(np.array_equal(expected_patches_without_dc, patches_without_dc))