itkBRAINSROIAutoImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Program:   Insight Segmentation & Registration Toolkit
00004  *  Module:    $RCSfile: itkBRAINSROIAutoImageFilter.h,v $
00005  *  Language:  C++
00006  *  Date:      $Date: 2008-10-16 19:33:40 $
00007  *  Version:   $Revision: 1.7 $
00008  *
00009  *  Copyright (c) Insight Software Consortium. All rights reserved.
00010  *  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011  *
00012  *  This software is distributed WITHOUT ANY WARRANTY; without even
00013  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014  *  PURPOSE.  See the above copyright notices for more information.
00015  *
00016  *  =========================================================================*/
00017 #ifndef __itkBRAINSROIAutoImageFilter_h
00018 #define __itkBRAINSROIAutoImageFilter_h
00019 
00020 // First make sure that the configuration is available.
00021 // This line can be removed once the optimized versions
00022 // gets integrated into the main directories.
00023 #include "itkConfigure.h"
00024 #include "itkImageToImageFilter.h"
00025 #include "itkImage.h"
00026 
00027 #include "itkImageMaskSpatialObject.h"
00028 #include "itkLargestForegroundFilledMaskImageFilter.h"
00029 #include "itkCastImageFilter.h"
00030 
00031 typedef itk::SpatialObject< 3 >    SpatialObjectType;
00032 typedef SpatialObjectType::Pointer ImageMaskPointer;
00033 
00034 namespace itk
00035 {
00045 template< class TInputImage, class TOutputImage >
00046 class ITK_EXPORT BRAINSROIAutoImageFilter:
00047   public ImageToImageFilter< TInputImage, TOutputImage >
00048 {
00049 public:
00051   itkStaticConstMacro(InputImageDimension, unsigned int,
00052                       TInputImage::ImageDimension);
00053   itkStaticConstMacro(OutputImageDimension, unsigned int,
00054                       TOutputImage::ImageDimension);
00055 
00057   typedef TInputImage  InputImageType;
00058   typedef TOutputImage OutputImageType;
00059 
00061   typedef BRAINSROIAutoImageFilter                              Self;
00062   typedef ImageToImageFilter< InputImageType, OutputImageType > Superclass;
00063   typedef SmartPointer< Self >                                  Pointer;
00064   typedef SmartPointer< const Self >                            ConstPointer;
00065 
00067   itkNewMacro(Self);
00068 
00070   itkTypeMacro(BRAINSROIAutoImageFilter, ImageToImageFilter);
00071 
00073   typedef typename InputImageType::PixelType  InputPixelType;
00074   typedef typename OutputImageType::PixelType OutputPixelType;
00075 
00076   typedef typename InputImageType::RegionType  InputImageRegionType;
00077   typedef typename OutputImageType::RegionType OutputImageRegionType;
00078 
00079   typedef typename InputImageType::SizeType InputSizeType;
00080 
00081   typedef itk::Image< unsigned char, 3 >                            UCHARIMAGE;
00082   typedef itk::ImageMaskSpatialObject< UCHARIMAGE::ImageDimension > ImageMaskSpatialObjectType;
00083 
00085   itkSetMacro(OtsuPercentileThreshold, double);
00086   itkGetConstMacro(OtsuPercentileThreshold, double);
00088   itkSetMacro(ThresholdCorrectionFactor, double);
00089   itkGetConstMacro(ThresholdCorrectionFactor, double);
00092   itkSetMacro(ClosingSize, double);
00093   itkGetConstMacro(ClosingSize, double);
00096   itkSetMacro(DilateSize, double);
00097   itkGetConstMacro(DilateSize, double);
00098 
00099   // NOTE:  This will generate a new spatial object each time it is called, and
00100   // not return the previous spatial object
00101   ImageMaskPointer GetSpatialObjectROI(void)
00102   {
00103     if ( m_ResultMaskPointer.IsNull() ) // This is a cheap way to only create
00104                                         // the mask once, note that this is made
00105                                         // null when GenerateData is called.
00106       {
00107       typedef itk::CastImageFilter< OutputImageType, UCHARIMAGE > CastImageFilter;
00108       typename CastImageFilter::Pointer castFilter = CastImageFilter::New();
00109       castFilter->SetInput( this->GetOutput() );
00110       castFilter->Update();
00111 
00112       // convert mask image to mask
00113       typename ImageMaskSpatialObjectType::Pointer mask = ImageMaskSpatialObjectType::New();
00114       mask->SetImage( castFilter->GetOutput() );
00115       mask->ComputeObjectToWorldTransform();
00116       m_ResultMaskPointer = dynamic_cast< ImageMaskSpatialObjectType * >( mask.GetPointer() );
00117       }
00118     return m_ResultMaskPointer;
00119   }
00120   typename UCHARIMAGE::ConstPointer GetBinaryImageROI()
00121   {
00122     ImageMaskPointer tmp = this->GetSpatialObjectROI();
00123     typename UCHARIMAGE::ConstPointer rval;
00124     if(tmp.IsNotNull())
00125       {
00126       typename itk::ImageMaskSpatialObject<3>::Pointer imso =
00127         dynamic_cast<itk::ImageMaskSpatialObject<3> *>
00128         (tmp.GetPointer());
00129       if(imso.IsNotNull())
00130         {
00131         rval = imso->GetImage();
00132         }
00133       }
00134     return rval;
00135   }
00136 #ifdef ITK_USE_CONCEPT_CHECKING
00137 
00138   itkConceptMacro( SameDimensionCheck,
00139                    ( Concept::SameDimension< InputImageDimension, OutputImageDimension > ) );
00141 #endif
00142 protected:
00143   BRAINSROIAutoImageFilter();
00144   virtual ~BRAINSROIAutoImageFilter() {}
00145   void PrintSelf(std::ostream & os, Indent indent) const;
00146 
00147   void GenerateData();
00148 
00149 private:
00150   BRAINSROIAutoImageFilter(const Self &); // purposely not implemented
00151   void operator=(const Self &);           // purposely not implemented
00152 
00153   double           m_OtsuPercentileThreshold;
00154   double           m_ThresholdCorrectionFactor;
00155   double           m_ClosingSize;
00156   double           m_DilateSize;
00157   ImageMaskPointer m_ResultMaskPointer;
00158 };
00159 } // end namespace itk
00160 
00161 #ifndef ITK_MANUAL_INSTANTIATION
00162 #  include "itkBRAINSROIAutoImageFilter.txx"
00163 #endif
00164 
00165 #endif

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1