]> Creatis software - clitk.git/commitdiff
Added png support with window/level options to clitkSplitImage
authorsrit <srit>
Mon, 12 Jul 2010 17:39:16 +0000 (17:39 +0000)
committersrit <srit>
Mon, 12 Jul 2010 17:39:16 +0000 (17:39 +0000)
filters/clitkSplitImageGenericFilter.cxx
filters/clitkSplitImageGenericFilter.h
tools/clitkSplitImage.cxx
tools/clitkSplitImage.ggo

index 2b9502495bba3ab841326977dc62950c34f6165d..433fb93e69ca5258090e0d0e92eecec56d97f783 100644 (file)
@@ -25,8 +25,8 @@
  -------------------------------------------------------------------*/
 
 #include "clitkSplitImageGenericFilter.h"
-
 #include "clitkSplitImageGenericFilter.txx"
+#include <itkIntensityWindowingImageFilter.h>
 //--------------------------------------------------------------------
 clitk::SplitImageGenericFilter::SplitImageGenericFilter():
   clitk::ImageToImageGenericFilter<Self>("SplitImage")
@@ -43,7 +43,7 @@ template<unsigned int Dim>
 void clitk::SplitImageGenericFilter::InitializeImageType()
 {
   ADD_DEFAULT_IMAGE_TYPES(Dim);
-  ADD_VEC_IMAGE_TYPE(Dim, 3,float);
+  //ADD_VEC_IMAGE_TYPE(Dim, 3,float);
 }
 //--------------------------------------------------------------------
 
@@ -72,14 +72,24 @@ void clitk::SplitImageGenericFilter::UpdateWithInputImageType()
   unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension];
   for (unsigned int i=0; i<number_of_output_images; i++) {
     std::ostringstream ss;
-    ss << i;
+    ss << std::setfill('0') << std::setw((int)(log10(number_of_output_images)+1)) << i;
     index[mSplitDimension]=i;
     extracted_region.SetIndex(index);
     filter->SetExtractionRegion(extracted_region);
     filter->Update();
-    SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
-    typename OutputImageType::Pointer output=filter->GetOutput();
-    SetNextOutput<OutputImageType>(output);
+    if(this->m_Png){
+      typedef itk::Image< unsigned char, ImageType::ImageDimension-1 > OutputPngImageType;
+      typedef itk::IntensityWindowingImageFilter< OutputImageType, OutputPngImageType > CastFilterType;
+      typename CastFilterType::Pointer cast = CastFilterType::New();
+      cast->SetWindowLevel(this->m_Window, this->m_Level);
+      cast->SetInput(filter->GetOutput());
+      SetOutputFilename(base_filename+"_"+ss.str()+".png");
+      SetNextOutput<OutputPngImageType>(cast->GetOutput());
+    }
+    else {
+      SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
+      SetNextOutput<OutputImageType>(filter->GetOutput());
+    }
   }
 }
 //--------------------------------------------------------------------
index e72eba1521e7327954964b04a06952e900aeef00..a32530133e4751301125040566347247e8f11bfc 100644 (file)
@@ -57,6 +57,8 @@ namespace clitk {
     // Set methods
     void SetSplitDimension (int dim) { mSplitDimension = dim; }
     void SetVerbose (const bool v) { m_Verbose = v; }
+    void SetPng (const bool v) { m_Png = v; }
+    void SetWindowLevel(const double w, const double l){ m_Window = w; m_Level = l;}
 
    //--------------------------------------------------------------------
     // Main function called each time the filter is updated
@@ -67,6 +69,8 @@ namespace clitk {
     template<unsigned int Dim> void InitializeImageType();
     int  mSplitDimension;
     bool m_Verbose;
+    bool m_Png;
+    double m_Window, m_Level;
 
   }; // end class SplitImageGenericFilter
 //--------------------------------------------------------------------
index a76f88c23dea824288a5d9c5caf653de583acabf..4b52cee87836f69cd4ffe01c2f9bd9ffada5b9d9 100644 (file)
@@ -53,6 +53,8 @@ int main(int argc, char * argv[])
   filter.SetInputFilename(args_info.input_arg);
   filter.SetOutputFilename(args_info.output_arg);
   filter.SetSplitDimension(args_info.dimension_arg);
+  filter.SetPng(args_info.png_flag);
+  filter.SetWindowLevel(args_info.window_arg, args_info.level_arg);
   filter.SetVerbose(args_info.verbose_flag);
   filter.Update();
 
index b68eddf1123189a19810e539d16a1ddf003b1dde..e9b4b3f9823ab722db49fe3ec207cf121e371018 100644 (file)
@@ -10,3 +10,6 @@ option "output"    o  "Output image base filename"      string   yes
 option "verbose"   v   "Verbose"                 flag     off
 
 option "dimension"     d       "Dimension to split on"  int yes
+option "png"       p   "Png file format"                 flag     off
+option "window"    w  "Window" double no
+option "level"     l  "Level"  double no