frankkramer-lab / aucmedi

a framework for Automated Classification of Medical Images
https://frankkramer-lab.github.io/aucmedi/
GNU General Public License v3.0
38 stars 12 forks source link

PIL.UnidentifiedImageError: cannot identify image file #187

Closed Pfleiderer-Adrian closed 1 year ago

Pfleiderer-Adrian commented 1 year ago

Hi aucmedi-Team,

I wanted to load Nifti (.nii) or .mha images with aucmedi. Both formats are specified as supported in the documentation: https://frankkramer-lab.github.io/aucmedi/reference/data_processing/io_data/#aucmedi.data_processing.io_data.ACCEPTABLE_IMAGE_FORMATS

Unfortunately i always get this error:

File "/usr/local/lib/python3.8/dist-packages/aucmedi/data_processing/io_loader/image_loader.py", line 76, in image_loader img_raw = Image.open(path_img) File "/usr/local/lib/python3.8/dist-packages/PIL/Image.py", line 3186, in open raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file

Aucmedi currently uses the PIL framework to load images. Neither .nii or .mha files are supported in version 9.3.0. I can contribute a modified image_loader.py for aucmedi which support .nii and .mha files with the itk framework if this is not an error on my part.

Greetings, Adrian

`python -m PIL` returns on my system:
> --------------------------------------------------------------------
> Pillow 9.3.0
> Python 3.8.10 (default, Mar 15 2022, 12:22:08)
>        [GCC 9.4.0]
> --------------------------------------------------------------------
> Python modules loaded from /usr/local/lib/python3.8/dist-packages/PIL
> Binary modules loaded from /usr/local/lib/python3.8/dist-packages/PIL
> --------------------------------------------------------------------
> --- PIL CORE support ok, compiled for 9.3.0
> *** TKINTER support not installed
> --- FREETYPE2 support ok, loaded 2.12.1
> --- LITTLECMS2 support ok, loaded 2.13.1
> --- WEBP support ok, loaded 1.2.4
> --- WEBP Transparency support ok
> --- WEBPMUX support ok
> --- WEBP Animation support ok
> --- JPEG support ok, compiled for libjpeg-turbo 2.1.4
> --- OPENJPEG (JPEG2000) support ok, loaded 2.5.0
> --- ZLIB (PNG/ZIP) support ok, loaded 1.2.11
> --- LIBTIFF support ok, loaded 4.4.0
> --- RAQM (Bidirectional Text) support ok, loaded 0.9.0, fribidi 1.0.8, harfbuzz 5.3.1
> *** LIBIMAGEQUANT (Quantization method) support not installed
> --- XCB (X protocol) support ok
> --------------------------------------------------------------------
> BLP
> Extensions: .blp
> Features: open, save, encode
> --------------------------------------------------------------------
> BMP image/bmp
> Extensions: .bmp
> Features: open, save
> --------------------------------------------------------------------
> BUFR
> Extensions: .bufr
> Features: open, save
> --------------------------------------------------------------------
> CUR
> Extensions: .cur
> Features: open
> --------------------------------------------------------------------
> DCX
> Extensions: .dcx
> Features: open
> --------------------------------------------------------------------
> DDS
> Extensions: .dds
> Features: open, save
> --------------------------------------------------------------------
> DIB image/bmp
> Extensions: .dib
> Features: open, save
> --------------------------------------------------------------------
> EPS application/postscript
> Extensions: .eps, .ps
> Features: open, save
> --------------------------------------------------------------------
> FITS
> Extensions: .fit, .fits
> Features: open, save
> --------------------------------------------------------------------
> FLI
> Extensions: .flc, .fli
> Features: open
> --------------------------------------------------------------------
> FTEX
> Extensions: .ftc, .ftu
> Features: open
> --------------------------------------------------------------------
> GBR
> Extensions: .gbr
> Features: open
> --------------------------------------------------------------------
> GIF image/gif
> Extensions: .gif
> Features: open, save, save_all
> --------------------------------------------------------------------
> GRIB
> Extensions: .grib
> Features: open, save
> --------------------------------------------------------------------
> HDF5
> Extensions: .h5, .hdf
> Features: open, save
> --------------------------------------------------------------------
> ICNS image/icns
> Extensions: .icns
> Features: open, save
> --------------------------------------------------------------------
> ICO image/x-icon
> Extensions: .ico
> Features: open, save
> --------------------------------------------------------------------
> IM
> Extensions: .im
> Features: open, save
> --------------------------------------------------------------------
> IMT
> Features: open
> --------------------------------------------------------------------
> IPTC
> Extensions: .iim
> Features: open
> --------------------------------------------------------------------
> JPEG image/jpeg
> Extensions: .jfif, .jpe, .jpeg, .jpg
> Features: open, save
> --------------------------------------------------------------------
> JPEG2000 image/jp2
> Extensions: .j2c, .j2k, .jp2, .jpc, .jpf, .jpx
> Features: open, save
> --------------------------------------------------------------------
> MCIDAS
> Features: open
> --------------------------------------------------------------------
> MPEG video/mpeg
> Extensions: .mpeg, .mpg
> Features: open
> --------------------------------------------------------------------
> MSP
> Extensions: .msp
> Features: open, save, decode
> --------------------------------------------------------------------
> PCD
> Extensions: .pcd
> Features: open
> --------------------------------------------------------------------
> PCX image/x-pcx
> Extensions: .pcx
> Features: open, save
> --------------------------------------------------------------------
> PIXAR
> Extensions: .pxr
> Features: open
> --------------------------------------------------------------------
> PNG image/png
> Extensions: .apng, .png
> Features: open, save, save_all
> --------------------------------------------------------------------
> PPM image/x-portable-anymap
> Extensions: .pbm, .pgm, .pnm, .ppm
> Features: open, save
> --------------------------------------------------------------------
> PSD image/vnd.adobe.photoshop
> Extensions: .psd
> Features: open
> --------------------------------------------------------------------
> SGI image/sgi
> Extensions: .bw, .rgb, .rgba, .sgi
> Features: open, save
> --------------------------------------------------------------------
> SPIDER
> Features: open, save
> --------------------------------------------------------------------
> SUN
> Extensions: .ras
> Features: open
> --------------------------------------------------------------------
> TGA image/x-tga
> Extensions: .icb, .tga, .vda, .vst
> Features: open, save
> --------------------------------------------------------------------
> TIFF image/tiff
> Extensions: .tif, .tiff
> Features: open, save, save_all
> --------------------------------------------------------------------
> WEBP image/webp
> Extensions: .webp
> Features: open, save, save_all
> --------------------------------------------------------------------
> WMF
> Extensions: .emf, .wmf
> Features: open, save
> --------------------------------------------------------------------
> XBM image/xbm
> Extensions: .xbm
> Features: open, save
> --------------------------------------------------------------------
> XPM image/xpm
> Extensions: .xpm
> Features: open
> --------------------------------------------------------------------
> XVTHUMB
> Features: open
> --------------------------------------------------------------------
muellerdo commented 1 year ago

Heyho @Pfleiderer-Adrian,

you are right, the image loader interface, which utilizes Pillow for loading 2D images, does not support loading 3D images like .nii or .mha.

But check out the SimpleITK loader in AUCMEDI ;)

Cheers, Dominik

Pfleiderer-Adrian commented 1 year ago

Hi @muellerdo,

ohh nice.. I missed this completely ;D

thank you!

Greetings, Adrian