Label image defects after saving

Guys, I am not sure if that is the correct place to ask that, BUT I have nowhere to run.

I used nrrd and slicerio extensions to separate .seg.nrrd files into separated segments or label images.
Great. It gives me array images. I, then, proceed SAVING those labels into local image files (.jpeg). Good.

The problem arises when I load such images back into say jupyter notebook for Deep Learning application.

I created a binary, 1 and 0, label image and saved in .jpeg, however when I load them back into python, some random pixels with value 2 appears. Yes! 2. How come?

I checked loading with both matplotlib (imread) and Pillow. By the way, I saved those images with Pillow in .jpeg format. I’ve tracked the whole code and everything sounds ok. The crashing happens after saving and loading it back.

I am working with deep learning semantic segmentation and it is crucial that the image have only 0 and 1`s.

Thanks in advance.

I’d guess those are compression artifacts from the jpg encoding. Maybe you can use .png instead?

1 Like

The current recommendation for Medical Imaging Deep Learning is to use Monai where you are using the medical imaging file directly such as a nrrd file. You are likely to run into issues using simple image formats like jpeg.

Tutorials for Monai are available at GitHub - Project-MONAI/tutorials: MONAI Tutorials.

2 Likes

That was it. Thanks a lot, @pieper!