Esempio n. 1
0
def show_featuremap(featuremap, win_name='feature_map'):
    print("Feature map shape: ", featuremap.shape)
    print("Feature part value: ", featuremap[0, 0:2, 0:10, 0:10])
    if featuremap.type() == 'torch.FloatTensor':
        featuremap = torch.mean(featuremap, dim=1)
        featuremap = featuremap.detach()
        featuremap = featuremap.numpy()[0]
    elif featuremap.type() == 'torch.ByteTensor':
        featuremap = featuremap.detach()
        featuremap = featuremap.numpy()[0, 0]
    wwtool.show_grayscale_as_heatmap(featuremap, win_name=win_name, wait_time=10)
Esempio n. 2
0
def show_featuremap(featuremap, win_name='feature_map'):
    if featuremap.type() == 'torch.FloatTensor':
        print("original feature map shape: ", featuremap.shape)
        featuremap = torch.mean(featuremap, dim=1)
        print("mean feature map shape: ", featuremap.shape)
        featuremap = featuremap.detach()
        featuremap = featuremap.numpy()[0]
        print("numpy feature map shape: ", featuremap.shape)
        print("max num: {}, min num: {}".format(featuremap.max(),
                                                featuremap.min()))
        min_num = np.percentile(featuremap, 5)
        max_num = np.percentile(featuremap, 90)
        print("percentile max: {}, percentile min: {}".format(
            max_num, min_num))
        featuremap = rescale(featuremap, min_num, max_num)
    elif featuremap.type() == 'torch.ByteTensor':
        featuremap = featuremap.detach()
        featuremap = featuremap.numpy()[0, 0]

    heatmap = wwtool.show_grayscale_as_heatmap(featuremap,
                                               win_name=win_name,
                                               wait_time=500,
                                               return_img=True)

    cv2.imwrite(
        '/home/jwwangchn/Documents/Nutstore/100-Work/110-Projects/2019-DOTA/05-CVPR/supplementary/heatmap/save.png',
        heatmap)
Esempio n. 3
0
def show_polygons_on_image(masks, 
                           img, 
                           alpha=0.4, 
                           output_file=None):
    """show masks on image

    Args:
        masks (list): list of coordinate
        img (np.array): original image
        alpha (int): compress
        output_file (str): save path
    """
    color_list = list(wwtool.COLORS.keys())
    img_h, img_w, _ = img.shape

    foreground = wwtool.generate_image(img_h, img_w, (0, 0, 0))
    for idx, mask in enumerate(masks):
        mask = np.array(mask).reshape(1, -1, 2)
        cv2.fillPoly(foreground, mask, (wwtool.COLORS[color_list[idx % 20]][2], wwtool.COLORS[color_list[idx % 20]][1], wwtool.COLORS[color_list[idx % 20]][0]))

    heatmap = wwtool.show_grayscale_as_heatmap(foreground / 255.0, show=False, return_img=True)
    beta = (1.0 - alpha)
    fusion = cv2.addWeighted(heatmap, alpha, img, beta, 0.0)

    if output_file is not None:
        cv2.imwrite(output_file, fusion)
    else:
        wwtool.show_image(fusion, save_name=None)

    return fusion
Esempio n. 4
0
rgb_img = cv2.imread(image_file)
mask_parser = wwtool.MaskParse()

objects = mask_parser(mask_file, category=(1, 3))

gt_masks = []
for obj in objects:
    mask = obj['segmentation']
    gt_masks.append([mask])

img = wwtool.generate_image(2048, 2048, (0, 0, 0))

COLORS = {'Blue': (0, 130, 200), 'Red': (230, 25, 75), 'Yellow': (255, 225, 25), 'Green': (60, 180, 75), 'Orange': (245, 130, 48), 'Purple': (145, 30, 180), 'Cyan': (70, 240, 240), 'Magenta': (240, 50, 230), 'Lavender': (230, 190, 255), 'Lime': (210, 245, 60), 'Teal': (0, 128, 128), 'Pink': (250, 190, 190), 'Brown': (170, 110, 40), 'Beige': (255, 250, 200), 'Maroon': (128, 0, 0), 'Mint': (170, 255, 195), 'Olive': (128, 128, 0), 'Apricot': (255, 215, 180), 'Navy': (0, 0, 128), 'Grey': (128, 128, 128), 'White': (255, 255, 255), 'Black': (0, 0, 0)}

color_list = list(COLORS.keys())

masks = wwtool.generate_image(2048, 2048)
for idx, gt_mask in enumerate(gt_masks):
    mask = poly2mask(gt_mask, 2048, 2048) * 1
    masks[:, :, 0] = mask * COLORS[color_list[idx % 20]][2]
    masks[:, :, 1] = mask * COLORS[color_list[idx % 20]][1]
    masks[:, :, 2] = mask * COLORS[color_list[idx % 20]][0]
    img += masks

heatmap = wwtool.show_grayscale_as_heatmap(img / 255.0, show=False, return_img=True)
alpha = 0.4
beta = (1.0 - alpha)
fusion = cv2.addWeighted(heatmap, alpha, rgb_img, beta, 0.0)

draw_grid(fusion, pxstep=1024)
wwtool.show_image(fusion, save_name='{}.png'.format(image_file_name))