question about saving jpgs

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

question about saving jpgs

Tobias Kloepper
Dear all,
I started to use imageJ as a lib for my java application and got stuck
trying to write an ImagePlus object to an OutputStream (actually I am
trying to save the image in a database). I would like to use jpg as
output format, rather than writing the raw object.
  I am guessing I need to use a FileInfo object  to generate an instance
of ImageWriter, which will then provide the write method for the
OutputStream, but how do I get the compression into jpg (or any other
format)  to work?

Any help would be very much appreciated.

Tobias

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: question about saving jpgs

Barry DeZonia
I think you can just use JpegWriter (ij.plugin.JpegWriter) directly and
skip all the FileInfo. It has a static save() method.


On Fri, Feb 8, 2013 at 3:06 AM, Tobias Kloepper
<[hidden email]>wrote:

> Dear all,
> I started to use imageJ as a lib for my java application and got stuck
> trying to write an ImagePlus object to an OutputStream (actually I am
> trying to save the image in a database). I would like to use jpg as output
> format, rather than writing the raw object.
>  I am guessing I need to use a FileInfo object  to generate an instance of
> ImageWriter, which will then provide the write method for the OutputStream,
> but how do I get the compression into jpg (or any other format)  to work?
>
> Any help would be very much appreciated.
>
> Tobias
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.**html<http://imagej.nih.gov/ij/list.html>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: question about saving jpgs

ctrueden
In reply to this post by Tobias Kloepper
Hi Tobias,

> I started to use imageJ as a lib for my java application and got stuck
> trying to write an ImagePlus object to an OutputStream (actually I am
> trying to save the image in a database). I would like to use jpg as
> output format, rather than writing the raw object.

With a little effort, you can use Bio-Formats to write your data to a byte
array in memory in any supported output format (e.g., JPEG) [1].
Bio-Formats in included in the Fiji distribution of ImageJ (http://fiji.sc/
).

The key part to make it write to a byte array is:

    String outId = fileName + ".jpg";
    ByteArrayHandle outputFile = new ByteArrayHandle();
    Location.mapFile(outId, outputFile);

Which maps the id string (which would normally be considered a filename) to
a byte array handle instead.

For quick results, you could hack up a version of the Bio-Formats Exporter
plugin [1] to incorporate the logic above.

Alternately, if you are really in a hurry, you can use JpegWriter as Barry
suggested to write to a temp file, then just rip the file back in from disk.

Regards,
Curtis

[1]
https://github.com/openmicroscopy/bioformats/blob/v4.4.5/components/bio-formats/utils/ReadWriteInMemory.java
[2]
https://github.com/openmicroscopy/bioformats/blob/v4.4.5/components/loci-plugins/src/loci/plugins/out/Exporter.java


On Fri, Feb 8, 2013 at 3:06 AM, Tobias Kloepper
<[hidden email]>wrote:

> Dear all,
> I started to use imageJ as a lib for my java application and got stuck
> trying to write an ImagePlus object to an OutputStream (actually I am
> trying to save the image in a database). I would like to use jpg as output
> format, rather than writing the raw object.
>  I am guessing I need to use a FileInfo object  to generate an instance of
> ImageWriter, which will then provide the write method for the OutputStream,
> but how do I get the compression into jpg (or any other format)  to work?
>
> Any help would be very much appreciated.
>
> Tobias
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.**html<http://imagej.nih.gov/ij/list.html>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html