Skip to content

Brats-20 dataset labels visualization on 3D images #5682

@mfaizan-ai

Description

@mfaizan-ai

Hi, I am working on the Brats-20 dataset. I want to create a gif animation of labels on images and prediction results on images. I am trying to do that. However, I am confused about the plots I get from the visualization.

I use the Keras function 'to_categorical' to convert labels to one hot representation from (240, 240, 155) shape as in the following code.

`def categorical(image, mask, is_categorical=False):
if not is_categorical:
label = to_categorical(mask, num_classes = 4).astype(np.uint8)

image = cv2.normalize(image[:, :, :, 0], None, alpha=0, beta=255,
                        norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F).astype(np.uint8)
                        
labeled_image = np.zeros_like(label[:, :, :, 1:])
labeled_image[:, :, :, 0] = image * (label[:, :, :, 0])
labeled_image[:, :, :, 1] = image * (label[:, :, :, 0])
labeled_image[:, :, :, 2] = image * (label[:, :, :, 0])

# color labels
labeled_image += label[:, :, :, 1:] * 255

return labeled_image`

Here the image has the shape of (240, 240, 155, 4) corresponding to a patient scan, and the mask has the shape of (240, 240, 155).
I want to create a nice visualization like that:

index

And a gif file to show labels or prediction results on an image. But the _seg.nii.gz (label file) contains the number 4 in the tensor. Which gives me an error in to_categorical. Because I am using num_classes =4 in the above function as you can see. Then I normalized the labels which converted labels for int to float values, and it was wrong.

Then I wrote something like limiting pixel labels from 1 to 3 to remove the error. Which successfully removed the error, however, I don't know if it is correct to label colors for the visualization. OR has it been mapped accurately or not? I need guidance, please.

I wrote the following code to map labels from 1 to 3 (I don't know if it's correct or not), but it removed the error in the to_categorical function. The code:

`def normalize(mask: np.ndarray):

# data_min = np.min(data)
# return (data - data_min) / (np.max(data) - data_m
mask[mask == 1] = 1
mask[mask == 2] = 2
# mask[mask == 3] = 0
mask[mask == 4] = 3
return mask`

Help will be appreciated as I am stuck here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions