[Python] How to handle image with extension .nii.gz? Is it possible to convert them in...

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have always work with images with extensions .png, .jpg, .jpeg Now, I have seen medical images with extension .nii.gz

    I'm using python and I have read it with the following code:

    path = "./Task01_BrainTumour/imagesTr"
    path_list = glob.glob(path+'/*.gz') #list with all paths of image.nii.gz

    img = nib.load(path_list[0]).get_data() #load a single image


    Now the image is an array of float32 and it has the following shape (240, 240, 155, 4). I have read online that (240, 240, 155, 4) indicates that the image has size (240,240), 155 indicates the depth of the image object, namely there are 155 layers in every image object. However, this information related to the layer/depth is not clear to me, what does it mean that an image has some layers? Finally, 4 indicates the channel of the image.

    I would like to convert these images in the classical format (240,240,3) for rgb or (240,240) in grayscale. I don't know if it is possible to do that.

    Continue reading...

Compartilhe esta Página