Login  Register

Re: Need java code to uncompress a multiframe DICOM

Posted by Melissa Linkert on Jan 02, 2009; 5:01pm
URL: http://imagej.273.s1.nabble.com/Need-java-code-to-uncompress-a-multiframe-DICOM-tp3694125p3694130.html

Hi Phanikanth,

> But as I am uploading MultiFrame DICOM image from web page, is there any
> way
> to pass byte array as param to the IFormatReader.setId() method instead of
> file path.


You can't pass a byte array directly to IFormatReader.setId, but it is quite
easy to have Bio-Formats read images from a byte array instead of a file on
disk.  Here is an example of how to do this:

import java.io.IOException;
import loci.common.*;
import loci.formats.*;

public class Test {
  public static void main(String[] args) throws FormatException, IOException
{
    // the byte array from which to read
    byte[] bytes = new byte[];

    RABytes file = new RABytes(bytes);
    // Assign a name to the byte array - if you know the file type in
advance,
    // it's a good idea to use the appropriate extension. If you don't know
    // the file type, don't use an extension, e.g. "file-in-memory".
    //
    // This example assumes that the byte array represents DICOM data.
    Location.mapFile("file-in-memory.dcm", file);

    // initialize the reader
    ImageReader reader = new ImageReader();
    reader.setId("file-in-memory.dcm");

    // read each image
    for (int i=0; i<reader.getImageCount(); i++) {
      reader.openImage(i);
    }

    reader.close();
  }
}

Note that this requires keeping the entire file in memory, which can be
problematic if the file size exceeds the available memory.

I have CC'd the LOCI software mailing list - if you have additional
questions regarding how to use Bio-Formats as a library, please send them to
that list.  Instructions on how to subscribe/post to the LOCI software list
are available at http://loci.wisc.edu/software/index.html.

Regards,
-Melissa

On Fri, Jan 2, 2009 at 7:26 AM, vmunukutla <[hidden email]> wrote:

> Prashanth,
>
> Thank very much for your value able suggestion.
> Actaully my requirement is I will upload a compressed DICOM image from a
> web
> page and I have to uncompress the DICOM image and store the umcompressed
> images into the database.
>
> Using bio-formats as a library I am able to get the uncompressed images.
>
> But as I am uploading MultiFrame DICOM image from web page, is there any
> way
> to pass byte array as param to the IFormatReader.setId() method instead of
> file path.
>
> import java.io.IOException;
> import loci.formats.ChannelSeparator;
> import loci.formats.FormatException;
> import loci.formats.IFormatReader;
> public class Read_Image {
>          public static void main(String args[]) {
>
>                String id  = "D:\\compressed\\US-PAL-8-10x-echo.dcm";
>                IFormatReader r = new ChannelSeparator();
>                try {
>                      r.setId(id);
>                      int num = r.getImageCount();
>                      System.out.println("num :: "+num);
>                }
>                catch (FormatException exc) {
>                     exc.printStackTrace();
>                }
>                catch (IOException exc) {
>                    exc.printStackTrace();
>                }
>          }
> }
>
>
>
> --
> View this message in context:
> http://n2.nabble.com/Need-java-code-to-uncompress-a-multiframe-DICOM-tp2101318p2101777.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>