Beispiel #1
0
def stitch_with_stitched(result, imageB, info, thresh, vertical=False):
    '''
    stitch the prediction on a stitched image with a raw image.
    '''
    visual = Visualizer()
    print(result[0].shape)

    final_image = make_overlap(result[0], imageB, vertical=vertical)

    prediction_B = get_prediction(imageB, info, display=False)

    if not vertical:
        masks_A, boxes_A = remove_predictions_on_edge(result[1],
                                                      result[2],
                                                      result[0].shape,
                                                      edge='right')
    else:
        masks_A, boxes_A = remove_predictions_on_edge(result[1],
                                                      result[2],
                                                      result[0].shape,
                                                      edge='bottom')

    masks_kept, boxes_kept = remove_overlapped_masks(
        prediction_B.get_field("mask"),
        prediction_B.bbox,
        thresh,
        final_image.shape,
        vertical=vertical)

    stitched_masks, stitched_boxes = visual.display_stitched_instances(
        final_image[:, :, ::-1],
        boxes_A,
        masks_A,
        boxes_kept,
        masks_kept,
        show_mask=False)
    plt.clf()
    stitched_masks = convert_to_torch(stitched_masks)
    stitched_boxes = convert_to_torch(stitched_boxes)

    return [final_image, stitched_masks, stitched_boxes]
Beispiel #2
0
def stitch(imageA, imageB, info, thresh=100, vertical=False):
    '''
    get the prediction of imageA and imageB and stitch the prediction together
    '''
    result = make_overlap(imageA, imageB, vertical=vertical)

    prediction_A = get_prediction(imageA, info, display=False)
    prediction_B = get_prediction(imageB, info, display=False)

    if not vertical:
        masks_A, boxes_A = remove_predictions_on_edge(
            prediction_A.get_field("mask"),
            prediction_A.bbox,
            imageA.shape,
            edge='right')
    else:
        masks_A, boxes_A = remove_predictions_on_edge(
            prediction_A.get_field("mask"),
            prediction_A.bbox,
            imageA.shape,
            edge='bottom')

    masks_kept, boxes_kept = remove_overlapped_masks(
        prediction_B.get_field("mask"),
        prediction_B.bbox,
        thresh,
        result.shape,
        vertical=vertical)

    visual = Visualizer()
    stitched_masks, stitched_boxes = visual.display_stitched_instances(
        result[:, :, ::-1],
        boxes_A,
        masks_A,
        boxes_kept,
        masks_kept,
        show_mask=False)
    plt.clf()
    return result, stitched_masks, stitched_boxes
Beispiel #3
0
def stitch_two_stitched(imageA, imageB, thresh, vertical=True):
    '''
    stitch the stitched images together from the other direction.
    '''
    visual = Visualizer()

    final_image = make_overlap(imageA[0], imageB[0], vertical=vertical)

    if not vertical:
        masks_A, boxes_A = remove_predictions_on_edge(imageA[1],
                                                      imageA[2],
                                                      imageA[0].shape,
                                                      edge='right')
    else:
        masks_A, boxes_A = remove_predictions_on_edge(imageA[1],
                                                      imageA[2],
                                                      imageA[0].shape,
                                                      edge='bottom')

    masks_kept, boxes_kept = remove_overlapped_masks(imageB[1],
                                                     imageB[2],
                                                     thresh,
                                                     final_image.shape,
                                                     vertical=vertical)
    #print(len(masks_kept))
    stitched_masks, stitched_boxes = visual.display_stitched_instances(
        final_image[:, :, ::-1],
        boxes_A,
        masks_A,
        boxes_kept,
        masks_kept,
        show_mask=False)
    plt.clf()
    stitched_masks = convert_to_torch(stitched_masks)
    stitched_boxes = convert_to_torch(stitched_boxes)

    return [final_image, stitched_masks, stitched_boxes]