jpeg200 conversion changes/loses data
Posted: 2016-05-01T06:11:57-07:00
Dear folks, I found that IM converter TO jp2 format seems to change (in some sense lose) data. However, I could not find a related discussion, so posting my findings.
First, I'm using linux gentoo x64 and
ImageMagick 6.9.0-3 Q16 x86_64 2016-04-28
Second, I need INDEED a lossless transformation. And, accounting the compression success of jp2 I would prefer jp2 given I have already about 3TB of tiff-s. Again, lossless means strictly mathematically lossless. No single bit should change.
After trial and tries, the test I did is as follow:
0. I took a Bliss.bmp file, standard windows xp wallpaper.
So, kind of a random source. Then:
1. I converted it to png using IM (im.png)
2. I converted it to jp2 using IM saying "-quality 100" (I tried also "-compress lossless" to no avail, the method is compiled in but the result is the same as "-quality 100", i.e. jp2-files are identical) (im.jp2)
3. I converted im.png to impng.bmp
4. I converted im.jp2 to imjp2.bmp
5. I compare impng.bmp and imjp2.bmp using "cmp -l" and see that actual bitmaps are different. 214 bytes differ.
So, at this stage it is obvious that that some conversions change data.
To find out which I did as follows:
6. I converted Bliss.bmp to png using photoshop (ps.png)
7. I converted Bliss.bmp to jp2 usnig photoshop (ps.jp2)
8. I converted ps.png to pspng.bmp using photoshop
9. I converted ps.jp2 to psjp2.bmp using photoshop
10. I compared bitmaps of pspng.bmp and psjp2.bmp and they are identical
So, photoshop at least pretends to be lossless.
Thus, I did cross-checks.
11. I converted photoshop produced png and jp2 to bmp-s using IM. The names are pspngim.bmp and psjp2im.bmp.
12. I checked that all 4 bitmaps (pspngim.bmp and psjp2im.bmp and pspng.bmp and psjp2.bmp) Of course I carefully accounted that headers from photoshop and IM are different and used the offset from the header. Then I specified an appropriate SKIP1 SKIP2 to "cmp -l" command.
So, it seems that conversion FROM jp2 are consistent in IM.
Further I did like that:
13. I converted IM produced png and jp2 to bmp-s using photoshop. The names are impngps.bmp and imjp2ps.bmp
14. Checking bitmaps I got that:
bitmaps of impng.bmp and impngps.bmp coincide
bitmaps of imjp2.bmp and imjp2ps.bmp coincide
bitmaps of impng.bmp and imjp2.bmp (or equivalently impngps.bmp and imjp2ps.bmp) differ in 214 bytes.
Finally the grand crosscheck was done, the comparison shows that:
15. bitmaps of impng.bmp and pspng.bmp coincide
From here the conclusion is that data change as long as a conversion by IM in the direction TO jp2 is involved. Since it is exactly what I need I'm seeking for help/advice.
I accept that conversion results are indistinguishable by a human eye. But, for my needs I need just strictly invertible transforms. I can go with photoshop but I'm in favour of opensource and batch command line processing (preferably in linux).
All referred files are here: http://altaray.net/inout/upload/ll.tar.bz2
I guess my programming experience is enough to find out the glitch but the source is large. I'd be happy to be pointed more or less precisely to where I should look at. Math aspects are not a problem as I'm a theoretical physicist, ii.e. math is the simplest part for me.
Thanks, Alex
First, I'm using linux gentoo x64 and
ImageMagick 6.9.0-3 Q16 x86_64 2016-04-28
Second, I need INDEED a lossless transformation. And, accounting the compression success of jp2 I would prefer jp2 given I have already about 3TB of tiff-s. Again, lossless means strictly mathematically lossless. No single bit should change.
After trial and tries, the test I did is as follow:
0. I took a Bliss.bmp file, standard windows xp wallpaper.
So, kind of a random source. Then:
1. I converted it to png using IM (im.png)
2. I converted it to jp2 using IM saying "-quality 100" (I tried also "-compress lossless" to no avail, the method is compiled in but the result is the same as "-quality 100", i.e. jp2-files are identical) (im.jp2)
3. I converted im.png to impng.bmp
4. I converted im.jp2 to imjp2.bmp
5. I compare impng.bmp and imjp2.bmp using "cmp -l" and see that actual bitmaps are different. 214 bytes differ.
So, at this stage it is obvious that that some conversions change data.
To find out which I did as follows:
6. I converted Bliss.bmp to png using photoshop (ps.png)
7. I converted Bliss.bmp to jp2 usnig photoshop (ps.jp2)
8. I converted ps.png to pspng.bmp using photoshop
9. I converted ps.jp2 to psjp2.bmp using photoshop
10. I compared bitmaps of pspng.bmp and psjp2.bmp and they are identical
So, photoshop at least pretends to be lossless.
Thus, I did cross-checks.
11. I converted photoshop produced png and jp2 to bmp-s using IM. The names are pspngim.bmp and psjp2im.bmp.
12. I checked that all 4 bitmaps (pspngim.bmp and psjp2im.bmp and pspng.bmp and psjp2.bmp) Of course I carefully accounted that headers from photoshop and IM are different and used the offset from the header. Then I specified an appropriate SKIP1 SKIP2 to "cmp -l" command.
So, it seems that conversion FROM jp2 are consistent in IM.
Further I did like that:
13. I converted IM produced png and jp2 to bmp-s using photoshop. The names are impngps.bmp and imjp2ps.bmp
14. Checking bitmaps I got that:
bitmaps of impng.bmp and impngps.bmp coincide
bitmaps of imjp2.bmp and imjp2ps.bmp coincide
bitmaps of impng.bmp and imjp2.bmp (or equivalently impngps.bmp and imjp2ps.bmp) differ in 214 bytes.
Finally the grand crosscheck was done, the comparison shows that:
15. bitmaps of impng.bmp and pspng.bmp coincide
From here the conclusion is that data change as long as a conversion by IM in the direction TO jp2 is involved. Since it is exactly what I need I'm seeking for help/advice.
I accept that conversion results are indistinguishable by a human eye. But, for my needs I need just strictly invertible transforms. I can go with photoshop but I'm in favour of opensource and batch command line processing (preferably in linux).
All referred files are here: http://altaray.net/inout/upload/ll.tar.bz2
I guess my programming experience is enough to find out the glitch but the source is large. I'd be happy to be pointed more or less precisely to where I should look at. Math aspects are not a problem as I'm a theoretical physicist, ii.e. math is the simplest part for me.
Thanks, Alex