1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__REGIONOFINTERESTIMAGECALCULATOR__HXX__
6 #define __CPEXTENSIONS__ALGORITHMS__REGIONOFINTERESTIMAGECALCULATOR__HXX__
8 #include <itkImageRegionConstIteratorWithIndex.h>
10 // -------------------------------------------------------------------------
11 template< class _TImage >
12 void cpExtensions::Algorithms::RegionOfInterestImageCalculator< _TImage >::
15 typedef itk::ImageRegionConstIteratorWithIndex< _TImage > _TIterator;
16 typedef typename _TImage::RegionType _TRegion;
18 if( this->m_Image.IsNotNull( ) )
20 _TRegion region = this->m_Image->GetRequestedRegion( );
21 TIndex minidx = region.GetIndex( );
22 TIndex maxidx = minidx + region.GetSize( );
23 for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
27 _TIterator i( this->m_Image, region );
28 for( i.GoToBegin( ); !i.IsAtEnd( ); ++i )
30 if( i.Get( ) != this->m_BackgroundValue )
32 TIndex idx = i.GetIndex( );
35 for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
37 minidx[ d ] = ( idx[ d ] < minidx[ d ] )? idx[ d ]: minidx[ d ];
38 maxidx[ d ] = ( idx[ d ] > maxidx[ d ] )? idx[ d ]: maxidx[ d ];
44 minidx = maxidx = idx;
52 this->m_Minimum = minidx;
53 this->m_Maximum = maxidx;
57 this->m_Minimum.Fill( 0 );
58 this->m_Maximum.Fill( 0 );
63 // -------------------------------------------------------------------------
64 template< class _TImage >
65 cpExtensions::Algorithms::RegionOfInterestImageCalculator< _TImage >::
66 RegionOfInterestImageCalculator( )
68 m_BackgroundValue( TPixel( 0 ) )
70 this->m_Minimum.Fill( 0 );
71 this->m_Maximum.Fill( 0 );
74 // -------------------------------------------------------------------------
75 template< class _TImage >
76 cpExtensions::Algorithms::RegionOfInterestImageCalculator< _TImage >::
77 ~RegionOfInterestImageCalculator( )
83 typename _TImage::ConstPointer m_Image;
84 TPixel m_BackgroundValue;
90 #endif // __CPEXTENSIONS__ALGORITHMS__REGIONOFINTERESTIMAGECALCULATOR__HXX__