Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualization #13

Closed
endeavorman opened this issue Apr 5, 2022 · 6 comments
Closed

Visualization #13

endeavorman opened this issue Apr 5, 2022 · 6 comments

Comments

@endeavorman
Copy link

Hi
Congratulations on your Oral Presentation being accepted.
Do you have the codes to visualize the corresponding segmentation results?I want to see the segmentation effect of the training model。Do I have access to the codes?

@chunbolang
Copy link
Owner

Hi,
thanks for your interest!

You can refer to the code below for visual analysis.

def plot_seg_result(img, mask, type=None, size=500, alpha=0.5, anns='mask'):
    assert type in ['red', 'blue', 'yellow']
    if type == 'red':
        color = (255, 50, 50)     # red  (255, 50, 50) (255, 90, 90) (252, 60, 60)
    elif type == 'blue':
        color = (90, 90, 218)   # blue (102, 140, 255) (90, 90, 218) (90, 154, 218)
    elif type == 'yellow':
        color = (255, 218, 90)  # yellow
    color_scribble = (255, 218, 90) # (255, 218, 90) (0, 0, 255)

    img_pre = img.copy()

    if anns == 'mask':
        for c in range(3):
            img_pre[:, :, c] = np.where(mask[:,:,0] == 1,
                                        img[:, :, c] * (1 - alpha) + alpha * color[c],
                                        img[:, :, c])            
    elif anns == 'scribble':
        mask[mask==255]=0
        mask = mask[:,:,0]
        dilated_size = 5
        Scribble_Expert = ScribblesRobot()
        scribble_mask = Scribble_Expert.generate_scribbles(mask)
        scribble_mask = ndimage.maximum_filter(scribble_mask, size=dilated_size) # 
        for c in range(3):
            img_pre[:, :, c] = np.where(scribble_mask == 1,
                                        color_scribble[c],
                                        img[:, :, c])                    
    elif anns == 'bbox':
        mask[mask==255]=0
        mask = mask[:,:,0]        
        bboxs = find_bbox(mask)
        for j in bboxs: 
            cv2.rectangle(img_pre, (j[0], j[1]), (j[0] + j[2], j[1] + j[3]), (255, 0, 0), 4) # -1->fill; 2->draw_rec

    img_pre = cv2.cvtColor(img_pre, cv2.COLOR_RGB2BGR)  
    
    if size is not None:
        img_pre = cv2.resize(img_pre, dsize=(size, size), interpolation=cv2.INTER_LINEAR)

    return img_pre

@endeavorman
Copy link
Author

Thanks for your reply, sincerely!

@chunbolang
Copy link
Owner

You are welcome. Feel free to contact~

@endeavorman
Copy link
Author

Trouble you again very sorry.
How to use model to generate image segmentation results? For example, use the model to generate PNG files for segmentation results. Is there code for that? You only tested the relevant IOU.

@chunbolang
Copy link
Owner

Hi,
You can generate a demo file based on test.py. Specifically, changing the mode of dataloader to 'demo' and adding the following code here to get the visual result:

que_img = ori_img_list[-1][0].numpy()
que_mask = ori_label.cpu().numpy().transpose((1, 2, 0))
pre_mask_final = output[:, :ori_label.size(1), :ori_label.size(2)].cpu().numpy().transpose((1, 2, 0))
que_gt = plot_seg_result(que_img, que_mask, type='blue')
que_pre_f = plot_seg_result(que_img, pre_mask_final, type='red')
cv2.imwrite(viz_path + 'que_gt.png', que_gt)                 # please specify the path
cv2.imwrite(viz_path + 'que_pre_f.png', que_pre_f)           # same here

Note that ori_img_list corresponds to this list, and plot_seg_result denotes the function given above.

@endeavorman
Copy link
Author

Thank you for your detailed answer. I've got the segmentation results of the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants