Re: ImageJ AVI export & JPEG compression

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ AVI export & JPEG compression

Wayne Rasband
 > Hello I think I am having a small issue ImageJ AVI export &
 > JPEG compression :
 >
 > The quality factor for JPEG is not used: selecting 10 or 90
 > does not affect the quality or the size of the resulting
 > movie.

I broke the JPEG Quality option when I replaced
com.sun.image.codec.jpeg with ImageIO so that ImageJ could be compiled
with the OpenJDK. I removed the AVI Writer's JPEG Quality option in
v1.43n since it is not obvious how to specify the quality with ImageIO.
In any case, this option was confusing since it only applied to one out
of the three compression choices.

 > That JPEG compression option you added a few months ago is
 > great: It keeps a good quality and plays just everywhere
 > without having to install anything (windows, mac,
 > powerpoint windows & mac, quicktime....)

Michael Schmid should get most of the credit for ImageJ's ability to
read and write AVIs.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ AVI export & JPEG compression

Albert Cardona-2
On Thu, Dec 10, 2009 at 3:13 PM, Wayne Rasband <[hidden email]> wrote:

>> Hello I think I am having a small issue ImageJ AVI export &
>> JPEG compression :
>>
>> The quality factor for JPEG is not used: selecting 10 or 90
>> does not affect the quality or the size of the resulting
>> movie.
>
> I broke the JPEG Quality option when I replaced com.sun.image.codec.jpeg
> with ImageIO so that ImageJ could be compiled with the OpenJDK. I removed
> the AVI Writer's JPEG Quality option in v1.43n since it is not obvious how
> to specify the quality with ImageIO. In any case, this option was confusing
> since it only applied to one out of the three compression choices.


I use ImageIO in TrakEM2. Setting JPEG quality is verbose, but can be done:

String path = ....

FileOutputStream f = null;
ImageOutputStream ios = null;
ImageWriter writer = null;
BufferedImage grey = bi;
try {
    f = new FileOutputStream(path);
    writer = ImageIO.getImageWritersByFormatName("jpeg").next();
    ios = ImageIO.createImageOutputStream(f);
    writer.setOutput(ios);
    ImageWriteParam param = writer.getDefaultWriteParam();
    param.setCompressionMode(param.MODE_EXPLICIT);
    param.setCompressionQuality(quality);
    IIOImage iioImage = new IIOImage(grey, null, null);
    writer.write(null, iioImage, param);
} catch (Exception e) {
    IJError.print(e);
} finally {
    if (null != f) try { f.close(); } catch (Exception ee) {}
    if (null != writer) try { writer.dispose(); } catch (Exception ee) {}
    if (null != ios) try { ios.close(); } catch (Exception ee) {}
}

See the code in context:

http://repo.or.cz/w/trakem2.git/blob/HEAD:/ini/trakem2/io/ImageSaver.java#l150

Albert
--
http://albert.rierol.net