Search code examples
numpypython-imaging-libraryimage-segmentationnpz-file

problem in visualized image derived from npz file


I am trying to open and visualize images of different ct slices in a npz formatted file to proceed my NN segmentation task later on. I used the following code:

data = np.load('case0005_slice060.npz')
image = data['image']
img = Image.fromarray(image,'RGB')

and finally, I could visualize the image, but it seems there is a problem somewhere that I can't understand. here is the output (the problem is that I may need to solve overlapped images but I don't know how)

enter image description here


Solution

  • Thanks. I normalized the image which was float32 and removed the RGB here is the final code:

    from numpy import load
    import matplotlib.pyplot as plt
    def normalize8(I):
        mn = I.min()
        mx = I.max()
    
        mx -= mn
    
        I = ((I - mn)/mx) * 255
        return I.astype(np.uint8)
    
    data = np.load('case0005_slice060.npz')
    print(data.files)
    image = data['image']
    image=normalize8( image)
    img = Image.fromarray(image)
    

    enter image description here