Re: Open an ImagePlus from a stream or bytearray

Posted by ctrueden on
URL: http://imagej.273.s1.nabble.com/Open-an-ImagePlus-from-a-stream-or-bytearray-tp3700040p3700042.html

Hi Johannes,

You can construct an ImageProcessor subclass corresponding to the type
of pixel data you need, and then pass it to the ImagePlus constructor.
For example, for an 8-bit image stored as bytes:

    byte[] pix = ...; // get your bytes somehow
    int w = ...; // width of image
    int h = ...; // height of image
    ByteProcessor proc = new ByteProcessor(w, h, pix, null);
    ImagePlus imp = new ImagePlus("My Image", proc);
    imp.show();

We do a lot of array-to-ImagePlus conversions in the Bio-Formats
Importer plugin. You can check the source for a more complex example:

https://skyking.microscopy.wisc.edu/svn/java/trunk/loci/plugins/Importer.java

Lines 718-868, which constructs ImageProcessor and ImagePlus objects,
are probably most relevant.

-Curtis

On 3/16/07, Johannes Hermen <[hidden email]> wrote:

> Hi,
>
> Does anybody know if it is possible to create an ImagePlus directly from an
> InputStream or a ByteArray.
> I need to create ImagePlus objects from DICOM files that are retrieved from
> a Database, so that i can only get them as Stream or ByteArray.
>
>
> Thanks in advance
>
>        _Johannes
>
> -----------------------------------------------------------------
> Johannes Hermen  -  Ingenieur de Recherche
> [hidden email]
> -----------------------------------------------------------------
> CRP Henri Tudor  http://www.santec.tudor.lu
> 29, Avenue John F. Kennedy
> L-1855 Luxembourg
> -----------------------------------------------------------------
>