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)


First, check what you have. You need to know the shape and type of your Numpy array:
If the shape is of the form
h,w,3it's likely RGB. If of the formh,w, it's likely greyscale and you could put'L'as the mode when creating yourPIL Imagefrom it instead of'RGB', though you can normally leave the mode out and it is inferred from the Numpy array shape.You then need to consider the
dtype. Ifnp.uint8, you're all set. If other than that, you may need to provide one of the modes PIL accepts, or cast with something like: