MATLAB: Can I not open a JPEG image written using lossless compression outside of MATLAB

MATLAB

I am writing to an image file using the IMWRITE function. I have specified the mode to be 'lossless'. The image file is not viewable outside of MATLAB. I have tried a number of different viewers. I can read the image back into MATLAB and display it. If I specify the mode to be 'lossy', the image is viewable outside MATLAB.
I am using the following code to create the image:
x = rand(100,100);
imwrite(x,'test.jpg','mode','lossless');

Best Answer

The lossless JPEG format is not a popular format and is not supported by most common applications including Microsoft applications. The more popular JPEG format is lossy.
Lossless JPEG should not be confused with JPEG-LS a new standard which uses lossless compression. MATLAB does not support JPEG-LS.
PNG is a common lossless compression format. The following code writes an image to PNG format:
x = rand(100,100);
imwrite(x,'test.png');