[Insight-developers] What are the bounds of an itkImageRegion?
Luis Ibanez
luis.ibanez at kitware.com
Tue Dec 30 18:51:29 EST 2008
Hi Steve,
Image Regions are defined in the digital space of the image grid,
not in the continous space of physical coordinates.
The region defined by
start = 1
size = 2
includes only the two pixels of indices :
a) index = 1
b) index = 2
not the continous range of real coordinates
[1.0, 2.99)
The point at 2.99 is not part of that region.
In fact, this ties up to the discussion on how we define the
center of a pixel, and how we compute rounding.
The currect code in itkImageRegion is:
/** Test if an index is inside */
template <typename TCoordRepType>
bool
IsInside(const ContinuousIndex<
TCoordRepType,VImageDimension> &index) const
{
for(unsigned int i=0; i<ImageDimension; i++)
{
if( index[i] < static_cast<TCoordRepType>( m_Index[i] ) )
{
return false;
}
// bound is the last valid pixel location
const TCoordRepType bound = static_cast<TCoordRepType>(
m_Index[i] + static_cast<long>(m_Size[i]) - 1);
if( index[i] > bound )
{
return false;
}
}
return true;
}
We have to review our definition of Voronoi regions
associated to the image grid, before we can tell
if this is a bug or not.
We plan to discuss this next week at the NAMIC meeting...
Regards,
Luis
-------------------------
Steve M. Robbins wrote:
> Hi,
>
> While pondering issue 6558 "Physical coordinates of a pixel - Severe
> inconsistency and bug in ImageBase", I started writing some
> tests for itkImageRegion.
>
> I came to the conclusion that either I misunderstand this class or
> there's a more fundamental bug in there.
>
> The class doc says:
>
> * \brief An image region represents a structured region of data.
> *
> * ImageRegion is an class that represents some structured portion or
> * piece of an Image. The ImageRegion is represented with an index and
> * a size in each of the n-dimensions of the image. (The index is the
> * corner of the image, the size is the lengths of the image in each of
> * the topological directions.)
>
> Consider a 1-dimensional region with start=1, size=2. I interpreted
> the above to mean that the region is the half-open interval [1,3) on
> the real line. Or maybe it's the closed interval [1,3] ?
>
> In either case, I expected 2.99 to be included in the region,
> but it isn't as the following test-case shows (written
> using Boost.Test; c.f. my earlier post from this evening).
>
>
> BOOST_AUTO_TEST_CASE( testContinuousIndexPointIsInsideEdgeConvention )
> {
> Fixture1 line( 1, 2 );
> Fixture1::CIndexType p0, p1, p2, p3;
>
> p0[0] = 0.99;
> p1[0] = 1.01;
> p2[0] = 2.99;
> p3[0] = 3.01;
>
> BOOST_CHECK( ! line.mRegion.IsInside( p0 ) );
> BOOST_CHECK( line.mRegion.IsInside( p1 ) );
> BOOST_CHECK( line.mRegion.IsInside( p2 ) );
> BOOST_CHECK( ! line.mRegion.IsInside( p3 ) );
> }
>
>
> See below for the Fixture code. This test fails on the p2 line -- it
> is treated as being outside the region.
>
> By the way, is there any concensus to fix this? I believe the code
> should be modified to follow the ITK Software Guide; i.e. to
> use pixel-centre convention, in which case the test needs to
> be modified to:
>
> p0[0] = 0.49;
> p1[0] = 0.51;
> p2[0] = 2.49;
> p3[0] = 2.51;
>
>
> Regards,
> -Steve
>
> P.S. The Fixture code follows.
>
> template< unsigned int VImageDimension >
> struct Fixture
> {
> typedef itk::ImageRegion<VImageDimension> RegionType;
> typedef typename RegionType::IndexType IndexType;
> typedef typename RegionType::SizeType SizeType;
> typedef itk::ContinuousIndex<float,VImageDimension> CIndexType;
>
> RegionType mRegion;
> };
>
> struct Fixture1 : public Fixture<1>
> {
> Fixture1( int start0,
> int size0 )
> {
> IndexType start = {{ start0 }};
> SizeType size = {{ size0 }};
> mRegion = RegionType( start, size );
> }
> };
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
More information about the Insight-developers
mailing list