]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.cxx
92b8ac5e094cecf404a59b8ab8a66c734434aa0f
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / RGBImageToOtherChannelsFilter.cxx
1 #include "RGBImageToOtherChannelsFilter.h"
2 #include <cpPlugins/Interface/Image.h>
3
4 #include <cpExtensions/Algorithms/RGBImageToOtherChannelsFilter.h>
5 #include <cpExtensions/Algorithms/RGBExtractFunction.h>
6 #include <cpExtensions/Algorithms/RGBToHSVFunction.h>
7 #include <cpExtensions/Algorithms/RGBToYPbPrFunction.h>
8
9 // -------------------------------------------------------------------------
10 cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
11 RGBImageToOtherChannelsFilter( )
12   : Superclass( )
13 {
14   this->_AddInput( "Input" );
15   this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
16
17   std::vector< std::string > choices;
18   choices.push_back( "HSV" );
19   choices.push_back( "YPbPr" );
20   this->m_Parameters->ConfigureAsChoices( "OutChannel", choices );
21 }
22
23 // -------------------------------------------------------------------------
24 cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
25 ~RGBImageToOtherChannelsFilter( )
26 {
27 }
28
29 // -------------------------------------------------------------------------
30 std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
31 _GenerateData( )
32 {
33   auto image = this->GetInputData( "Input" );
34   itk::DataObject* itk_image = NULL;
35   std::string r = "";
36   cpPlugins_Image_Demangle_AllRGBTypes( 2, image, itk_image, r, _GD0 );
37   else cpPlugins_Image_Demangle_AllRGBTypes( 3, image, itk_image, r, _GD0 );
38   else cpPlugins_Image_Demangle_AllRGBTypes( 4, image, itk_image, r, _GD0 );
39   else r = "RGBImageToOtherChannelsFilter: Input image type not supported.";
40   return( r );
41 }
42
43 // -------------------------------------------------------------------------
44 template< class I >
45 std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
46 _GD0( itk::DataObject* image )
47 {
48   typedef typename I::PixelType _P;
49
50   std::string outc = this->m_Parameters->GetSelectedChoice( "OutChannel" );
51   std::string r = "";
52
53   using namespace cpExtensions::Algorithms;
54   if( outc == "HSV" )
55     r = this->_RealGD< I, RGBToHSVFunction< _P > >( image );
56   else if( outc == "YPbPr" )
57     r = this->_RealGD< I, RGBToYPbPrFunction< _P > >( image );
58   else if( outc == "Copy" )
59     r = this->_RealGD< I, RGBExtractFunction< _P > >( image );
60   else
61     r =
62       std::string( "RGBImageToOtherChannelsFilter: Conversor not available: " ) +
63       outc;
64   return( r );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class I, class C >
69 std::string cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter::
70 _RealGD( itk::DataObject* image )
71 {
72   typedef itk::Image< itk::RGBPixel< double >, I::ImageDimension > _O;
73   typedef
74     cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, _O, C >
75     _F;
76
77   // Configure filter
78   _F* filter = this->_CreateITK< _F >( );
79   filter->SetInput( dynamic_cast< I* >( image ) );
80   filter->Update( );
81
82   // Connect output
83   auto out = this->GetOutputData( "Output" );
84   out->SetITK( filter->GetOutput( ) );
85   return( "" );
86 }
87
88 // eof - $RCSfile$