DFP/segmentation_image.py
def display_medkit_mask(image, mask, regions, class_ids, scores, CLASS_NAMES):
    """Display the given image and the top few class masks."""
    to_display = []
    to_display.append(image)
    # Pick top prominent classes in this image
    chosen_class_ids = []
    if len(class_ids) > 0:
        for i in range(len(class_ids)):
            if not class_ids[i] in chosen_class_ids and class_ids[i] in [6,8]:
                chosen_class_ids.append(class_ids[i])

    mask_area = [np.sum(mask[:, :, np.where(class_ids == i)[0]])
                 for i in chosen_class_ids]
    top_ids = [v[0] for v in sorted(zip(chosen_class_ids, mask_area),
                                    key=lambda r: r[1], reverse=True) if v[1] > 0]
    # Generate images and titles
    class_id = top_ids[0] if 0 < len(top_ids) else -1
    # Pull masks of instances belonging to the same class.
    m = mask[:, :, np.where(class_ids == class_id)[0]].astype('float32')
    m = np.sum(m * np.arange(1, m.shape[-1] + 1), -1)

    for i in range(len(regions)):
        m[regions[i][0]:regions[i][2],regions[i][1]:regions[i][3]] = \
        np.sign(m[regions[i][0]:regions[i][2],regions[i][1]:regions[i][3]]) * scores[i]

    # to_display.append(m)
    # visualize.display_images(to_display, titles=['simulator image', 'medkit mask'], cols= 2, cmap="Blues_r")
    return m
Display the given image and the top few class masks.
Display the given image and the top few class masks.
Display the given image and the top few class masks .
def display_medkit_mask(image, mask, regions, class_ids, scores, CLASS_NAMES):
    to_display = []
    to_display.append(image)
    chosen_class_ids = []
    if len(class_ids) > 0:
        for i in range(len(class_ids)):
            if not class_ids[i] in chosen_class_ids and class_ids[i] in [6,8]:
                chosen_class_ids.append(class_ids[i])
    mask_area = [np.sum(mask[:, :, np.where(class_ids == i)[0]])
                 for i in chosen_class_ids]
    top_ids = [v[0] for v in sorted(zip(chosen_class_ids, mask_area),
                                    key=lambda r: r[1], reverse=True) if v[1] > 0]
    class_id = top_ids[0] if 0 < len(top_ids) else -1
    m = mask[:, :, np.where(class_ids == class_id)[0]].astype('float32')
    m = np.sum(m * np.arange(1, m.shape[-1] + 1), -1)
    for i in range(len(regions)):
        m[regions[i][0]:regions[i][2],regions[i][1]:regions[i][3]] = \
        np.sign(m[regions[i][0]:regions[i][2],regions[i][1]:regions[i][3]]) * scores[i]
    return m
def display_medkit_mask ( image , mask , regions , class_ids , scores , CLASS_NAMES ) : to_display = [ ] to_display . append ( image ) chosen_class_ids = [ ] if len ( class_ids ) > 0 : for i in range ( len ( class_ids ) ) : if not class_ids [ i ] in chosen_class_ids and class_ids [ i ] in [ 6 , 8 ] : chosen_class_ids . append ( class_ids [ i ] ) mask_area = [ np . sum ( mask [ : , : , np . where ( class_ids == i ) [ 0 ] ] ) for i in chosen_class_ids ] top_ids = [ v [ 0 ] for v in sorted ( zip ( chosen_class_ids , mask_area ) , key = lambda r : r [ 1 ] , reverse = True ) if v [ 1 ] > 0 ] class_id = top_ids [ 0 ] if 0 < len ( top_ids ) else - 1 m = mask [ : , : , np . where ( class_ids == class_id ) [ 0 ] ] . astype ( 'float32' ) m = np . sum ( m * np . arange ( 1 , m . shape [ - 1 ] + 1 ) , - 1 ) for i in range ( len ( regions ) ) : m [ regions [ i ] [ 0 ] : regions [ i ] [ 2 ] , regions [ i ] [ 1 ] : regions [ i ] [ 3 ] ] = np . sign ( m [ regions [ i ] [ 0 ] : regions [ i ] [ 2 ] , regions [ i ] [ 1 ] : regions [ i ] [ 3 ] ] ) * scores [ i ] return m
Display the given image and the top few class masks.
Display the given image and the top few class masks .
"""Display the given image and the top few class masks.""" # Pick top prominent classes in this image # Generate images and titles # Pull masks of instances belonging to the same class. # to_display.append(m) # visualize.display_images(to_display, titles=['simulator image', 'medkit mask'], cols= 2, cmap="Blues_r")
image
mask
regions
class_ids
scores
CLASS_NAMES