[Insight-developers] Get/SetPixel() with taking an offset parameter
Gaetan Lehmann
gaetan.lehmann at jouy.inra.fr
Mon Dec 11 11:20:59 EST 2006
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
--
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66 fax: 01 34 65 29 09
http://voxel.jouy.inra.fr
More information about the Insight-developers
mailing list