コード例 #1
0
    def do_super_resolution(self, file_path, output_folder="output"):

        filename, extension = os.path.splitext(file_path)
        output_folder = output_folder + "/"
        org_image = util.load_image(file_path)
        util.save_image(output_folder + file_path, org_image)

        if len(org_image.shape
               ) >= 3 and org_image.shape[2] == 3 and self.channels == 1:
            scaled_image = util.resize_image_by_pil_bicubic(
                org_image, self.scale)
            util.save_image(output_folder + filename + "_bicubic" + extension,
                            scaled_image)
            input_ycbcr_image = util.convert_rgb_to_ycbcr(
                scaled_image, jpeg_mode=self.jpeg_mode)
            output_y_image = self.do(input_ycbcr_image[:, :, 0:1])
            util.save_image(output_folder + filename + "_result_y" + extension,
                            output_y_image)

            image = util.convert_y_and_cbcr_to_rgb(output_y_image,
                                                   input_ycbcr_image[:, :,
                                                                     1:3],
                                                   jpeg_mode=self.jpeg_mode)
        else:
            scaled_image = util.resize_image_by_pil_bicubic(
                org_image, self.scale)
            util.save_image(output_folder + filename + "_bicubic" + extension,
                            scaled_image)
            image = self.do(scaled_image)

        util.save_image(output_folder + filename + "_result" + extension,
                        image)
        return 0
コード例 #2
0
    def do_super_resolution(self, file_path, output_folder):

        filename, extension = os.path.splitext(file_path)
        org_image = util.load_image(file_path)
        input_image = util.resize_image_by_bicubic(org_image, self.scale)
        util.save_image("output/" + file_path, org_image)

        if len(input_image.shape
               ) >= 3 or input_image.shape[2] == 3 and self.channels == 1:
            # use y_image for rgb_image
            input_ycbcr_image = util.convert_rgb_to_ycbcr(
                input_image, jpeg_mode=self.jpeg_mode)
            input_y_image = input_ycbcr_image[:, :, 0:1].copy()
            output_y_image = self.do(input_y_image)
            image = util.convert_y_and_cbcr_to_rgb(output_y_image,
                                                   input_ycbcr_image,
                                                   jpeg_mode=self.jpeg_mode)
        else:
            image = self.do(org_image)

        util.save_image("output/" + filename + "_result" + extension, image)
        return 0
コード例 #3
0
	def do_super_resolution_for_test(self, file_path, output_folder="output", output=True):

		filename, extension = os.path.splitext(file_path)
		output_folder = output_folder + "/"
		true_image = util.set_image_alignment(util.load_image(file_path), self.scale)

		if len(true_image.shape) >= 3 and true_image.shape[2] == 3 and self.channels == 1:
			input_y_image = util.build_input_image(true_image, channels=self.channels, scale=self.scale, alignment=self.scale,
			                                       convert_ycbcr=True, jpeg_mode=self.jpeg_mode)
			true_ycbcr_image = util.convert_rgb_to_ycbcr(true_image, jpeg_mode=self.jpeg_mode)

			output_y_image = self.do(input_y_image)
			mse = util.compute_mse(true_ycbcr_image[:, :, 0:1], output_y_image, border_size=self.scale)

			if output:
				output_color_image = util.convert_y_and_cbcr_to_rgb(output_y_image, true_ycbcr_image[:, :, 1:3],
				                                                    jpeg_mode=self.jpeg_mode)
				loss_image = util.get_loss_image(true_ycbcr_image[:, :, 0:1], output_y_image, border_size=self.scale)

				util.save_image(output_folder + file_path, true_image)
				util.save_image(output_folder + filename + "_input" + extension, input_y_image)
				util.save_image(output_folder + filename + "_true_y" + extension, true_ycbcr_image[:, :, 0:1])
				util.save_image(output_folder + filename + "_result" + extension, output_y_image)
				util.save_image(output_folder + filename + "_result_c" + extension, output_color_image)
				util.save_image(output_folder + filename + "_loss" + extension, loss_image)
		else:
			input_image = util.load_input_image(file_path, channels=1, scale=self.scale, alignment=self.scale)
			output_image = self.do(input_image)
			mse = util.compute_mse(true_image, output_image, border_size=self.scale)

			if output:
				util.save_image(output_folder + file_path, true_image)
				util.save_image(output_folder + filename + "_result" + extension, output_image)

		print("MSE:%f PSNR:%f" % (mse, util.get_psnr(mse)))
		return mse
コード例 #4
0
import os
import numpy as np

import super_resolution_utilty as util

print("Data Augmentation For Training Data")

training_filenames = util.get_files_in_directory("data/99/")
augmented_directory = "data/992/"
util.make_dir(augmented_directory)

for file_path in training_filenames:
    org_image = util.load_image(file_path)

    _, filename = os.path.split(file_path)
    filename, extension = os.path.splitext(filename)

    util.save_image(augmented_directory + filename + extension, org_image)
    ud_image = np.flipud(org_image)
    util.save_image(augmented_directory + filename + "_v" + extension,
                    ud_image)
    lr_image = np.fliplr(org_image)
    util.save_image(augmented_directory + filename + "_h" + extension,
                    lr_image)
    lrud_image = np.flipud(lr_image)
    util.save_image(augmented_directory + filename + "_hv" + extension,
                    lrud_image)

print("\nFinished.")
コード例 #5
0
    def do_super_resolution_for_test(self, file_path, output_folder):

        filename, extension = os.path.splitext(file_path)
        true_image = util.set_image_alignment(util.load_image(file_path),
                                              self.scale)
        util.save_image("output/" + file_path, true_image)

        input_image = util.load_input_image(file_path,
                                            channels=self.channels,
                                            scale=self.scale,
                                            alignment=self.scale,
                                            convert_ycbcr=True,
                                            jpeg_mode=self.jpeg_mode)
        util.save_image("output/" + filename + "_input" + extension,
                        input_image)
        input_color_image = util.load_input_image(file_path,
                                                  channels=3,
                                                  scale=self.scale,
                                                  alignment=self.scale,
                                                  convert_ycbcr=False,
                                                  jpeg_mode=self.jpeg_mode)
        util.save_image("output/" + filename + "_input_c" + extension,
                        input_color_image)

        if len(true_image.shape
               ) >= 3 and true_image.shape[2] == 3 and self.channels == 1:
            true_image = util.convert_rgb_to_y(true_image,
                                               jpeg_mode=self.jpeg_mode)
            util.save_image("output/" + filename + "_true" + extension,
                            true_image)
            input_ycbcr_image = util.load_input_image(file_path,
                                                      channels=3,
                                                      scale=self.scale,
                                                      alignment=self.scale,
                                                      convert_ycbcr=True,
                                                      jpeg_mode=self.jpeg_mode)
            output_image = self.do(input_image)
            output_color_image = util.convert_y_and_cbcr_to_rgb(
                output_image,
                input_ycbcr_image[:, :, 1:3],
                jpeg_mode=self.jpeg_mode)
            util.save_image("output/" + filename + "_result_c" + extension,
                            output_color_image)
        else:
            # for monochro or rgb image
            output_image = self.do(input_image)

        mse = util.compute_mse(true_image,
                               output_image,
                               border_size=self.scale)

        util.save_image("output/" + filename + "_result" + extension,
                        output_image)
        print("MSE:%f PSNR:%f" % (mse, util.get_psnr(mse)))
        return mse
