1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__
6 #define __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__
10 #include <vnl/vnl_math.h>
12 #include <itkImageRegionIterator.h>
13 #include <itkImageRegionConstIterator.h>
15 // -------------------------------------------------------------------------
16 template< class I, class O, class C >
17 O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
20 return( this->GetOutput( 0 ) );
23 // -------------------------------------------------------------------------
24 template< class I, class O, class C >
25 O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
28 return( this->GetOutput( 1 ) );
31 // -------------------------------------------------------------------------
32 template< class I, class O, class C >
33 O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
36 return( this->GetOutput( 2 ) );
39 // -------------------------------------------------------------------------
40 template< class I, class O, class C >
41 const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
44 if( this->GetNumberOfOutputs( ) > 0 )
46 dynamic_cast< const O* >(
47 this->itk::ProcessObject::GetOutput( 0 )
54 // -------------------------------------------------------------------------
55 template< class I, class O, class C >
56 const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
59 if( this->GetNumberOfOutputs( ) > 1 )
61 dynamic_cast< const O* >(
62 this->itk::ProcessObject::GetOutput( 1 )
69 // -------------------------------------------------------------------------
70 template< class I, class O, class C >
71 const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
74 if( this->GetNumberOfOutputs( ) > 2 )
76 dynamic_cast< const O* >(
77 this->itk::ProcessObject::GetOutput( 2 )
84 // -------------------------------------------------------------------------
85 template< class I, class O, class C >
86 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
87 GraftChannel1( O* hue )
89 this->GraftNthOutput( 0, hue );
92 // -------------------------------------------------------------------------
93 template< class I, class O, class C >
94 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
95 GraftChannel2( O* saturation )
97 this->GraftNthOutput( 1, saturation );
100 // -------------------------------------------------------------------------
101 template< class I, class O, class C >
102 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
103 GraftChannel3( O* value )
105 this->GraftNthOutput( 2, value );
108 // -------------------------------------------------------------------------
109 template< class I, class O, class C >
110 cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
111 RGBImageToOtherChannelsFilter( )
114 this->SetNumberOfRequiredInputs( 1 );
115 this->SetNumberOfRequiredOutputs( 3 );
116 for( unsigned int i = 0; i < 3; i++ )
118 typename O::Pointer o = O::New( );
119 this->SetNthOutput( i, o );
124 // -------------------------------------------------------------------------
125 template< class I, class O, class C >
126 cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
127 ~RGBImageToOtherChannelsFilter( )
131 // -------------------------------------------------------------------------
132 template< class I, class O, class C >
133 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
134 BeforeThreadedGenerateData( )
138 // -------------------------------------------------------------------------
139 template< class I, class O, class C >
140 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
141 AfterThreadedGenerateData( )
145 // -------------------------------------------------------------------------
146 template< class I, class O, class C >
147 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
148 ThreadedGenerateData(
149 const typename Superclass::OutputImageRegionType& region,
150 itk::ThreadIdType threadId
153 // typedef typename TInputPixel::ComponentType _TComponent;
154 typedef itk::ImageRegionConstIterator< I > _TInIt;
155 typedef itk::ImageRegionIterator< O > _TOutIt;
156 typedef typename C::TOutPixel _TOutPixel;
158 _TInIt inIt( this->GetInput( ), region );
159 _TOutIt hIt( this->GetChannel1( ), region );
160 _TOutIt sIt( this->GetChannel2( ), region );
161 _TOutIt vIt( this->GetChannel3( ), region );
166 for( ; !inIt.IsAtEnd( ); ++inIt, ++hIt, ++sIt, ++vIt )
168 _TOutPixel other = this->Converter( inIt.Get( ) );
169 hIt.Set( other[ 0 ] );
170 sIt.Set( other[ 1 ] );
171 vIt.Set( other[ 2 ] );
176 #endif // __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__