コード例 #1
0
def worker_super_resolution_one(image,
                                new_heigth=None,
                                new_width=None,
                                save_filename="huey_SR_test"):

    current_heigth, current_width = image.shape[:2]
    resized_image = image

    if new_heigth is not None:
        if new_width is not None:
            resized_image = cv2.resize(image, (new_width, new_heigth))
        else:
            resized_image = cv2.resize(image, (current_width, new_heigth))
    else:
        if new_width is not None:
            resized_image = cv2.resize(image, (new_width, current_heigth))

    logging.info("Image has been resized from {} to {}".format(
        image.shape, resized_image.shape))

    processor = ImageProcessor()

    model = get_model_by_name("super_resolution_model")

    new_image = processor.process_image(image=resized_image,
                                        model=model,
                                        overlay=20)

    cv2.imwrite("./processed_images/{}.png".format(save_filename), new_image)

    return new_image
コード例 #2
0
def worker_general(image, model_name, save_filename="bad_filename"):
    model = get_model_by_name(model_name)

    processor = ImageProcessor()

    new_image = processor.process_image(image=image, model=model, overlay=20)
    cv2.imwrite("./processed_images/{}.png".format(save_filename), new_image)
    return new_image
コード例 #3
0
    def test_image_processing(self):
        test_image = cv2.imread("./test_data/test_image.jpg")[:224, :224, :]
        proc = ImageProcessor()

        name = "super_resolution_model"
        with open(join(ROOT_DIR, 'GAN/Models/{}.json'.format(name)),
                  'r') as json_file:
            model = model_from_json(json_file.read())
        model.load_weights(join(ROOT_DIR, "GAN/Models/{}.h5".format(name)))
        model._make_predict_function()

        result = proc.process_image(image=test_image, model=model, overlay=20)

        processed_test_image = cv2.imread(
            "./test_data/test_image_processed.png")

        self.assertListEqual(list(result[100][100]),
                             list(processed_test_image[100][100]))
コード例 #4
0
                  'r') as json_file:
            loaded_model = model_from_json(json_file.read())

        loaded_model.load_weights(
            "E:/Licenta/Licenta/GAN//Models/super_resolution_model.h5")
        # loaded_model.summary()

        global model_graph
        model_graph = tf.get_default_graph()

        # Test on image
        processor = ImageProcessor()

        image = cv2.imread("E:/AiDatasets/Licenta/Test/data/test1.jpg")

        cv2.imwrite("E:/AiDatasets/Licenta/Test/results/test1_3_original.jpg",
                    image)

        img_h, img_w, _ = image.shape
        image = cv2.resize(image, (img_w // 4, img_h // 4))
        image = cv2.resize(image, (img_w, img_h))
        cv2.imwrite("E:/AiDatasets/Licenta/Test/results/test1_1_downRes.jpg",
                    image)

        new_image = processor.process_image(image=image,
                                            model=loaded_model,
                                            model_graph=model_graph,
                                            overlay=0)
        cv2.imwrite("E:/AiDatasets/Licenta/Test/results/test1_2_generated.jpg",
                    new_image)