DICOM images in Unet segmentation model

Hi everyone!

I have a U-net segmentation model that I used to deal with tiff images. Now I am working with DICOM. And the results of my model it has become really bad and weird. I did make some changes in my code to work with DICOM, but maybe he is not correct yet?

#pydicom to array, resize, normalize
        image = (image - np.min(image)) / (np.max(image) - np.min(image))
        image= np.array(image, dtype=np.float32)
        image = Image.fromarray(image)
        image = image.resize([int(image.width*0.1), int(image.height*0.1)], Image.LANCZOS) 
        image = np.array(image, dtype=np.float32)

Am I doing something wrong?


Your code looks generally OK, but I would verify what exactly:

image = Image.fromarray(image)

is doing.
Its input should be a normalized (in [0, 1]) np.array in float32, but assuming your DICOM has multiple slices I would expect Image.fromarray to fail.