Error when saving labelmap to jpg

I am working with JPG images:
When I try to save a labelmap to any of the JPG or PNG formats I get this error:
“Cannot write data file: /Users/xx/Documents/Segmentation-labe.jpg.
Do you want to continue saving?”

I am in MAC. Slicer 4.10.

Slicer 4.11 preview crashes


Volumes cannot be saved into JPEG without information loss (JPEG can only store a single slice, cannot store spacing between slices, etc.). You can easily export a labelmap to JPEG as shown in this example in script repository.

If you ask this because you want to use these images for deep learning: do not use JPEG for temporarily storing image slices. Many people find some deep learning examples on the web that use JPEG (e.g., because they are originally developed by computer vision people, working on camera images), and assume that it is the right thing to do for medical images, but this is just very wrong. JPEG can only store 8-bit images (while many medical images becomes barely usable if you reduce their dynamic range to 8 bits), may introduce compression artifacts, slower to compress/decompress than plain numpy array npy files, and your machine learning library needs numpy arrays as inputs anyway. So, instead of compromising data by writing to disk as JPEG, write it directly as numpy array. You can get voxels of a volume as numpy array by calling slicer.util.arrayFromVolume() from Slicer’s Python console.