DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.74k stars 387 forks source link

Compression Ratio being lower for JBIG2 than JBIG1 ???!!! #672

Closed Sahil-5111998 closed 1 year ago

Sahil-5111998 commented 1 year ago

I am currently working on the compression of binary images. There is an algorithm that I am trying to test and compare its compression ratio to JBIG2 encoded images.

I am getting into a problem, and I am hoping that you might be able to help me here. I want to compute the compression ratio of specific images using my algorithm and computer them to standards JBIG1 and JBIG2. For JBIG1, I am using JBIG-kit (from Markus K) and jbig2enc for JBIG2 compression. However, the size of the encoded JBIG2 file is similar to that of the JBIG1 (.jbg) encoder. This should not happen as JBIG2 should give at least 2-3 times smaller results. I am giving a .pbm image as input for both encoders, and in some cases, the JBIG1 encoder is giving me a lower size.

For generating the jbig2 encoded file I am using the command: $ jbig2 -s a.pbm > a.jb2 The size of this file is coming more as compared to one generated by jbig1 encoder. As the encoder is using leptonica library, can you please let me know what wrong am I doing here?

DanBloomberg commented 1 year ago

I agree that doesn't seem right, but I haven't used the jbig1 kit -- in fact, I didn't even know that jbig1 was in use at all.

Please tell me:

Sahil-5111998 commented 1 year ago

I built the library using MacPorts Leptonica: https://ports.macports.org/port/leptonica/ MacPorts jbig2enc: https://ports.macports.org/port/jbig2enc/

I have build the files in my Users folder then I run the encoder using the command: $ jbig2 -s HandBoneStructure.tiff > a I am reading the file in MATLAB using the fopen command. fid = fopen(a);
[y,cnt] = fread(fid, Inf); y is giving the number of bytes from there I am comparing the size of both encoded files.

In the zip file, I have put both the 'tiff' image and the encoded file. Img.zip

DanBloomberg commented 1 year ago

I see that ubuntu has a 'snaps' facility that is similar to the Apple's 'macports' and the debian package manager. They all download a library along with any dependent libraries that are not found.

You have chosen to test on a particular image that has only 27 connected components when converted to 1 bpp, and all the components are significantly different. Therefore, jbig2 will compress it losslessly. But jbig2 is usually used for lossy compression, and that is where it shines.

jbig (aka jbig1) only does lossless compression. Because your special image is compressed losslessly by jbig2, I'd expect the results to be comparable in size. But in any event, the big advantage that jbig2 has when it can use lossy compression does not exist for your hand example.

I suggest you make the comparison for some scanned text.

Sahil-5111998 commented 1 year ago

ok thanks