I have been working on a problem where I need to save a matrix as an Image and for it to be a truly lossless example of the matrix in MATLAB.
I have tried writing the image as a png and tiff both in lossless form:
Name Size Bytes Class Attributes diff 237x354 671184 double imPng 237x354 167796 uint16 imPngD 237x354 671184 double imTiff 237x354 83898 uint8 imTiffD 237x354 671184 double padded 2042x2170 35449120 double testImage 237x354 671184 double
testImage is the matrix I would like to save losslessly.
I used the following lines to write the matrix as a tif and png:
EDU>> imwrite(testImage,'imTiff.tif','tiff','compression','none');
EDU>> imwrite(testImage,'imTiff.png','PNG','bitdepth',16);
I then loaded the images back to the work space (imTiff and inPng) and converted them to double.
EDU>> imPngD = im2double(imPng);
EDU>> imTiffD = im2double(imTiff);
but when I subtract either imPngD or imTiffD from testImage there are residual values left.
My questions are:
Is there something wrong in my processing?
If not, does this mean that tif and png are not truly completely lossless?
I can supply images if you think it would help.
I thought these images might help:
testImage
Difference between imTiffD and testImage
Difference between imPngD and testImage
Please note: the values of the grey pixels in images 2-3 are zero i.e. the difference between testImage and the reloaded images are zero.
PNG and TIFF are both truly lossless (ignoring the TIFF option to package JPEG, which you are not using). However they are truly lossless given their input, which is either 8 or 16 bits per pixel per color value for PNG, or 8 bits per pixel per color value for TIFF.
If you are looking beyond the precision that can be carried by 8 or 16 bit values, then you will see a difference.