[Insight-users] Re: Importing image data from a byte array

Karthik Krishnan Karthik.Krishnan at kitware.com
Wed Sep 7 21:16:13 EDT 2005


On Wed, 2005-09-07 at 14:26 -0700, Chris Farmer wrote:
> 
> This makes perfect sense.  I was trying this since others suggested the
> ImportImageFilter as a way to get PNG data into an itk image.  Now I'm
> back to square one... is there a straightforward way to get PNG data (or
> some other non-raw image format)

To read PNG data as an image, you *need* a PNG reader. PNG's are
compressed and not trivially readable as one shot file read... ITK has a
PNG reader. Your system probably has interfaces that you could use:
libpng.

Now, if you were asking for a way to convert PNG to raw: 

1. Use ImageMagick (www.imagemagick.org)

For instance to covert BrainProtonDensitySlice.png to raw:

/usr/bin/covert BrainProtonDensitySlice.png
gray:BrainProtonDensitySlice.raw


2. Use ITK to read it as *.png , write it as *.raw...


>  from a byte array into an itk Image?

One you have the byte array, using the import image filter just as you
did is fine.

> 
> 
> 
>  
> 
> -----Original Message-----
> From: Karthik Krishnan [mailto:Karthik.Krishnan at kitware.com] 
> Sent: Wednesday, September 07, 2005 2:14 PM
> To: Chris Farmer
> Cc: insight-users at itk.org
> Subject: Re: [Insight-users] Re: Importing image data from a byte array
> 
> <snip>
> 
> You cannot read in a PNG image like a standard file stream . PNG's have 
> headers... You could do this with a "RAW" file format. (which you 
> probably will never find on the web). Such a raw file will be of size 
> 240*160*sizeof(PixelType).
> 
> This is why your output is garbled.
> 
>  
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list