0

I am using FreeImageNet.dll to compress j2k file(100KB) using various FREE_IMAGE_LOAD_FLAGS.

sample code is here.

      string fileName=abc.jpg;
      string outFileName=xyz.j2k;
      FREE_IMAGE_FORMAT imageFormat = FREE_IMAGE_FORMAT.FIF_J2K;

      dib = new FIBITMAP();
      dib = FreeImage.LoadEx(fileName, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
      FreeImage.SaveEx(dib, outFileName, imageFormat,FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB);
      dib.SetNull();

I got 7KB compressed file by this and differences are visible between original and compressed image.

How can i compress image up to 30 KB with no visible differences?

Thanks in advance.

stack
  • 59
  • 1
  • 6
  • Recompressing a compressed image format with another compression method is in general a bad idea. JPEG_QUALITYSUPERB only applies to the JPEG encoder, start with JP2_DEFAULT (which is probably what you got now), try an integer next, starting at 100. – Hans Passant Apr 01 '14 at 11:02
  • i am not finding these flag.. JP2_DEFAULT and J2K_DEFAULT,when i pass integer value as a flag it shows me an error.flag only accept 0 value. – stack Apr 01 '14 at 13:01
  • 0 == JP2_DEFAULT. Jpeg2000 is a rather ignored image file format. You don't want it. – Hans Passant Apr 01 '14 at 13:10
  • when i pass flag value 0, my image compresses up to 54KB without visible differences.is this the only option? can I manually define the compression value? – stack Apr 01 '14 at 13:40

1 Answers1

1

You define the compression as a ratio, JP2 will do up to 16:1.

It is a lossy compression, so not all images will achieve the same aesthetic quality at the same compression ratio. It depends on the contents of the image.

To set that just pass in the integer value 1 - 16 and cast it like,

FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JP2, dib, newName, (FREE_IMAGE_SAVE_FLAGS)Properties.Settings.Default.JPEG2000CompressionRateXto1);
Underground
  • 127
  • 5
  • This is almost correct, the "flags" for the JP2/J2K plugins are indeed interpreted as the rate. However it actually goes up to 1023, the actual line of code reads `parameters.tcp_rates[0] = (float)(flags & 0x3FF);` – poizan42 Jan 20 '17 at 16:00