frankkramer-lab / MIScnn

A framework for Medical Image Segmentation with Convolutional Neural Networks and Deep Learning
GNU General Public License v3.0
402 stars 116 forks source link

The orientation of segmentation prediction into with the NIFTI file format #69

Open deeplearining-sheen opened 3 years ago

deeplearining-sheen commented 3 years ago

Hi,

Regardless of its dice_soft, the orientation of all predicted segmentations with NIFTI file format was different from the ground truth. I tried to fix dicom_io.py, but I could not do.

I need to the correct orientation for fusion with their own CT data.

I really appreciate if you let me know how to fix it.

GroundT_Prediction

deeplearining-sheen commented 3 years ago

Hi,

Its reason is x, y, z array order as following: Ground Truth: Image Dimensions (X, Y, Z): 512 x 512 x 134 Prediction: Image Dimensions (X, Y, Z): 134 x 512 x 512

When I checked its .gif, there is no problem. However, the NIFIT file format was wrong.

Please let me know how to correct it.

muellerdo commented 3 years ago

Hello @deeplearining-sheen,

mhm. MIScnn shouldn't play with the orientation at all and theoretically just loads the data 'as-is' from the provided imaging file.

Can you elaborate a bit on what you have tried or how you obtained these mirrored orientations? Have you used NIfTI or DICOM data? How do you obtain these image shapes? What do you mean with fix dicom_io.py?

I assume that you have DICOM files from your clinic, transform these in NIfTI format, pipe them into MIScnn and the predicted segmentation orientations are not identical to the original DICOM image?

The easiest way to verify things is that you load a ground truth NIfTI file and a predicted segmentation NIfTI file via the nibabel Python package. Then print out their shapes.

I mean, if I would take a guess than I would say that the orientation mirror is a by product during format conversion and don't occur during MIScnn (of course, I may be wrong -> it's a bug and I would be glad if we find + fix it!), but for fast fixing this issue you can just load the predicted segmentation file via nibabel, flip the segmenation matrix via NumPy and store it again to disk via nibabel.

Links: https://nipy.org/nibabel/gettingstarted.html https://numpy.org/doc/stable/reference/generated/numpy.flip.html

Cheers, Dominik

deeplearining-sheen commented 3 years ago

Hi Dominik,

I really appreciate your information.

I would like to explain this issue more.

I got 'NSCLC-Radiomics' data sets from TCIA. They are consisted with CT images and RTSS with DICOM format. I used them without any converting to NIfTI format for ' LCTSC_DICOMInterface.ipynb'.

After finishing their deep learning using ' LCTSC_DICOMInterface.ipynb', two folders (evaluation folder and prediction folder) were made.

Their predicted segmentation with NIfTI format were saved in prediction folder, and their animated gifs were saved in evaluation folder.

The orientation of the predicted segmentation with NIfTI format was different from that of original data, while that of their animated gifs was no problem. Its reason is x, y, z array order as I have mentioned previously.

Therefore, I thought that it was happened when the predicted segmentation were saved with NIfTI, and it could be fixed if some part were modified.

Currently only way is that I used data with NIfTI format in order to get the correction orientation......???

I will check it with NIfTI format as following your suggestions.

visualization case_LUNG1-265

visualization case_LUNG1-265

muellerdo commented 3 years ago

Hey @deeplearining-sheen,

sorry for the late reply.

Mhm, interesting behavior. Maybe, this could result from the NIfTI conversion via nibabel or from different loading protocols from your image viewer/PACS.

Currently only way is that I used data with NIfTI format in order to get the correction orientation......???

The fastest and most easiest way is probably to load the predicted segmentation file via nibabel, flip the segmenation matrix via NumPy and store it again to disk via nibabel.

An experiment would be to convert the NIfTI prediction files to DICOM and see if the orientations are the same or still different.

Cheers, Dominik