[Insight-developers] Get/SetPixel() with taking an offset parameter

Luis Ibanez luis.ibanez at kitware.com
Mon Dec 11 17:51:08 EST 2006


Hi Gaetan,

That's an interesting option.

However, please note that a better way of approaching this problem
is to create an Iterator that is specific to the way you want to
walk in your image.

It seems that in your algorithm you are already defining a clever
way of finding the offsets that will lead you to the next pixel
of interest.  What we probably want to explore is the possibility
of creating a new Image Iterator that will do the equivalent job.

In general you want to avoid having direct access to the image buffer.
One of the reasons for it is that soon we will be introducing in ITK
an alternative memory layout where the pixel data is not stored in a
contiguous block of memory. Instead, the pixel data may be stored as
a collection of disconnected slices.

Having a GetPixel()/SetPixel() methods with direct access to the
buffer data will not work in this memory layout. We already will have
to manage the modification of the existing ComputOffset() method.

You will also have a harder time making sure that the algorithm works
in N-Dimensional images. It is in general, easier, to delegate to
Iterators the complex details of dealing with the N-Dimensionality
of the image.

What is the specific way in which you need to walk through the image
in the morphological reconstruction filters that you are preparing ?


   Please let us know,


      Thanks


         Luis



----------------------
Gaetan Lehmann wrote:
> 
> Hi,
> 
> Currently, the GetPixel() and SetPixel() methods of the itk::Image 
> class  are taking a itk::Index parameter to know which pixel is 
> concerned in the  image.
> The itk::Image also have the ComputeIndex() and ComputeOffset() methods 
> to  manipulate directly the offset in the buffer, and to convert this 
> offset  from/to an index.
> 
> Manipulating indexes in an algorithm (like in the current morphological  
> reconstruction filters, in the component tree contribution I'm 
> preparing  
> (http://voxel.jouy.inra.fr/darcsweb/darcsweb.cgi?r=componentTree;a=summary),  
> ...) would be a lot more efficient, both in memory and in execution 
> time,  by using the offsets instead of the indexes: store an itk::Index 
> cost 3  long (with dim=3), while an offset is only 1, and there is no 
> need to  convert the offset to an index and the index to an offset.
> Unfortunately, there is no Get/SetPixel() method able to work with an  
> offset.
> 
> I think that it would be a good idea to implement them as follow (not  
> tested yet, that's an example):
> 
> 
> 
> in itkImage.h:
> 
> void SetPixel(const OffsetValueType &offset, const TPixel& value)
>   {
>   (*m_Buffer)[offset] = value;
>   }
> 
> const TPixel& GetPixel(const OffsetValueType &offset) const
>   {
>   return ( (*m_Buffer)[offset] );
>   }
> 
> TPixel& GetPixel(const OffsetValueType &offset)
>   {
>   return ( (*m_Buffer)[offset] );
>   }
> 
> TPixel & operator[](const OffsetValueType &offset)
>   { return this->GetPixel(offset); }
> 
> const TPixel& operator[](const OffsetValueType &offset) const
>   { return this->GetPixel(offset); }
> 
> 
> void SetPixel(const IndexType &index, const TPixel& value)
>   {
>   typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
>   this->SetPixel( offset, value );
>   }
> 
> const TPixel& GetPixel(const IndexType &index) const
>   {
>   typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
>   return this->GetPixel( offset );
>   }
> 
> TPixel& GetPixel(const IndexType &index)
>   {
>   typename Superclass::OffsetValueType offset = this->ComputeOffset(index);
>   return this->GetPixel( offset );
>   }
> 
> TPixel & operator[](const IndexType &index)
>   { return this->GetPixel(index); }
> 
> const TPixel& operator[](const IndexType &index) const
>   { return this->GetPixel(index); }
> 
> 
> 
> in itkImageAdaptor.h:
> 
> void SetPixel(const IndexType &index, const PixelType & value)
>   { m_PixelAccessor.Set( m_Image->GetPixel(index), value ); }
> 
> PixelType GetPixel(const IndexType &index) const
>   { return m_PixelAccessor.Get( m_Image->GetPixel(index) ); }
> 
> PixelType operator[](const IndexType &index) const
>   { return m_PixelAccessor.Get( m_Image->GetPixel(index) ); }
> 
> 
> void SetPixel(const OffsetValueType &offset, const PixelType & value)
>   { m_PixelAccessor.Set( m_Image->GetPixel(offset), value ); }
> 
> PixelType GetPixel(const OffsetValueType &offset) const
>   { return m_PixelAccessor.Get( m_Image->GetPixel(offset) ); }
> 
> PixelType operator[](const OffsetValueType &offset) const
>   { return m_PixelAccessor.Get( m_Image->GetPixel(offset) ); }
> 
> 
> 
> Does it seem reasonable to do that ?
> 
> Thanks,
> 
> Gaetan
> 
> 
> 


More information about the Insight-developers mailing list