[Insight-developers] Reading vector images

Stephen R. Aylward aylward at unc.edu
Thu, 13 May 2004 18:26:36 -0400


Hi,

I dunno, is a multi-channel image of floats the same as an image of 
vectors of floats? :)  Right now, I think, metaImage handles them the 
same, but I think MetaImage is wrong in this regard and we should 
perhaps distinguish them.

The idea behind using FLOAT instead of FLOAT_ARRAY is based on how the 
data is read.   Basically the size (in memory) of an image is set as 
numberOfPixel*numberOfChannels*sizeOfPixelType

For the simple case of multiple values per pixel this works with 
PixelType = FLOAT.

The question becomes what should we return for SizeOf(FLOAT_ARRAY). 
UGH - right now it returns 4 (bad Stephen).   Yup, sometimes metaImage 
sucks.   There isn't a simple fix.  But, I'd rather fix this in 
metaImage than accept the convention that sizeOf(FLOAT_ARRAY) = 4 and 
that numberOfChannels is the number of components in that array - it 
seems wrong that SizeOf(FLOAT) = SizeOf(FLOAT_ARRAY).  So, until we fix 
that, perhaps we should keep using an image of vectors as a 
multi-channel image instead of a single channel image of a pixelType 
that returns the wrong SizeOf.  That way, if we fix the 
sizeOf(FLOAT_ARRAY) problem then we'll be able to have multi-channel 
images where each channel is an array of floats...

Lessor of evils...your choice...take the blue pill....

Stephen


Miller, James V (Research) wrote:

