Issam28 / Brain-tumor-segmentation

A deep learning based approach for brain tumor MRI segmentation.
191 stars 63 forks source link

Question #9

Closed Johncheng1 closed 5 years ago

Johncheng1 commented 5 years ago

How to show segmentation result(different colours) on Original image like in your Readme?I tried findcontours, but it not work,thank you!

Issam28 commented 5 years ago

you can use the following function :

import numpy as np
from skimage import color, img_as_float
from skimage.exposure import adjust_gamma

def show_segmented_image(orig_img, pred_img):
    '''
    Show the prediction over the original image
    INPUT:
        1)orig_img: the test image, which was used as input
        2)pred_img: the prediction output
    OUTPUT:
        segmented image rendering
    '''
    orig_img/=np.max(orig_img)
    #img_mask = np.pad(pred_img, (16,16), mode='edge')
    ones = np.argwhere(pred_img == 1)
    twos = np.argwhere(pred_img == 2)
    threes = np.argwhere(pred_img == 3)
    fours = np.argwhere(pred_img == 4)
    gray_img = img_as_float(orig_img)

    image = adjust_gamma(color.gray2rgb(gray_img), 1)
    sliced_image = image.copy()
    red_multiplier = [1, 0.2, 0.2]
    yellow_multiplier = [1,1,0.25]
    green_multiplier = [0.35,0.75,0.25]
    blue_multiplier = [0,0.25,0.9]

        # change colors of segmented classes
    for i in range(len(ones)):
        sliced_image[ones[i][0]][ones[i][1]] = red_multiplier
    for i in range(len(twos)):
        sliced_image[twos[i][0]][twos[i][1]] = green_multiplier
    for i in range(len(threes)):
        sliced_image[threes[i][0]][threes[i][1]] = blue_multiplier
    for i in range(len(fours)):
        sliced_image[fours[i][0]][fours[i][1]] = yellow_multiplier

    return sliced_image
shaktichetan commented 5 years ago

What should i pass for predicted images

JiangZongKang commented 5 years ago

How to show segmentation result(different colours) on Original image like in your Readme?I tried findcontours, but it not work,thank you!

hello,I use Issam28‘ above code, but can not show segmentation result(different colours) on Original image, please you work it? thank you.

akashshingha850 commented 4 years ago

@Issam28 if you kindly demonstrate how to generate those image from the trained model, that would be really helpful. Most of the people are facing such problem. In your read.me file, you only explain how to run the codes but for some reason, most of the people fail to understand how to generate such a colorful image. @Johncheng1 if you understand properly, please demonstrate it. Thank you.