Re: Better jpeg quality

Posted by Jon Harman on
URL: http://imagej.273.s1.nabble.com/Better-jpeg-quality-tp3697120p3697126.html

Hi,

Thanks for pointing me in that direction.
The code
             int i0 = param.getHorizontalSubsampling(0);
             int i1 = param.getHorizontalSubsampling(1);
             int i2 = param.getHorizontalSubsampling(2);
              IJ.write("Horiz:" + i0 + " " + i1 + " " + i2);
             int j0 = param.getVerticalSubsampling(0);
             int j1 = param.getVerticalSubsampling(1);
             int j2 = param.getVerticalSubsampling(2);
             IJ.write("Vert:" + j0 + " " + j1 + " " + j2);
produces the results:
Horiz:1 2 2
Vert:1 2 2
I think that this means the subsampling is set to 2 for the two color
channels and to 1 for the brightness channel.

The code:
             param.setHorizontalSubsampling(1, 1);
             param.setHorizontalSubsampling(2, 1);
             param.setVerticalSubsampling(1, 1);
             param.setVerticalSubsampling(2, 1);
produces the results:
Horiz:1 1 1
Vert:1 1 1

The output has better quality for colors, but poorer compression at the
same quality number.

My guess is that this is what Irfanview does.

Since I am very interested in colors I think it would be great if ImageJ
would give the option to set the jpeg color subsampling to 1.



Jon


Albert Cardona wrote:

> Jon,
>
> There is no such plugin, but you can have a look yourself at the
> com.sun.image.codec.jpeg.*  classes, particuarly:
>
> JPEGImageEncoder encoder =
> JPEGCodec.createJPEGEncoder(f);                        
> JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi)
>
>
> and the decoder equivalents.
>
> But be warned: half the time one doesn't get the parameters right, and
> the jpg file fails to decode.
>
>
> Albert
>