Exemple #1
0
    def reconstruct(self, ratio, sr_image):
        """Reconstruct the SR image by the given ratio.

        @param ratio: reconstruct ratio
        @type ratio: float
        @param sr_image: original SR image
        @type sr_image: L{sr_image.SRImage}
        @return: reconstructed SR image
        @rtype: L{sr_image.SRImage}
        """
        sr_dataset = SRDataSet.from_sr_image(sr_image)
        reconstructed_sr_image = sr_image
        construct_level = int(math.log(ratio, ALPHA) + 0.5)
        r = ALPHA
        for level in range(construct_level):
            reconstructed_sr_image = self._reconstruct(r,
                                                       reconstructed_sr_image,
                                                       sr_dataset)
            reconstructed_sr_image = sr_image_util.back_project(
                reconstructed_sr_image, sr_image, 3, level + 1)
            new_sr_dataset = SRDataSet.from_sr_image(reconstructed_sr_image)
            sr_dataset.merge(new_sr_dataset)
            sys.stdout.write("\rReconstructing %.2f%%" %
                             (float(level + 1) / construct_level * 100))
            sys.stdout.flush()
        return reconstructed_sr_image
Exemple #2
0
    def reconstruct(self, ratio, sr_image):
        """
        Reconstruct the SR image by the given ratio.

        :param ratio: reconstruct ratio
        :type ratio: float
        :param sr_image: original SR image
        :type sr_image: L{sr_image.SRImage}
        :return: reconstructed SR image
        :rtype: L{sr_image.SRImage}
        """
        # import matplotlib.pyplot as plt

        sr_dataset = SRDataSet.from_sr_image(sr_image)
        reconstructed_sr_image = sr_image
        construct_level = 1  # int(math.log(ratio, ALPHA) + 0.5)
        r = ALPHA
        for level in xrange(construct_level):
            reconstructed_sr_image = self._reconstruct(r,
                                                       reconstructed_sr_image,
                                                       sr_dataset)
            reconstructed_sr_image = sr_image_util.back_project(
                reconstructed_sr_image, sr_image, 3, level + 1)
            new_sr_dataset = SRDataSet.from_sr_image(reconstructed_sr_image)
            # plt.imshow(reconstructed_sr_image)
            # plt.show()
            sr_dataset.merge(new_sr_dataset)
            sys.stdout.write("\rReconstructing %.2f%%" %
                             (float(level + 1) / construct_level * 100))
            sys.stdout.flush()
        return reconstructed_sr_image
Exemple #3
0
 def test_from_sr_image(self):
     sr_image = sr_image_factory.SRImageFactory.create_sr_image_from(
         "test_data/babyface_4.png")
     sr_dataset = SRDataSet.from_sr_image(sr_image)
     low_res_patches = sr_dataset.low_res_patches
     high_res_patches = sr_dataset.high_res_patches
     self.assertEqual(np.shape(low_res_patches), np.shape(high_res_patches))
Exemple #4
0
    def reconstruct(self, ratio, sr_image):
        """Reconstruct the SR image by the given ratio.

        @param ratio: reconstruct ratio
        @type ratio: float
        @param sr_image: original SR image
        @type sr_image: L{sr_image.SRImage}
        @return: reconstructed SR image
        @rtype: L{sr_image.SRImage}
        """
        sr_dataset = SRDataSet.from_sr_image(sr_image)
        reconstructed_sr_image = sr_image
        r = ratio ** (1.0/DEFAULT_RECONSTRUCT_LEVEL)
        for level in range(DEFAULT_RECONSTRUCT_LEVEL):
            reconstructed_sr_image = self._reconstruct(r, reconstructed_sr_image, sr_dataset)
            new_sr_dataset = SRDataSet.from_sr_image(reconstructed_sr_image)
            sr_dataset.merge(new_sr_dataset)
        return reconstructed_sr_image
Exemple #5
0
    def reconstruct(self, ratio, sr_image):
        """Reconstruct the SR image by the given ratio.

        @param ratio: reconstruct ratio
        @type ratio: float
        @param sr_image: original SR image
        @type sr_image: L{sr_image.SRImage}
        @return: reconstructed SR image
        @rtype: L{sr_image.SRImage}
        """
        sr_dataset = SRDataSet.from_sr_image(sr_image)
        reconstructed_sr_image = sr_image
        construct_level = int(math.log(ratio, ALPHA) + 0.5)
        r = ALPHA
        for level in range(construct_level):
            reconstructed_sr_image = self._reconstruct(r, reconstructed_sr_image, sr_dataset)
            reconstructed_sr_image = sr_image_util.back_project(reconstructed_sr_image, sr_image,
                                                                3, level+1)
            new_sr_dataset = SRDataSet.from_sr_image(reconstructed_sr_image)
            sr_dataset.merge(new_sr_dataset)
            sys.stdout.write("\rReconstructing %.2f%%" % (float(level+1) /
                                                          construct_level * 100))
            sys.stdout.flush()
        return reconstructed_sr_image
Exemple #6
0
 def test_from_sr_image(self):
     sr_image = sr_image_factory.SRImageFactory.create_sr_image_from("test_data/babyface_4.png")
     sr_dataset = SRDataSet.from_sr_image(sr_image)
     low_res_patches = sr_dataset.low_res_patches
     high_res_patches = sr_dataset.high_res_patches
     self.assertEqual(np.shape(low_res_patches), np.shape(high_res_patches))