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

Chris Farmer cfarmer at scitegic.com
Wed Sep 7 21:48:31 EDT 2005



Clearly I'm not getting my real question across here! :(

I don't really care so much about PNG.  I really just care that I don't
have a file, and I don't want to have to create a file.  I understand
that there must be a PNG *reader* of some sort to interpret the
relatively complex data structure within the file.  I just don't
understand why the source of the data (PNG or otherwise) must be a
physical file.  I have an array of bytes that contains png data.  I know
the lifetime of this array is such that it can be around for as long as
I need it.  Why can't I use this array as a source to a PNG reader?

Would you suggest that I write my own classes to extend the file-based
readers to handle in-memory buffer reads?  It seems like this isn't
quite the right way to go, since the logic in the Read method (for the
PNG reader at least) is pretty tied in to the file pointer and would
require a fair amount of refactoring and debugging for someone with no
familiarity with the code.  But, I'm willing to write code to accomplish
this.

I would certainly appreciate hearing your reasons why you think this is
a dumb idea or why it can't be done.  My concern is that I'd spend a lot
of time writing and reading files, while my image processing task itself
may not be all that interesting.  (Again, this may be pre-optimizing a
non-existent problem.)

Am I grossly misunderstanding some key aspect of the itk framework here?
It certainly feels like I'm barking up the wrong tree!


Thanks,
Chris


 

-----Original Message-----
From: Karthik Krishnan [mailto:Karthik.Krishnan at kitware.com] 
Sent: Wednesday, September 07, 2005 6:16 PM
To: Chris Farmer
Cc: insight-users at itk.org
Subject: RE: [Insight-users] Re: Importing image data from a byte array

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.

 


More information about the Insight-users mailing list