1 #include <plugins/ImageFilters/RegionOfInterestImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances_ExtractImageFilters.h>
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::RegionOfInterestImageFilter::
7 RegionOfInterestImageFilter( )
10 this->_AddInput( "Input" );
11 this->_AddOutput< cpPlugins::Image >( "Output" );
12 this->m_Parameters.ConfigureAsBool( "AutomaticRegion" );
13 this->m_Parameters.ConfigureAsReal( "BackgroundValue" );
14 this->m_Parameters.SetBool( "AutomaticRegion", true );
15 this->m_Parameters.SetReal( "BackgroundValue", 0 );
18 // -------------------------------------------------------------------------
19 cpPluginsImageFilters::RegionOfInterestImageFilter::
20 ~RegionOfInterestImageFilter( )
24 // -------------------------------------------------------------------------
25 void cpPluginsImageFilters::RegionOfInterestImageFilter::
28 auto image = this->GetInputData< itk::DataObject >( "Input" );
29 cpPlugins_Image_Demangle_Pixel_AllScalars ( _GD0, image, 2 );
30 else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
31 else this->_Error( "No valid input image." );
34 // -------------------------------------------------------------------------
35 template< class _TInputImage >
36 void cpPluginsImageFilters::RegionOfInterestImageFilter::
37 _GD0( _TInputImage* image )
40 itk::RegionOfInterestImageFilter< _TInputImage, _TInputImage >
43 cpExtensions::Algorithms::RegionOfInterestImageCalculator< _TInputImage >
46 if( this->m_Parameters.GetBool( "AutomaticRegion" ) )
48 typename _TCalculator::Pointer calculator = _TCalculator::New( );
49 calculator->SetImage( image );
50 calculator->Compute( );
52 auto minidx = calculator->GetMinimum( );
53 auto maxidx = calculator->GetMaximum( );
54 typename _TInputImage::SizeType size;
55 for( unsigned int d = 0; d < _TInputImage::ImageDimension; ++d )
56 size[ d ] = maxidx[ d ] - minidx[ d ] + 1;
58 typename _TInputImage::RegionType roi;
59 roi.SetIndex( minidx );
62 auto filter = this->_CreateITK< _TFilter >( );
63 filter->SetInput( image );
64 filter->SetRegionOfInterest( roi );
66 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
69 this->_Error( "Manual region not yet implemented." );