コード例 #6
0
ファイル: super_resolution.py プロジェクト: lengji22/DRCN_tf
    def do_super_resolution_for_test(self, file_path, output_folder="output", output=True):

        filename, extension = os.path.splitext(file_path)
        output_folder = output_folder + "/"
        true_image = util.set_image_alignment(util.load_image(file_path), self.scale) #读取文件夹中图片并根据scale图片对准

        if len(true_image.shape) >= 3 and true_image.shape[2] == 3 and self.channels == 1: #图片预处理 
            input_y_image = util.build_input_image(true_image, channels=self.channels, scale=self.scale, alignment=self.scale,
                                                   convert_ycbcr=True, jpeg_mode=self.jpeg_mode) #从true_image中创建网络输入图片测试LR图片
            true_ycbcr_image = util.convert_rgb_to_ycbcr(true_image, jpeg_mode=self.jpeg_mode) # 将true_image从RGB格式转为YCBCR格式HR图片

            output_y_image = self.do(input_y_image) #输入测试LR图片到网络中得到输出
            mse = util.compute_mse(true_ycbcr_image[:, :, 0:1], output_y_image, border_size=self.scale)#计算HR图与输出图的mse

            if output: 
                output_color_image = util.convert_y_and_cbcr_to_rgb(output_y_image, true_ycbcr_image[:, :, 1:3],
                                                                    jpeg_mode=self.jpeg_mode) #把输出图片YCBCR再转为RGB
                loss_image = util.get_loss_image(true_ycbcr_image[:, :, 0:1], output_y_image, border_size=self.scale)#将HR图和LR输出图相减

                util.save_image(output_folder + file_path, true_image)
                util.save_image(output_folder + filename + "_input" + extension, input_y_image)#保存测试LR图片
                util.save_image(output_folder + filename + "_true_y" + extension, true_ycbcr_image[:, :, 0:1])#保存测试HR图片
                util.save_image(output_folder + filename + "_result" + extension, output_y_image)#保存测试输出图片
                util.save_image(output_folder + filename + "_result_c" + extension, output_color_image)#保存输出图片转为RGB图
                util.save_image(output_folder + filename + "_loss" + extension, loss_image)#保存HR图与LR输出图的差值
        else:
            input_image = util.load_input_image(file_path, channels=1, scale=self.scale, alignment=self.scale)
            output_image = self.do(input_image)
            mse = util.compute_mse(true_image, output_image, border_size=self.scale)

            if output:
                util.save_image(output_folder + file_path, true_image)
                util.save_image(output_folder + filename + "_result" + extension, output_image)

        print("MSE:%f PSNR:%f" % (mse, util.get_psnr(mse)))
        return mse
コード例 #7
0
    def do_super_resolution_for_test(self, i, label_file_path, file_path, output_folder="output", output=True):

        true_image = util.set_image_alignment(util.load_image(label_file_path), self.scale)
        output_folder = output_folder + "/"
        filename, extension = os.path.splitext(label_file_path)

        input_y_image = []
        if len(true_image.shape) >= 3 and true_image.shape[2] == 3 and self.channels == 1:
            for j in range (i*5, i*5+5):
                input_image = util.load_input_image(file_path[i], channels=1, scale=self.scale, alignment=self.scale)
                input_y_image.append(input_image)         # convert_ycbcr:True->False
            input_y_image = np.dstack((input_y_image[0], input_y_image[1],
                                       input_y_image[2], input_y_image[3], input_y_image[4]))
            true_ycbcr_image = util.convert_rgb_to_ycbcr(true_image, jpeg_mode=self.jpeg_mode)

            output_y_image = self.do(input_y_image, true_ycbcr_image[:, :, 0:1])
            mse = util.compute_mse(true_ycbcr_image[:, :, 0:1], output_y_image, border_size=self.scale)

            if output:
                output_color_image = util.convert_y_and_cbcr_to_rgb(output_y_image, true_ycbcr_image[:, :, 1:3],
        		                                                    jpeg_mode=self.jpeg_mode)
                loss_image = util.get_loss_image(true_ycbcr_image[:, :, 0:1], output_y_image, border_size=self.scale)

                util.save_image(output_folder + label_file_path, true_image)
                util.save_image(output_folder + filename + "_input" + extension, input_y_image)
                util.save_image(output_folder + filename + "_true_y" + extension, true_ycbcr_image[:, :, 0:1])
                util.save_image(output_folder + filename + "_result" + extension, output_y_image)
                util.save_image(output_folder + filename + "_result_c" + extension, output_color_image)
                util.save_image(output_folder + filename + "_loss" + extension, loss_image)
        else:
            for j in range (i*5, i*5+5):
                input_image = util.load_input_image(file_path[i], channels=1, scale=self.scale, alignment=self.scale)
                input_y_image.append(util.build_input_image(input_image, channels=self.channels, scale=self.scale, alignment=self.scale,
        	                                                convert_ycbcr=False, jpeg_mode=self.jpeg_mode))         # convert_ycbcr:True->False
            input_y_image = np.dstack((input_y_image[0], input_y_image[1],
                                       input_y_image[2], input_y_image[3], input_y_image[4]))
            output_image = self.do(input_y_image, true_image)
            mse = util.compute_mse(true_image, output_image, border_size=self.scale)

            if output:
                util.save_image(output_folder + label_file_path, true_image)
                util.save_image(output_folder + filename + "_result" + extension, output_image)

        print("MSE:%f PSNR:%f" % (mse, util.get_psnr(mse)))
        return mse