Example #1
0
def run_detection(transform, jpg, out, shape, interpolation, name,
                  LineDetectorClass):
    image = image_cv_from_jpg_fn(jpg)

    image = cv2.resize(image, shape, interpolation=interpolation)

    #     bgr = bgr[bgr.shape[0] / 2:, :, :]

    image_detections = line_detection(LineDetectorClass, image)
    transformed = transform(image)

    transformed_clipped = image_clip_255(transformed)
    transformed_detections = line_detection(LineDetectorClass,
                                            transformed_clipped)

    if not os.path.exists(out):
        os.makedirs(out)
    bn = os.path.splitext(os.path.basename(jpg))[0]

    def write(postfix, im):
        fn = os.path.join(out, '%s.%s.%s.png' % (bn, name, postfix))
        cv2.imwrite(fn, zoom_image(im, 4))

    together = make_images_grid(
        [
            image,  # transformed,
            merge_masks_res(image_detections),
            gray2rgb(image_detections['edges']),
            image_detections['annotated'],
            transformed_clipped,
            merge_masks_res(transformed_detections),
            gray2rgb(transformed_detections['edges']),
            transformed_detections['annotated'],
        ],
        cols=4,
        pad=35,
        bgcolor=[1, 1, 1])

    # write the string "name" in the upper left of image together
    cv2.putText(together, name, (0, 20), cv2.FONT_HERSHEY_SIMPLEX, 1,
                (0, 0, 255), 2)

    return together
Example #2
0
def resize_small_images(image_dict):
    check_isinstance(image_dict, dict)
    max_H, max_W = 0, 0
    for _, image in image_dict.items():
        H, W = image.shape[0:2]
        max_H = max(max_H, W)
        max_W = max(max_W, W)

    d = OrderedDict()
    for k, image in image_dict.items():
        if len(image.shape) == 2:  # grayscale
            image = gray2rgb(image)

        H, W = image.shape[0:2]
        ratio = max(max_H * 1.0 / H, max_W * 1.0 / W)
        ratio = int(np.ceil(ratio))
        if ratio > 1:
            image2 = d8_image_zoom_linear(image, ratio)
        else:
            image2 = image
        d[k] = image2
    return d
Example #3
0
 def yellow(x):
     x = gray2rgb(x)
     x[:, :, R] *= 1
     x[:, :, G] *= 1
     x[:, :, B] *= 0
     return x
Example #4
0
 def red(x):
     x = gray2rgb(x)
     x[:, :, R] *= 1
     x[:, :, G] *= 0
     x[:, :, B] *= 0
     return x
Example #5
0
 def white(x):
     x = gray2rgb(x)
     return x