예제 #1
0
def process_night_image(img, img_out=None):
    # inc_contrast = ImageProcessor(img).change_constrast()
    grey = ImageProcessor(img).convert_to_greyscale()
    bw = ImageProcessor(grey).convert_to_bw_given_thresh(128)
    if img_out:
        cv2.imwrite(img_out, bw)
    return bw
예제 #2
0
def process_map_image(img, img_out=None):
    roads = ImageProcessor(img).get_roads_in_map()
    roads_grey = ImageProcessor(roads).convert_to_greyscale()
    roads_bw = ImageProcessor(roads_grey).convert_to_bw_given_thresh(128)
    if img_out:
        cv2.imwrite(img_out, roads_bw)
    return roads_bw
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
 def __init__(self,
              dataset_name,
              img_res=(224, 224),
              processing_type=Processes.SUPER_RESOLUTION):
     self.dataset_name = dataset_name
     self.img_res = img_res
     self.processing_type = processing_type
     self.image_processor = ImageProcessor()
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
예제 #6
0
    def test_split_image(self):
        test_image = cv2.imread("./test_data/test_image.jpg")
        proc = ImageProcessor()
        results = proc._split_image(deepcopy(test_image), overlay=20)

        self.assertEqual(len(results), 3)
        self.assertEqual(len(results[0]), 4)
        self.assertEqual(results[0][1][0], 1)
        self.assertEqual(results[0][1][1], 0)
예제 #7
0
    def test_merge_image(self):
        test_image = cv2.imread("./test_data/test_image.jpg")
        proc = ImageProcessor()
        results = proc._split_image(deepcopy(test_image), overlay=20)

        new_image = proc._recreate_image(results[0], 224, 224, results[1],
                                         results[2])
        self.assertEqual(test_image[0, 0, 0], new_image[0, 0, 0])
        self.assertEqual(test_image[223, 223, 2], new_image[223, 223, 2])
        self.assertEqual(test_image[223, 0, 2], new_image[223, 0, 2])
        self.assertEqual(test_image[0, 223, 2], new_image[0, 223, 2])
예제 #8
0
def process_images(argv):
    ap = argparse.ArgumentParser()
    ap.add_argument("--map_image", help="path to the map image")
    ap.add_argument("--night_image", help="path to night image")
    ap.add_argument("--output", help="path to store output image")
    ap.add_argument("--background", help="background image to overlay final result on")
    args = vars(ap.parse_args())

    night_img = cv2.imread(args["night_image"])
    map_img = cv2.imread(args["map_image"])
    output_night_img = "night_image_bw.png"
    output_map_img = "map_image_bw.png"

    night_img_bw = process_night_image(night_img, output_night_img)
    map_img_bw = process_map_image(map_img, output_map_img)

    # try to account for skew in night_img_bw
    # - shift image by 5 pixels in each direction
    # - compute bitwise_and of each of these images with the original image
    rows, cols = night_img_bw.shape
    M_list = [
        np.float32([[1, 0, 0],  [0, 1, -5]]),  # shift up
        np.float32([[1, 0, 0],  [0, 1, 5]]),   # shift down
        np.float32([[1, 0, -5], [0, 1, 0]]),   # shift left
        np.float32([[1, 0, 5],  [0, 1, 0]])    # shift right
    ]
    shift_result_list = []
    for M in M_list:
        night_img_shift = cv2.warpAffine(night_img_bw, M, (cols, rows))
        shift_result_list.append(
            cv2.bitwise_and(map_img_bw, cv2.bitwise_not(night_img_shift))
        )

    # map_img_bw AND (NOT night_img_bw)
    # - take shift_result_list also into account to compute result
    result = cv2.bitwise_and(map_img_bw, cv2.bitwise_not(night_img_bw))
    for r in shift_result_list:
        result = cv2.bitwise_and(result, r)

    # convert white to blue
    result = cv2.cvtColor(result, cv2.COLOR_GRAY2BGR)
    result[np.where((result == [255, 255, 255]).all(axis=2))] = [0, 0, 255]

    # convert black to transparent
    result = cv2.cvtColor(result, cv2.COLOR_BGR2RGBA)
    result[np.all(result == [0, 0, 0, 255], axis=2)] = [0, 0, 0, 0]
    result = cv2.cvtColor(result, cv2.COLOR_RGBA2RGB)

    # overlay result on map image
    background = cv2.imread(args['background'])
    final_image = ImageProcessor(background).blend_non_transparent(result)
    cv2.imwrite(args['output'], final_image)
예제 #9
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]))
예제 #10
0
    def test_reduce_yellow(self):
        proc = ImageProcessor()
        test_image = [[
            [1, 2, 3],
            [1, 2, 3],
            [1, 2, 3],
        ], [
            [1, 2, 3],
            [1, 2, 3],
            [1, 2, 3],
        ], [
            [1, 2, 3],
            [1, 2, 3],
            [1, 2, 3],
        ]]
        test_image = np.asarray(test_image, dtype='uint8')

        new_image = proc._reduce_yellow(deepcopy(test_image), 1)

        self.assertEqual(test_image[0, 0, 0] - 1, new_image[0, 0, 0])
        self.assertEqual(test_image[0, 0, 1] - 1, new_image[0, 0, 1])
        self.assertEqual(test_image[0, 0, 2], new_image[0, 0, 2])
예제 #11
0
    parser.add_option('--input', dest='input', action='store', default='', type='str',
                      help='путь к *.ppm или *.pgm файлу')
    parser.add_option('--output', dest='output', action='store', default='', type='str',
                      help='путь к файлу, который следует записать.')
    parser.add_option('--encode', dest='encode', action='store_true', default=False,
                      help='режим кодирования')
    parser.add_option('--decode', dest='decode', action='store_true', default=False,
                      help='режим декодирования')
    parser.add_option('--times', dest='times', action='store', default=1, type='int',
                      help='сколько раз выполнить преобразование')

    options, args = parser.parse_args()

    filename = ''.join(options.input.split('.')[:-1])
    type = options.input.split('.')[-1]
    proc = ImageProcessor()

    try:
        if options.encode or options.decode:

            if options.encode:
                image = proc.read(options.input)
                result = proc.haar_encode(image, options.times)
            else:
                image = proc.read(options.input, compressed=True)
                result = proc.haar_decode(image, options.times)

            if not options.output:
                filename_output = filename + '_tmp.' + type
            else:
                filename_output = options.output