Skip to main content

How to reduce the size of a jpeg2000 image ?

5 replies [Last post]
le_marlou
Offline
Joined: 2010-01-27
Points: 0

Hi all,

I use Java ImageIO to :
- create JPEG images from JPEG2000 images
- create JPEG2000 images from JPEG images

The transformation JPEG2000 to JPEG works fine. The transformation JPEG to JPEG2000 works too, but the JPEG2000 images that I get have a size too big.
=> For a JPEG image 640x480 with a size 43 Kb, I get a JPEG2000 image with a size 170 Kb
=> For a JPEG image 800x600 with a size 66 Kb, I get a JPEG2000 image with a size 276 Kb

I tried to change many parameters in the J2KImageWriteParam object :

<br />
final J2KImageWriteParam paramJ2K = new J2KImageWriteParam();<br />
paramJ2K.setLossless(false);<br />
paramJ2K.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);<br />
paramJ2K.setCompressionType("JPEG2000");<br />
paramJ2K.setCompressionQuality(0.5F);<br />
paramJ2K.setEncodingRate(Double.MAX_VALUE);<br />
paramJ2K.setFilter(J2KImageWriteParam.FILTER_53);</p>
<p>//      paramJ2K.setWriteCodeStreamOnly(true);<br />
//      paramJ2K.setComponentTransformation(true);<br />
//      paramJ2K.setProgressionType("res"); //Resolution-Layer-Component-Position<br />
//      paramJ2K.setProgressionType("layer"); //Layer-Resolution-Component-Position<br />
//      paramJ2K.setProgressionType("res-pos"); //Resolution-Position-Component-Layer<br />
//      paramJ2K.setProgressionType("pos-comp"); //Position-Component-Resolution-Layer<br />
//      paramJ2K.setProgressionType("comp-pos"); //Component-Position-Resolution-Layer<br />

But, whatever the values, I still have the same size.
Can someone help me please ?
Thanx

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
marcgfx
Offline
Joined: 2010-04-21
Points: 0

//casting works, the parameter is correct
J2KImageWriteParam jwp = (J2KImageWriteParam)iwp;
jwp.setLossless(false);
jwp.setFilter(jwp.FILTER_97);

//no matter what is set here, the result does not change
jwp.setEncodingRate(0.01);
--------------------------------

none of the settings I have made seem to have an effect on the resulting image. I was expecting a low compression quality to give me small files, or that a low encoding rate would do the trick. the resulting image is always of good quality, so I believe maybe the setLossless(false) has no effect?

marcgfx
Offline
Joined: 2010-04-21
Points: 0

um sorry for this 3rd post in a row, but the forum would not take my full message in one go. half of it just got dumped, so i had to add it again in the second post. this one is just to clear things up. yay.

le_marlou
Offline
Joined: 2010-01-27
Points: 0

Hi,
I found a solution, for those interested :
I change filter to have this :

[code]
paramJ2K.setFilter(J2KImageWriteParam.FILTER_97);
[/code]
So I get a JPEG2000 with very good quality and a size ~40 Kb.
Nevertheless, whatever the value I set for compression quality and encoding rate, it has no effect on the quality and the size of the JPEG2000 image, I don't know why...

marcgfx
Offline
Joined: 2010-04-21
Points: 0

I'm currently trying to reduce the size too. I must be doing something similar as le_marlou, but I really think the 40Kb would be a bad result. I am currently getting results similar to png and I know for sure that this is by far not good enough for jpeg2000. So either I am doing something wrong (very likely) or something is not working correctly. Code has been cleaned for posting, so if there is a small mistake, it happened while editing.

--------------------------------
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg2000");
ImageWriter writer = (ImageWriter)iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();

//list of all types, only one seems to exist
String[] ct = iwp.getCompressionTypes();
for(int i=0;i System.out.println("compression type : "+ct[0]);
}

iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionType(ct[0]);
iwp.setCompressionQuality(0.01f);

//casting works, the parameter is correct
J2KImageWriteParam jwp = (J2KImageWriteParam)iwp;
jwp.setLossless(false);
jwp.setFilter(jwp.FILTER_97);

//no matter what is set here, the result does not change
jwp.setEncodingRate(0.01);
--------------------------------

none of the settings I have made seem to have an effect on the resulting image. I was expecting a low compression quality to give me small files, or that a low encoding rate would do the trick. the resulting image is always of good quality, so I believe maybe the setLossless(false) has no effect?

jasper2011
Offline
Joined: 2011-02-15
Points: 0

Hi marcgfx,
I am facing the similar issue whilst converting the jpeg to jpeg2000 (the size is increased to 3 / 4 times ) .
Did you find any solution for it .please share the piece of code .
Thanks.