Example #1
0
def use_img_classifier_in_mem(
    clf, segmenter_args, label_to_colors_args, img_path, out_img
):
    img = skimage.io.imread(img_path)
    seg, clf = image_segmentation.trainable_segmentation(img, clf=clf, **segmenter_args)
    color_seg = shapes_to_segmentations.label_to_colors(seg, **label_to_colors_args)
    segimgpil = plot_common.img_array_to_pil_image(color_seg)
    segimgpil.save(out_img)
Example #2
0
def use_img_classifier_in_mem(
    clf, segmenter_args, label_to_colors_args, img_path, out_img
):
    img = skimage.io.imread(img_path)

    features = multiscale_basic_features(
        img,
        sigma_min=segmenter_args["sigma_min"],
        sigma_max=segmenter_args["sigma_max"],
        **segmenter_args["segmentation_features_dict"],
    )
    seg = predict_segmenter(features, clf)
    color_seg = shapes_to_segmentations.label_to_colors(seg, **label_to_colors_args)
    segimgpil = plot_common.img_array_to_pil_image(color_seg)
    segimgpil.save(out_img)
Example #3
0
def show_segmentation(image_path, mask_shapes, features, segmenter_args):
    """ adds an image showing segmentations to a figure's layout """
    # add 1 because classifier takes 0 to mean no mask
    shape_layers = [color_to_class(shape["line"]["color"]) + 1 for shape in mask_shapes]
    label_to_colors_args = {
        "colormap": class_label_colormap,
        "color_class_offset": -1,
    }
    segimg, _, clf = compute_segmentations(
        mask_shapes,
        img_path=image_path,
        shape_layers=shape_layers,
        label_to_colors_args=label_to_colors_args,
        features=features,
    )
    # get the classifier that we can later store in the Store
    classifier = save_img_classifier(clf, label_to_colors_args, segmenter_args)
    segimgpng = plot_common.img_array_to_pil_image(segimg)
    return (segimgpng, classifier)