frankkramer-lab / MIScnn

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

Resolving grayscale image handling & conversions #91

Closed jumutc closed 2 years ago

jumutc commented 3 years ago

For some datasets like Fluo-N2DL-HeLa after loading by Image_interface we get blank images because of img_raw.convert("LA") conversion. This breaks down training and execution of subfunctions.

muellerdo commented 3 years ago

Hey @jumutc,

thank you for finding this bug and providing a solution! :) Sorry for the inconvenience, that Continuous Integration is currently disabled due to travis-ci.org has moved to travis-ci.com, which requires permissions and setup again (already on my to-do list before my vacation).

When running pytest locally, I got the following exception for this pull request:

============================= test session starts ==============================
platform linux -- Python 3.6.9, pytest-5.4.3, py-1.8.1, pluggy-0.13.1 -- /usr/bin/python
cachedir: .pytest_cache
rootdir: /home/mudomini/projects/MIScnn
plugins: cov-2.10.0, typeguard-2.12.1
collected 136 items                                                            

tests/test_architectures.py::architectureTEST::test_ARCHITECTURES_UNET_compact PASSED [  0%]
tests/test_architectures.py::architectureTEST::test_ARCHITECTURES_UNET_dense PASSED [  1%]
tests/test_architectures.py::architectureTEST::test_ARCHITECTURES_UNET_multires PASSED [  2%]
tests/test_architectures.py::architectureTEST::test_ARCHITECTURES_UNET_plain PASSED [  2%]
tests/test_architectures.py::architectureTEST::test_ARCHITECTURES_UNET_residual PASSED [  3%]
tests/test_architectures.py::architectureTEST::test_ARCHITECTURES_UNET_standard PASSED [  4%]
tests/test_cli.py::cliTEST::test_CLI_setup PASSED                        [  5%]
tests/test_cli.py::cliTEST::test_CLIbinningAnalysis PASSED               [  5%]
tests/test_cli.py::cliTEST::test_CLIbinningSegAnalysis PASSED            [  6%]
tests/test_cli.py::cliTEST::test_CLIclassAnalysis PASSED                 [  7%]
tests/test_cli.py::cliTEST::test_CLIminaxSegAnalysis PASSED              [  8%]
tests/test_cli.py::cliTEST::test_CLIminmaxAnalysis PASSED                [  8%]
tests/test_cli.py::cliTEST::test_CLIratioAnalysis PASSED                 [  9%]
tests/test_cli.py::cliTEST::test_CLIstructureAnalysis PASSED             [ 10%]
tests/test_cli.py::cliTEST::test_checkRegistration PASSED                [ 11%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_BASE_create PASSED [ 11%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_BASE_cycles PASSED [ 12%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_BASE_infauf PASSED [ 13%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_BASE_run2D PASSED [ 13%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_BASE_run3D PASSED [ 14%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_brightness PASSED [ 15%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_classification PASSED [ 16%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_contrast PASSED [ 16%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_cropping PASSED [ 17%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_edeform PASSED [ 18%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_gamma PASSED [ 19%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_gaussiannoise PASSED [ 19%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_mirror PASSED [ 20%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_percentage PASSED [ 21%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_rotation PASSED [ 22%]
tests/test_dataaugmentation.py::DataAugmentationTEST::test_DATAAUGMENTATION_parameter_scaling PASSED [ 22%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_augcyling PASSED [ 23%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_consistency PASSED [ 24%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_create PASSED [ 25%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_inferenceAug PASSED [ 25%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_iterations PASSED [ 26%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_prepareData PASSED [ 27%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_runPrediction PASSED [ 27%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_runTraining PASSED [ 28%]
tests/test_datagenerator.py::DataGeneratorTEST::test_DATAGENERATOR_shuffle PASSED [ 29%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BASE_create PASSED        [ 30%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BASE_getIndexList PASSED  [ 30%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BASE_getSampleList PASSED [ 31%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BASE_savePrediction PASSED [ 32%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BATCHES_backup PASSED     [ 33%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BATCHES_cleanup PASSED    [ 33%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BATCHES_loading PASSED    [ 34%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BATCHES_sampleLoading PASSED [ 35%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_BATCHES_sampleStorage PASSED [ 36%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_SampleLoader_Combined PASSED [ 36%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_SampleLoader_Imaging PASSED [ 37%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_SampleLoader_Prediction PASSED [ 38%]
tests/test_dataio.py::Data_IOTEST::test_DATAIO_SampleLoader_Segmentation PASSED [ 38%]
tests/test_ensemblelearning.py::EnsembleLearningTest::test_INFERENCEAUG_preprocessing_2D PASSED [ 39%]
tests/test_ensemblelearning.py::EnsembleLearningTest::test_INFERENCEAUG_preprocessing_3D PASSED [ 40%]
tests/test_evaluations.py::evaluationTEST::test_EVALUATION_crossValidation PASSED [ 41%]
tests/test_evaluations.py::evaluationTEST::test_EVALUATION_crossValidation_splitRun PASSED [ 41%]
tests/test_evaluations.py::evaluationTEST::test_EVALUATION_leaveOneOut PASSED [ 42%]
tests/test_evaluations.py::evaluationTEST::test_EVALUATION_splitValidation PASSED [ 43%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_DICTIONARY_creation PASSED [ 44%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_DICTIONARY_initialize PASSED [ 44%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_DICTIONARY_loading PASSED [ 45%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_DICTIONARY_predictionhandling PASSED [ 46%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_IMAGE_creation PASSED [ 47%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_IMAGE_initialize PASSED [ 47%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_IMAGE_loading FAILED [ 48%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_IMAGE_predictionhandling PASSED [ 49%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_NIFTI_creation PASSED [ 50%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_NIFTI_initialize PASSED [ 50%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_NIFTI_loading PASSED [ 51%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_NIFTI_predictionhandling PASSED [ 52%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_NIFTIslicer_creation PASSED [ 52%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_NIFTIslicer_initialize PASSED [ 53%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_NIFTIslicer_loading PASSED [ 54%]
tests/test_iointerfaces.py::IO_interfacesTEST::test_IOI_NIFTIslicer_predictionhandling PASSED [ 55%]
tests/test_metrics.py::metricTEST::test_METRICS_DSC_CrossEntropy PASSED  [ 55%]
tests/test_metrics.py::metricTEST::test_METRICS_DSC_soft PASSED          [ 56%]
tests/test_metrics.py::metricTEST::test_METRICS_DSC_softLOSS PASSED      [ 57%]
tests/test_metrics.py::metricTEST::test_METRICS_DSC_standard PASSED      [ 58%]
tests/test_metrics.py::metricTEST::test_METRICS_DSC_standardLOSS PASSED  [ 58%]
tests/test_metrics.py::metricTEST::test_METRICS_DSC_weighted PASSED      [ 59%]
tests/test_metrics.py::metricTEST::test_METRICS_FocalCategorical PASSED  [ 60%]
tests/test_metrics.py::metricTEST::test_METRICS_Tversky PASSED           [ 61%]
tests/test_metrics.py::metricTEST::test_METRICS_Tversky_CrossEntropy PASSED [ 61%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_create PASSED [ 62%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_loading PASSED [ 63%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_multiGPU PASSED [ 63%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_prediction2D PASSED [ 64%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_prediction3D PASSED [ 65%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_predictionAugmentated_2D PASSED [ 66%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_predictionAugmentated_3D PASSED [ 66%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_prediction_activationOutput PASSED [ 67%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_prediction_returnOutput PASSED [ 68%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_resetWeights PASSED [ 69%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_storage PASSED [ 69%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_training2D PASSED [ 70%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_training3D PASSED [ 71%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_validation2D PASSED [ 72%]
tests/test_neuralnetwork.py::NeuralNetworkTEST::test_MODEL_validation3D PASSED [ 72%]
tests/test_patchoperations.py::PatchOperationsTEST::test_PATCHOPERATIONS_concatenate PASSED [ 73%]
tests/test_patchoperations.py::PatchOperationsTEST::test_PATCHOPERATIONS_cropping PASSED [ 74%]
tests/test_patchoperations.py::PatchOperationsTEST::test_PATCHOPERATIONS_padding PASSED [ 75%]
tests/test_patchoperations.py::PatchOperationsTEST::test_PATCHOPERATIONS_slicing PASSED [ 75%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_BASE_batchsizes PASSED [ 76%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_BASE_create PASSED [ 77%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_BASE_dataaugmentation PASSED [ 77%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_BASE_prepareBatches PASSED [ 78%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_BASE_prepareSubfunctions PASSED [ 79%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_BASE_run PASSED [ 80%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_fullimage_2D PASSED [ 80%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_fullimage_3D PASSED [ 81%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_patchwisecrop_2D PASSED [ 82%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_patchwisecrop_3D PASSED [ 83%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_patchwisecrop_skipBlanks PASSED [ 83%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_patchwisegrid_2D PASSED [ 84%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_patchwisegrid_3D PASSED [ 85%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_patchwisegrid_skipBlanks PASSED [ 86%]
tests/test_preprocessor.py::PreprocessorTEST::test_PREPROCESSOR_postprocessing_ PASSED [ 86%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_CLIPPING_postprocessing PASSED [ 87%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_CLIPPING_preprocessing PASSED [ 88%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_NORMALIZATION_postprocessing PASSED [ 88%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_NORMALIZATION_preprocessing PASSED [ 89%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_PADDING_postprocessing PASSED [ 90%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_PADDING_preprocessing PASSED [ 91%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_RESAMPLING_postprocessing PASSED [ 91%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_RESAMPLING_postprocessing_activationOutput PASSED [ 92%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_RESAMPLING_preprocessing PASSED [ 93%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_RESIZE_postprocessing PASSED [ 94%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_RESIZE_preprocessing PASSED [ 94%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_TransformHU_postprocessing PASSED [ 95%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_TransformHU_preprocessing PASSED [ 96%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_fullrun PASSED [ 97%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_postprocessing PASSED [ 97%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_prepare PASSED [ 98%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_prepare_MULTIPROCESSING PASSED [ 99%]
tests/test_subfunctions.py::SubfunctionsTEST::test_SUBFUNCTIONS_preprocessing PASSED [100%]

=================================== FAILURES ===================================
___________________ IO_interfacesTEST.test_IOI_IMAGE_loading ___________________

self = <tests.test_iointerfaces.IO_interfacesTEST testMethod=test_IOI_IMAGE_loading>

    def test_IOI_IMAGE_loading(self):
        interface = Image_interface(pattern="image_\\d+")
        sample_list = interface.initialize(self.tmp_data.name)
        img_01 = interface.load_image(sample_list[0])
        seg_01 = interface.load_segmentation(sample_list[0])
        true_img_01 = np.array(Image.fromarray(self.img[:, :, :3]).convert('LA'))
>       self.assertTrue(np.array_equal(img_01[0], true_img_01[:,:,0]))
E       AssertionError: False is not true

tests/test_iointerfaces.py:97: AssertionError
jumutc commented 3 years ago

Hi @muellerdo,

This exception is strange as I was running all tests locally and all was green! I will investigate. My Python version is higher so maybe there are some diffs coming from this fact.

jumutc commented 3 years ago

@muellerdo tests are fixed!