> A bug was reported in the beginning of February and another bug was
> reported in Oct 2003. And I just verified it again yesterday :)
> 
> The meta library was pretty much okay.  The MetaIO object was pretty much
> okay. The ImageIOBase and ImageFileReader were not. 
> 
> My interpretation of ImageIO object is that PixelType could be any of 
> CHAR, UCHAR, SHORT, USHORT, ...., RGB, RGBA, VECTOR, COVARIANTVECTOR, ...
> 
> ComponentType could be any native type (but not VECTOR, COVARIANTVECTOR,
> RGB...)
> 
> So a vector image would have a PixelType of VECTOR and ComponentType of 
> (for instance) float.
> 
> Currently, if you asked an ImageFileReader for an Image<Vector<float, 2>,
> 2>,
> you get a block of raw memory.  The ImageIO object says the PixelType
> is float while the reader is told to output Vector<float, 2>.  These types
> are not the same, so a call to DoConvertBuffer is made.  But there is no
> case in DoConvertBuffer for an output pixel type with two components.
> 
> DoConvertBuffer does make a number of assumptions that a multiple component
> pixel is RGB.  A potentially dangerous decision.
> 
> In terms of the Meta format.  I thought an image of MET_FLOAT_ARRAY would 
> be equivalent to a Vector<float, NumComponents> whereas an image of
> MET_FLOAT
> would be an image of scalar floats.  Is this not the case? If not, how does
> Meta
> treat pixels with multiple components? And what is a MET_FLOAT_ARRAY?
> 
> Jim
> 
> 
> 
> 
> -----Original Message-----
> From: Stephen R. Aylward [mailto:aylward at unc.edu]
> Sent: Thursday, May 13, 2004 10:51 AM
> To: Miller, James V (Research)
> Cc: 'Luis Ibanez'; Insight-developers (E-mail); Julien Jomier
> Subject: Re: [Insight-developers] Reading vector images
> 
> 
> Hi,
> 
> I think we need to think about this more for consistency.
> 
> I've traditionally distinguished multi-component images from images of 
> vectors.   MetaImage supports multi-component images - that is, an image 
> of float with multiple channels per pixel.  Versus an image of float_arrays.
> 
> MetaImage has been working for multi-channel images perhaps it has been 
> broken recently, but I know it has worked in the past ai-is.
> 
> If you make changes, please ensure backward compatibility with what has 
> been working in the past.   We and others have been using it by 
> by-passing itk's IO classes and using MetaIO direct.
> 
> Thanks,
> Stephen
> 
> Miller, James V (Research) wrote:
> 
> 
>>Okay.
>>
>>I have part of this working now. There was a minor error in the MetaIO
>>object wrt to setting ComponentType verses setting PixelType for arrays.
>>
>>I need to go back and check whether MetaIO writes pixel type in its header
>>as META_FLOAT_ARRAY when writing vector images.  I may have editted a  
>>meta header by hand to change a META_FLOAT to a META_FLOAT_ARRAY.
>>
>>However, most of bug is in the ImageFileReader and ImageIOBase. My current
>>solution relies on the memory layout for a Vector<T, N> being equivalent to
>>the
>>memory layout of an array T[N].  If we can assume this, then I have most
>>of the trivial case working (I was able to read a meta image with 2D
>>vectors).
>>
>>One hurdle is going to be if a file has vectors of floats and the reader is
>>asked to produce a vector of ints.  I'll need to modify
> 
> DoConvertPixelBuffer
> 
>>to handle this.
>>
>>Interesting that we have a number of examples that read vector images.
> 
> What
> 
>>file formats were these tested on?
>>
>>Jim
>>
>>
>>
>>-----Original Message-----
>>From: Luis Ibanez [mailto:luis.ibanez at kitware.com]
>>Sent: Wednesday, May 12, 2004 7:10 PM
>>To: Miller, James V (Research)
>>Cc: Insight-developers (E-mail); Julien Jomier
>>Subject: Re: [Insight-developers] Reading vector images
>>
>>
>>
>>Hi Jim,
>>
>>Yes, this is a known bug in the MetaImage reader.
>>
>> http://www.itk.org/Bug/bug.php?op=show&bugid=580&pos=12
>>
>>Although, as you pointed out, the error may actually
>>be in the ImageFileReader<> class.
>>
>>
>>If you have any hints of how to solve it,
>>please go ahead   :-)
>>
>>
>>Your suggestion seem to be in the right direction.
>>We certainly have a lot more types defined in
>>
>>
>>         ImageIOBase::SetPixelType()
>>
>>that in
>>
>>         ImageIOBase::GetPixelType()
>>
>>
>>They should probably be made symmetrical...
>>
>>
>>
>>  Luis
>>
>>
>>
>>
>>------------------------------------
>>Miller, James V (Research) wrote:
>>
>> 
>>
>>
>>>I just tried to read an image of two component vectors into ITK using 
>>>the Meta format.
>>>
>>>I get all zeros.
>>>
>>>It looks to me that in ImageFileReader::GenerateData() there is a test for
>>>
>>>     m_ImageIO->GetPixelType() == typeid(TOutputImage::PixelType)
>>>
>>>TOutputImage::PixelType should be Vector<float, 2>
>>>
>>>m_ImageIO->GetPixelType() returns float
>>>
>>>The above check for equality fails and a data conversion occurs.  The 
>>>result is all zeros.
>>>
>>>It looks as though people have asked this on the list before but I did 
>>>not find a response.
>>>I seem to recall people reading vectors as RGB pixels.
>>>
>>>Perhaps if I add a GetPixelType() method to MetaImageIO that checks the 
>>>m_PixelType to be VECTOR?
>>>
>>>
>>>
>>>
>>>*Jim Miller*
>>>*/_____________________________________/*
>>>/Visualization & Computer Vision//
>>>/GE Research/
>>>/Bldg. KW, Room C218B/
>>>/P.O. Box 8, Schenectady NY 12301/
>>>
>>>//_millerjv at research.ge.com <mailto:millerjv at research.ge.com>_/
>>>
>>>/_james.miller at research.ge.com_/
>>>/(518) 387-4005, Dial Comm: 8*833-4005, /
>>>/Cell: (518) 505-7065, Fax: (518) 387-6981/
>>>
>>>
>>>   
>>>
>>
>>
>>_______________________________________________
>>Insight-developers mailing list
>>Insight-developers at itk.org
>>http://www.itk.org/mailman/listinfo/insight-developers
>> 
>>
> 
> 
> 

-- 
===========================================================
Dr. Stephen R. Aylward
Associate Professor of Radiology
Adjunct Associate Professor of Computer Science and Surgery
http://caddlab.rad.unc.edu
aylward at unc.edu
(919) 966-9695