diff --git a/Code/BasicFilters/otbConvolutionImageFilter.txx b/Code/BasicFilters/otbConvolutionImageFilter.txx index 94b9db348b9e67b74cf0875ef414a6c1601a6cb8..722cd0ba772988afe7b8b9a79b00fa7afe625b40 100644 --- a/Code/BasicFilters/otbConvolutionImageFilter.txx +++ b/Code/BasicFilters/otbConvolutionImageFilter.txx @@ -27,6 +27,8 @@ #include "itkProgressReporter.h" #include "itkConstantBoundaryCondition.h" +#include "otbMacro.h" + namespace otb { diff --git a/Code/Common/otbVectorDataToLabelMapFilter.txx b/Code/Common/otbVectorDataToLabelMapFilter.txx index 5754014cc2375dcf63d766017dccc37b55093205..f5ca114a082b9e71a54b2b04b8feb1ae8e9c3bcd 100644 --- a/Code/Common/otbVectorDataToLabelMapFilter.txx +++ b/Code/Common/otbVectorDataToLabelMapFilter.txx @@ -312,10 +312,10 @@ VectorDataToLabelMapFilter< TVectorData, TLabelMap > std::cout << "spacing " << this->GetOutput()->GetSpacing()<< std::endl; // For each position in the bounding region of the polygon - for (unsigned int i = polygonExtRingBoundReg.GetOrigin(0);i < polygonExtRingBoundReg.GetOrigin(0) + polygonExtRingBoundReg.GetSize(0) ;i+=this->GetOutput()->GetSpacing()[0]) + for (double i = polygonExtRingBoundReg.GetOrigin(0);i < polygonExtRingBoundReg.GetOrigin(0) + polygonExtRingBoundReg.GetSize(0) ;i+=this->GetOutput()->GetSpacing()[0]) { vertex[0] = static_cast<VertexValueType>(i) ; - for (unsigned int j = polygonExtRingBoundReg.GetOrigin(1);j<polygonExtRingBoundReg.GetOrigin(1) + polygonExtRingBoundReg.GetSize(1) ;j+=this->GetOutput()->GetSpacing()[1]) + for (double j = polygonExtRingBoundReg.GetOrigin(1);j<polygonExtRingBoundReg.GetOrigin(1) + polygonExtRingBoundReg.GetSize(1) ;j+=this->GetOutput()->GetSpacing()[1]) { vertex[1] = static_cast<VertexValueType>(j) ; diff --git a/Code/Radiometry/otbRadarFunctors.txx b/Code/Radiometry/otbRadarFunctors.txx index 46fcf2bea0972cfbd1956dc2a499ac1e6abdd11a..f1268e7ab2e0acf6af0876359050b6403f770482 100644 --- a/Code/Radiometry/otbRadarFunctors.txx +++ b/Code/Radiometry/otbRadarFunctors.txx @@ -45,7 +45,7 @@ TerraSarCalibrationImageFunctor<TInput, TOutput> m_PRF = 1.; } - + template <class TInput, class TOutput> double TerraSarCalibrationImageFunctor<TInput, TOutput> @@ -63,11 +63,11 @@ TerraSarCalibrationImageFunctor<TInput, TOutput> { curRange = m_NoiseRangeValidityRef + ( m_NoiseRangeValidityMax-m_NoiseRangeValidityRef )/width_2 * (static_cast<double>(colId+1) - width_2 ); } - + return curRange; } - + template <class TInput, class TOutput> typename TerraSarCalibrationImageFunctor<TInput, TOutput>::DoubleVectorType TerraSarCalibrationImageFunctor<TInput, TOutput> @@ -75,7 +75,7 @@ TerraSarCalibrationImageFunctor<TInput, TOutput> { DoubleVectorType curCoeffs; if(m_UseFastCalibrationMethod) - { + { curCoeffs = m_NoisePolynomialCoefficientsList[0]; } else @@ -89,7 +89,7 @@ TerraSarCalibrationImageFunctor<TInput, TOutput> bool go = true; // deduct the corresponding noise acquisition index while( id<m_TimeUTC.size() && go) - { + { if( currTimeUTC < m_TimeUTC[id] ) go = false; id++; @@ -114,19 +114,19 @@ TerraSarCalibrationImageFunctor<TInput, TOutput> { double diffCurRange = ComputeCurrentNoise( static_cast<unsigned int>(index[0]) ) - m_NoiseRangeValidityRef; DoubleVectorType curCoeff = ComputeCurrentCoeffs( static_cast<unsigned int>(index[1]) ); - + TOutput outRadBr = m_RadarBrightness( inPix ); double NEBN = 0.; - for(int i=0; i<curCoeff.size(); i++) + for(unsigned int i=0; i<curCoeff.size(); i++) { NEBN += curCoeff[i]*vcl_pow( diffCurRange, i); } double sigma = ( outRadBr - m_CalFactor*NEBN ) * m_SinLocalIncidentAngle; - + return static_cast<TOutput>(sigma); } - + /** Constructor */ template <class TInput, class TOutput> @@ -145,7 +145,7 @@ TerraSarCalibrationComplexImageFunctor<TInput, TOutput> m_PRF = 1.; } - + template <class TInput, class TOutput> double TerraSarCalibrationComplexImageFunctor<TInput, TOutput> @@ -163,11 +163,11 @@ TerraSarCalibrationComplexImageFunctor<TInput, TOutput> { curRange = m_NoiseRangeValidityRef + ( m_NoiseRangeValidityMax-m_NoiseRangeValidityRef )/width_2 * (static_cast<double>(colId+1) - width_2 ); } - + return curRange; } - + template <class TInput, class TOutput> typename TerraSarCalibrationComplexImageFunctor<TInput, TOutput>::DoubleVectorType TerraSarCalibrationComplexImageFunctor<TInput, TOutput> @@ -175,7 +175,7 @@ TerraSarCalibrationComplexImageFunctor<TInput, TOutput> { DoubleVectorType curCoeffs; if(m_UseFastCalibrationMethod) - { + { curCoeffs = m_NoisePolynomialCoefficientsList[0]; } else @@ -189,7 +189,7 @@ TerraSarCalibrationComplexImageFunctor<TInput, TOutput> bool go = true; // deduct the corresponding noise acquisition index while( id<m_TimeUTC.size() && go) - { + { if( currTimeUTC < m_TimeUTC[id] ) go = false; id++; @@ -214,7 +214,7 @@ TerraSarCalibrationComplexImageFunctor<TInput, TOutput> { double diffCurRange = this->ComputeCurrentNoise( static_cast<unsigned int>(index[0]) ) - this->GetNoiseRangeValidityRef(); DoubleVectorType curCoeff = this->ComputeCurrentCoeffs( static_cast<unsigned int>(index[1]) ); - + double modulus = std::abs(inPix); double outRadBr = static_cast<double>(m_RadarBrightness( modulus )); @@ -224,15 +224,15 @@ TerraSarCalibrationComplexImageFunctor<TInput, TOutput> NEBN += curCoeff[i]*vcl_pow( diffCurRange, i); } double sigma = ( outRadBr - this->GetCalFactor()*NEBN ) * this->GetSinLocalIncidentAngle(); - + double phase = std::arg(inPix); TOutput out(sigma*vcl_cos(phase), sigma*vcl_sin(phase)); return out; } - + }// namespace Functor - + } // namespace otb #endif diff --git a/Code/Visualization/otbImageWidgetController.cxx b/Code/Visualization/otbImageWidgetController.cxx index 5f4e84557804b58d67ecd2a8d32d14890fe80199..259b422b72b89f997c7e7f08199ec2008c8476ee 100644 --- a/Code/Visualization/otbImageWidgetController.cxx +++ b/Code/Visualization/otbImageWidgetController.cxx @@ -82,7 +82,7 @@ void ImageWidgetController::HandleWidgetResize(std::string widgetId, int w, int { // Define an iterator on the action handlers list ActionHandlerListType::Iterator it = m_ActionHandlersList->Begin(); - + // The action handler found ActionHandlerType * handler; @@ -93,7 +93,7 @@ void ImageWidgetController::HandleWidgetResize(std::string widgetId, int w, int // try to handle the event with the current handler handler->HandleWidgetResize(widgetId,w,h); ++it; - } + } } void ImageWidgetController::HandleWidgetMove(std::string widgetId, int x, int y) @@ -101,7 +101,7 @@ void ImageWidgetController::HandleWidgetMove(std::string widgetId, int x, int y) otbMsgDevMacro(<<"ImageWidgetController::HandleWidgetMove(): ("<<widgetId<<", "<<x<<", "<<y<<")"); // Define an iterator on the action handlers list ActionHandlerListType::Iterator it = m_ActionHandlersList->Begin(); - + // The action handler found ActionHandlerType * handler; @@ -118,10 +118,10 @@ void ImageWidgetController::HandleWidgetMove(std::string widgetId, int x, int y) void ImageWidgetController::ActivateActionHandlers() { - otbMsgDevMacro(<<"ImageWidgetController::DectivateActionHandler(): ("<<widgetId<<")"); +// otbMsgDevMacro(<<"ImageWidgetController::DectivateActionHandler(): ("<<widgetId<<")"); // Define an iterator on the action handlers list ActionHandlerListType::Iterator it = m_ActionHandlersList->Begin(); - + // The action handler found ActionHandlerType * handler; @@ -137,10 +137,10 @@ void ImageWidgetController::ActivateActionHandlers() void ImageWidgetController::DeactivateActionHandlers() { - otbMsgDevMacro(<<"ImageWidgetController::DectivateActionHandler(): ("<<widgetId<<")"); +// otbMsgDevMacro(<<"ImageWidgetController::DectivateActionHandler(): ("<<widgetId<<")"); // Define an iterator on the action handlers list ActionHandlerListType::Iterator it = m_ActionHandlersList->Begin(); - + // The action handler found ActionHandlerType * handler; diff --git a/Examples/OBIA/ImageToLabelToImage.cxx b/Examples/OBIA/ImageToLabelToImage.cxx index 97144bf626c3f2df34977e39d476070728aa9959..db4fa2eaa327ae8f6e99a916b900ac6f4447f966 100644 --- a/Examples/OBIA/ImageToLabelToImage.cxx +++ b/Examples/OBIA/ImageToLabelToImage.cxx @@ -57,22 +57,22 @@ int main(int argc, char * argv[]) const int dim = 2; typedef unsigned short PixelType; - + typedef otb::Image< PixelType, dim > ImageType; typedef itk::LabelObject< PixelType, dim > LabelObjectType; typedef itk::LabelMap< LabelObjectType > LabelMapType; - + typedef itk::ImageFileReader< ImageType > ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName( argv[1] ); - + typedef itk::BinaryImageToLabelMapFilter< ImageType, LabelMapType> I2LType; I2LType::Pointer i2l = I2LType::New(); i2l->SetInput( reader->GetOutput() ); i2l->SetFullyConnected( atoi(argv[5]) ); - i2l->SetForegroundValue( atoi(argv[6]) ); - i2l->SetBackgroundValue( atoi(argv[7]) ); + i2l->SetInputForegroundValue( atoi(argv[6]) ); + i2l->SetOutputBackgroundValue( atoi(argv[7]) ); typedef itk::LabelMapToLabelImageFilter< LabelMapType, ImageType> L2IType; L2IType::Pointer l2i = L2IType::New(); diff --git a/Utilities/ITK/Code/Review/itkBinaryImageToLabelMapFilter.h b/Utilities/ITK/Code/Review/itkBinaryImageToLabelMapFilter.h index 8835e6d8cf208bbc81923c9248a67ca31e21010f..be772383adf95d1538e1e05b05938fbe5120e620 100644 --- a/Utilities/ITK/Code/Review/itkBinaryImageToLabelMapFilter.h +++ b/Utilities/ITK/Code/Review/itkBinaryImageToLabelMapFilter.h @@ -26,6 +26,9 @@ #include "itkProgressReporter.h" #include "itkBarrier.h" +//PATCH OTB +#include "itkLabelMap.h" + namespace itk { diff --git a/Utilities/InsightJournal/itkAutoCropLabelMapFilter.h b/Utilities/InsightJournal/itkAutoCropLabelMapFilter.h deleted file mode 100644 index c7ff8acba30e8488ea3e306d565cb87402c68ae8..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkAutoCropLabelMapFilter.h +++ /dev/null @@ -1,114 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkAutoCropLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:38 $ - Version: $Revision: 1.4 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkAutoCropLabelMapFilter_h -#define __itkAutoCropLabelMapFilter_h - -#include "itkChangeRegionLabelMapFilter.h" - -namespace itk -{ - -/** \class AutoCropLabelMapFilter - * \brief Crop a LabelMap image to fit exactly the objects in the LabelMap - * - * The CropBorder can be used to add a border which will never be larger than - * the input image. To add a border of size independant of the input image, - * PadLabelMapFilter can be used. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa PadLabelMapFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template <class TInputImage> -class ITK_EXPORT AutoCropLabelMapFilter : public ChangeRegionLabelMapFilter<TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef AutoCropLabelMapFilter Self; - typedef ChangeRegionLabelMapFilter<TInputImage> Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - - /** Run-time type information (and related methods). */ - itkTypeMacro(AutoCropLabelMapFilter, ChangeRegionImageFilter); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Superclass typedefs. */ - typedef typename Superclass::OutputImageType OutputImageType; - typedef typename Superclass::OutputImagePointer OutputImagePointer; - typedef typename Superclass::OutputImageRegionType OutputImageRegionType; - typedef typename Superclass::OutputImagePixelType OutputImagePixelType; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typedef typename InputImageType::PixelType PixelType; - typedef typename InputImageType::IndexType IndexType; - typedef typename InputImageType::SizeType SizeType; - typedef typename InputImageType::RegionType RegionType; - - typedef TInputImage TOutputImage; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TOutputImage::ImageDimension); - - - /** - * Set/Get the boder added to the mask before the crop. The default is 0 on - * all the axes. - */ - itkSetMacro(CropBorder, SizeType); - itkGetConstReferenceMacro(CropBorder, SizeType); - - protected: - AutoCropLabelMapFilter(); - ~AutoCropLabelMapFilter() {}; - - virtual void GenerateOutputInformation(); - -private: - AutoCropLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - SizeType m_CropBorder; - TimeStamp m_CropTimeStamp; - -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkAutoCropLabelMapFilter.txx" -#endif - -#endif diff --git a/Utilities/InsightJournal/itkAutoCropLabelMapFilter.txx b/Utilities/InsightJournal/itkAutoCropLabelMapFilter.txx deleted file mode 100644 index eec12a54ba96d226ddff561c87848e81f8f60489..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkAutoCropLabelMapFilter.txx +++ /dev/null @@ -1,136 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkAutoCropLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:39 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef _itkAutoCropLabelMapFilter_txx -#define _itkAutoCropLabelMapFilter_txx -#include "itkAutoCropLabelMapFilter.h" - - -namespace itk -{ - -template <class TInputImage> -AutoCropLabelMapFilter<TInputImage> -::AutoCropLabelMapFilter() -{ - m_CropBorder.Fill( 0 ); -} - - -template <class TInputImage> -void -AutoCropLabelMapFilter<TInputImage> -::GenerateOutputInformation() -{ - - const InputImageType * input = this->GetInput(); - - if( !(input->GetMTime() > m_CropTimeStamp) && !(this->GetMTime() > m_CropTimeStamp) ) - { - // early exit, crop sizes already computed - // std::cout << "Don't recompute the output size again." << std::endl; - // std::cout << "LargestPossibleRegion: " << this->GetOutput()->GetLargestPossibleRegion() << std::endl; - // std::cout << "BufferedRegion: " << this->GetOutput()->GetBufferedRegion() << std::endl; - // std::cout << "RequestedRegion: " << this->GetOutput()->GetRequestedRegion() << std::endl; - return; - } - - // update the input if needed - if( input->GetSource() ) - { - ProcessObject * upstream = input->GetSource(); - if (upstream) - { - // this->SetInput(NULL); - // std::cout << "Update the input (again?)." << std::endl; - upstream->Update(); - // this->SetInput(input); - } - } - - // Prefetch image region and size - InputImageRegionType cropRegion = input->GetLargestPossibleRegion(); - - // just find the bounding box of the objects - IndexType mins; - mins.Fill( NumericTraits< long >::max() ); - IndexType maxs; - maxs.Fill( NumericTraits< long >::NonpositiveMin() ); - // iterate over all the lines - typename InputImageType::LabelObjectContainerType container = this->GetInput()->GetLabelObjectContainer(); - for( typename InputImageType::LabelObjectContainerType::const_iterator loit = container.begin(); - loit != container.end(); - loit++ ) - { - const LabelObjectType * labelObject = loit->second; - typename LabelObjectType::LineContainerType::const_iterator lit; - const typename LabelObjectType::LineContainerType & lineContainer = labelObject->GetLineContainer(); - for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ ) - { - const IndexType & idx = lit->GetIndex(); - unsigned long length = lit->GetLength(); - - // update the mins and maxs - for( int i=0; i<ImageDimension; i++) - { - if( idx[i] < mins[i] ) - { - mins[i] = idx[i]; - } - if( idx[i] > maxs[i] ) - { - maxs[i] = idx[i]; - } - } - // must fix the max for the axis 0 - if( idx[0] + (long)length > maxs[0] ) - { - maxs[0] = idx[0] + length - 1; - } - } - } - // final computation - SizeType regionSize; - for( int i=0; i<ImageDimension; i++ ) - { - regionSize[i] = maxs[i] - mins[i] + 1; - } - cropRegion.SetIndex( mins ); - cropRegion.SetSize( regionSize ); - - // pad by the crop border, but take care to not be larger than the largest - // possible region of the input image - cropRegion.PadByRadius( m_CropBorder ); - cropRegion.Crop( input->GetLargestPossibleRegion() ); - - // finally set that region as the largest output region - this->SetRegion(cropRegion); - m_CropTimeStamp.Modified(); - - Superclass::GenerateOutputInformation(); - - // std::cout << "LargestPossibleRegion: " << this->GetOutput()->GetLargestPossibleRegion() << std::endl; - // std::cout << "BufferedRegion: " << this->GetOutput()->GetBufferedRegion() << std::endl; - // std::cout << "RequestedRegion: " << this->GetOutput()->GetRequestedRegion() << std::endl; -} - - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkBinaryImageToLabelMapFilter.h b/Utilities/InsightJournal/itkBinaryImageToLabelMapFilter.h deleted file mode 100644 index f236770f27138c3f1f70c8d96417fc61bc605d6d..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkBinaryImageToLabelMapFilter.h +++ /dev/null @@ -1,256 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkBinaryImageToLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2007/02/18 20:03:03 $ - Version: $Revision: 1.16 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ - -#ifndef __itkBinaryImageToLabelMapFilter_h -#define __itkBinaryImageToLabelMapFilter_h - -#include "itkLabelMap.h" -#include "itkLabelObject.h" -#include "itkImageToImageFilter.h" -#include "itkImage.h" -#include "itkConceptChecking.h" -#include <vector> -#include <map> -#include "itkProgressReporter.h" -#include "itkBarrier.h" - -namespace itk -{ - -/** - * \class BinaryImageToLabelMapFilter - * \brief Label the connected components in a binary image and produce a collection of label objects - * - * BinaryImageToLabelMapFilter labels the objects in a binary image. - * Each distinct object is assigned a unique label. - * The final object labels start with 1 and are consecutive. Objects - * that are reached earlier by a raster order scan have a lower - * label. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ConnectedComponentImageFilter, LabelImageToLabelMapFilter, LabelMap - */ - -template <class TInputImage, class TOutputImage=LabelMap< LabelObject< unsigned long, TInputImage::ImageDimension > > > -class ITK_EXPORT BinaryImageToLabelMapFilter : - public ImageToImageFilter< TInputImage, TOutputImage > -{ -public: - /** - * Standard "Self" & Superclass typedef. - */ - typedef BinaryImageToLabelMapFilter Self; - typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass; - - /** - * Types from the Superclass - */ - typedef typename Superclass::InputImagePointer InputImagePointer; - - /** - * Extract some information from the image types. Dimensionality - * of the two images is assumed to be the same. - */ - typedef typename TOutputImage::PixelType OutputPixelType; - typedef typename TInputImage::PixelType InputPixelType; - itkStaticConstMacro(ImageDimension, unsigned int, - TOutputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - - /** - * Image typedef support - */ - typedef TInputImage InputImageType; - typedef typename TInputImage::IndexType IndexType; - typedef typename TInputImage::SizeType SizeType; - typedef typename TInputImage::OffsetType OffsetType; - - typedef TOutputImage OutputImageType; - typedef typename TOutputImage::RegionType RegionType; - typedef typename TOutputImage::IndexType OutputIndexType; - typedef typename TOutputImage::SizeType OutputSizeType; - typedef typename TOutputImage::OffsetType OutputOffsetType; - typedef typename TOutputImage::PixelType OutputImagePixelType; - - typedef std::list<IndexType> ListType; - - /** - * Smart pointer typedef support - */ - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** - * Run-time type information (and related methods) - */ - itkTypeMacro(BinaryImageToLabelMapFilter, ImageToImageFilter); - - /** - * Method for creation through the object factory. - */ - itkNewMacro(Self); - - /** - * Set/Get whether the connected components are defined strictly by - * face connectivity or by face+edge+vertex connectivity. Default is - * FullyConnectedOff. For objects that are 1 pixel wide, use - * FullyConnectedOn. - */ - itkSetMacro(FullyConnected, bool); - itkGetConstReferenceMacro(FullyConnected, bool); - itkBooleanMacro(FullyConnected); - - // only set after completion - itkGetConstReferenceMacro(ObjectCount, unsigned long); - - // Concept checking -- input and output dimensions must be the same - itkConceptMacro(SameDimension, - (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension), - itkGetStaticConstMacro(OutputImageDimension)>)); - - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputPixelType); - itkGetConstMacro(BackgroundValue, OutputPixelType); - - /** - * Set/Get the value used as "foreground" in the output image. - * Defaults to NumericTraits<PixelType>::max(). - */ - itkSetMacro(ForegroundValue, InputPixelType); - itkGetConstMacro(ForegroundValue, InputPixelType); - -protected: - BinaryImageToLabelMapFilter() - { - m_FullyConnected = false; - m_ObjectCount = 0; - m_BackgroundValue = NumericTraits<OutputPixelType>::NonpositiveMin(); - m_ForegroundValue = NumericTraits<InputPixelType>::max(); - } - virtual ~BinaryImageToLabelMapFilter() {} - void PrintSelf(std::ostream& os, Indent indent) const; - - /** - * Standard pipeline method. - */ - void BeforeThreadedGenerateData (); - void AfterThreadedGenerateData (); - void ThreadedGenerateData (const RegionType& outputRegionForThread, int threadId) ; - - /** BinaryImageToLabelMapFilter needs the entire input. Therefore - * it must provide an implementation GenerateInputRequestedRegion(). - * \sa ProcessObject::GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion(); - - /** BinaryImageToLabelMapFilter will produce all of the output. - * Therefore it must provide an implementation of - * EnlargeOutputRequestedRegion(). - * \sa ProcessObject::EnlargeOutputRequestedRegion() */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - bool m_FullyConnected; - -private: - BinaryImageToLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputPixelType m_BackgroundValue; - InputPixelType m_ForegroundValue; - - unsigned long m_ObjectCount; - // some additional types - typedef typename TOutputImage::RegionType::SizeType OutSizeType; - - // types to support the run length encoding of lines - class runLength - { - public: - // run length information - may be a more type safe way of doing this - long int length; - typename InputImageType::IndexType where; // Index of the start of the run - unsigned long int label; // the initial label of the run - }; - - typedef std::vector<runLength> lineEncoding; - - // the map storing lines - typedef std::vector<lineEncoding> LineMapType; - - typedef std::vector<long> OffsetVec; - - // the types to support union-find operations - typedef std::vector<unsigned long int> UnionFindType; - UnionFindType m_UnionFind; - UnionFindType m_Consecutive; - // functions to support union-find operations - void InitUnion(const unsigned long int size) - { - m_UnionFind = UnionFindType(size + 1); - } - void InsertSet(const unsigned long int label); - unsigned long int LookupSet(const unsigned long int label); - void LinkLabels(const unsigned long int lab1, const unsigned long int lab2); - unsigned long int CreateConsecutive(); - ////////////////// - bool CheckNeighbors(const OutputIndexType &A, - const OutputIndexType &B); - - void CompareLines(lineEncoding ¤t, const lineEncoding &Neighbour); - - void FillOutput(const LineMapType &LineMap, - ProgressReporter &progress); - - void SetupLineOffsets(OffsetVec &LineOffsets); - - void Wait() - { - long nbOfThreads = this->GetNumberOfThreads(); - if( itk::MultiThreader::GetGlobalMaximumNumberOfThreads() != 0 ) - { - nbOfThreads = std::min( this->GetNumberOfThreads(), itk::MultiThreader::GetGlobalMaximumNumberOfThreads() ); - } - if( nbOfThreads > 1 ) - { - m_Barrier->Wait(); - } - } - - typename std::vector< long > m_NumberOfLabels; - typename std::vector< long > m_FirstLineIdToJoin; - typename Barrier::Pointer m_Barrier; -#if !defined(CABLE_CONFIGURATION) - LineMapType m_LineMap; -#endif -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#if !defined(CABLE_CONFIGURATION) -#include "itkBinaryImageToLabelMapFilter.txx" -#endif -#endif - -#endif diff --git a/Utilities/InsightJournal/itkBinaryImageToLabelMapFilter.txx b/Utilities/InsightJournal/itkBinaryImageToLabelMapFilter.txx deleted file mode 100644 index dedc98013f773494014563d64e0a92ac39689cc0..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkBinaryImageToLabelMapFilter.txx +++ /dev/null @@ -1,615 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkBinaryImageToLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2007/02/20 15:28:29 $ - Version: $Revision: 1.21 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkBinaryImageToLabelMapFilter_txx -#define __itkBinaryImageToLabelMapFilter_txx - -#include "itkBinaryImageToLabelMapFilter.h" -#include "itkNumericTraits.h" - -// don't think we need the indexed version as we only compute the -// index at the start of each run, but there isn't a choice -#include "itkImageLinearConstIteratorWithIndex.h" -#include "itkConstShapedNeighborhoodIterator.h" -#include "itkImageRegionIterator.h" -#include "itkConnectedComponentAlgorithm.h" - -namespace itk -{ -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( !input ) - { - return; - } - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); -} - -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::BeforeThreadedGenerateData() -{ - typename TOutputImage::Pointer output = this->GetOutput(); - typename TInputImage::ConstPointer input = this->GetInput(); - - output->SetBackgroundValue( m_BackgroundValue ); - - long nbOfThreads = this->GetNumberOfThreads(); - if( itk::MultiThreader::GetGlobalMaximumNumberOfThreads() != 0 ) - { - nbOfThreads = std::min( this->GetNumberOfThreads(), itk::MultiThreader::GetGlobalMaximumNumberOfThreads() ); - } - // number of threads can be constrained by the region size, so call the SplitRequestedRegion - // to get the real number of threads which will be used - typename TOutputImage::RegionType splitRegion; // dummy region - just to call the following method - nbOfThreads = this->SplitRequestedRegion(0, nbOfThreads, splitRegion); - // std::cout << "nbOfThreads: " << nbOfThreads << std::endl; - - // set up the vars used in the threads - m_NumberOfLabels.clear(); - m_NumberOfLabels.resize( nbOfThreads, 0 ); - m_Barrier = Barrier::New(); - m_Barrier->Initialize( nbOfThreads ); - long pixelcount = output->GetRequestedRegion().GetNumberOfPixels(); - long xsize = output->GetRequestedRegion().GetSize()[0]; - long linecount = pixelcount/xsize; - m_LineMap.resize( linecount ); - m_FirstLineIdToJoin.resize( nbOfThreads - 1 ); -} - - -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::ThreadedGenerateData(const RegionType& outputRegionForThread, - int threadId) -{ - typename TOutputImage::Pointer output = this->GetOutput(); - typename TInputImage::ConstPointer input = this->GetInput(); - - long nbOfThreads = this->GetNumberOfThreads(); - if( itk::MultiThreader::GetGlobalMaximumNumberOfThreads() != 0 ) - { - nbOfThreads = std::min( this->GetNumberOfThreads(), itk::MultiThreader::GetGlobalMaximumNumberOfThreads() ); - } - - // create a line iterator - typedef itk::ImageLinearConstIteratorWithIndex<InputImageType> - InputLineIteratorType; - InputLineIteratorType inLineIt(input, outputRegionForThread); - inLineIt.SetDirection(0); - - // set the progress reporter to deal with the number of lines - long pixelcountForThread = outputRegionForThread.GetNumberOfPixels(); - long xsizeForThread = outputRegionForThread.GetSize()[0]; - long linecountForThread = pixelcountForThread/xsizeForThread; - ProgressReporter progress(this, threadId, linecountForThread); - - // find the split axis - IndexType outputRegionIdx = output->GetRequestedRegion().GetIndex(); - IndexType outputRegionForThreadIdx = outputRegionForThread.GetIndex(); - int splitAxis = 0; - for( int i=0; i<ImageDimension; i++ ) - { - if( outputRegionIdx[i] != outputRegionForThreadIdx[i] ) - { - splitAxis = i; - } - } - - // compute the number of pixels before that threads - SizeType outputRegionSize = output->GetRequestedRegion().GetSize(); - outputRegionSize[splitAxis] = outputRegionForThreadIdx[splitAxis] - outputRegionIdx[splitAxis]; - long firstLineIdForThread = RegionType( outputRegionIdx, outputRegionSize ).GetNumberOfPixels() / xsizeForThread; - long lineId = firstLineIdForThread; - - OffsetVec LineOffsets; - SetupLineOffsets(LineOffsets); - - long nbOfLabels = 0; - for( inLineIt.GoToBegin(); - !inLineIt.IsAtEnd(); - inLineIt.NextLine() ) - { - inLineIt.GoToBeginOfLine(); - lineEncoding ThisLine; - while (! inLineIt.IsAtEndOfLine()) - { - InputPixelType PVal = inLineIt.Get(); - //std::cout << inLineIt.GetIndex() << std::endl; - if (PVal == m_ForegroundValue) - { - // We've hit the start of a run - runLength thisRun; - long length=0; - IndexType thisIndex; - thisIndex = inLineIt.GetIndex(); - //std::cout << thisIndex << std::endl; - ++length; - ++inLineIt; - while( !inLineIt.IsAtEndOfLine() - && inLineIt.Get() == m_ForegroundValue ) - { - ++length; - ++inLineIt; - } - // create the run length object to go in the vector - thisRun.length=length; - thisRun.label=0; // will give a real label later - thisRun.where = thisIndex; - ThisLine.push_back(thisRun); - nbOfLabels++; - } - else - { - ++inLineIt; - } - } - m_LineMap[lineId] = ThisLine; - lineId++; - progress.CompletedPixel(); - } - - m_NumberOfLabels[threadId] = nbOfLabels; - - // wait for the other threads to complete that part - this->Wait(); - - // compute the total number of labels - nbOfLabels = 0; - for( int i=0; i<nbOfThreads; i++ ) - { - nbOfLabels += m_NumberOfLabels[i]; - } - - if( threadId == 0 ) - { - // set up the union find structure - InitUnion(nbOfLabels); - // insert all the labels into the structure -- an extra loop but - // saves complicating the ones that come later - typename LineMapType::iterator MapBegin, MapEnd, LineIt; - MapBegin = m_LineMap.begin(); - MapEnd = m_LineMap.end(); - LineIt = MapBegin; - unsigned long label = 1; - for (LineIt = MapBegin; LineIt != MapEnd; ++LineIt) - { - typename lineEncoding::iterator cIt; - for (cIt = LineIt->begin();cIt != LineIt->end();++cIt) - { - cIt->label = label; - InsertSet(label); - label++; - } - } - } - - // wait for the other threads to complete that part - this->Wait(); - - // now process the map and make appropriate entries in an equivalence - // table - // assert( linecount == m_LineMap.size() ); - long pixelcount = output->GetRequestedRegion().GetNumberOfPixels(); - long xsize = output->GetRequestedRegion().GetSize()[0]; - long linecount = pixelcount/xsize; - - long lastLineIdForThread = linecount; - long nbOfLineIdToJoin = 0; - if( threadId != nbOfThreads - 1 ) - { - SizeType outputRegionForThreadSize = outputRegionForThread.GetSize(); - outputRegionForThreadSize[splitAxis] -= 1; - lastLineIdForThread = firstLineIdForThread + RegionType( outputRegionIdx, outputRegionForThreadSize ).GetNumberOfPixels() / xsizeForThread; - m_FirstLineIdToJoin[threadId] = lastLineIdForThread; - // found the number of line ids to join - nbOfLineIdToJoin = RegionType( outputRegionIdx, outputRegionForThread.GetSize() ).GetNumberOfPixels() / xsizeForThread - RegionType( outputRegionIdx, outputRegionForThreadSize ).GetNumberOfPixels() / xsizeForThread; - } - - for(long ThisIdx = firstLineIdForThread; ThisIdx < lastLineIdForThread; ++ThisIdx) - { - if( !m_LineMap[ThisIdx].empty() ) - { - for (OffsetVec::const_iterator I = LineOffsets.begin(); - I != LineOffsets.end(); ++I) - { - long NeighIdx = ThisIdx + (*I); - // check if the neighbor is in the map - if ( NeighIdx >= 0 && NeighIdx < linecount && !m_LineMap[NeighIdx].empty() ) - { - // Now check whether they are really neighbors - bool areNeighbors - = CheckNeighbors(m_LineMap[ThisIdx][0].where, m_LineMap[NeighIdx][0].where); - if (areNeighbors) - { - // Compare the two lines - CompareLines(m_LineMap[ThisIdx], m_LineMap[NeighIdx]); - } - } - } - } - } - - // wait for the other threads to complete that part - this->Wait(); - - while( m_FirstLineIdToJoin.size() != 0 ) - { - if( threadId * 2 < (long)m_FirstLineIdToJoin.size() ) - { - for(long ThisIdx = m_FirstLineIdToJoin[threadId * 2]; - ThisIdx < m_FirstLineIdToJoin[threadId * 2] + nbOfLineIdToJoin; - ++ThisIdx) - { - if( !m_LineMap[ThisIdx].empty() ) - { - for (OffsetVec::const_iterator I = LineOffsets.begin(); - I != LineOffsets.end(); ++I) - { - long NeighIdx = ThisIdx + (*I); - // check if the neighbor is in the map - if ( NeighIdx >= 0 && NeighIdx < linecount && !m_LineMap[NeighIdx].empty() ) - { - // Now check whether they are really neighbors - bool areNeighbors - = CheckNeighbors(m_LineMap[ThisIdx][0].where, m_LineMap[NeighIdx][0].where); - if (areNeighbors) - { - // Compare the two lines - CompareLines(m_LineMap[ThisIdx], m_LineMap[NeighIdx]); - } - } - } - } - } - } - - this->Wait(); - - if( threadId == 0 ) - { - // remove the region already joined - typename std::vector< long > newFirstLineIdToJoin; - for( int i = 1; i<(long)m_FirstLineIdToJoin.size(); i+=2 ) - { - newFirstLineIdToJoin.push_back( m_FirstLineIdToJoin[i] ); - } - m_FirstLineIdToJoin = newFirstLineIdToJoin; - } - - this->Wait(); - - } - -} - -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::AfterThreadedGenerateData() -{ - typename TOutputImage::Pointer output = this->GetOutput(); - typename TInputImage::ConstPointer input = this->GetInput(); - long pixelcount = output->GetRequestedRegion().GetNumberOfPixels(); - long xsize = output->GetRequestedRegion().GetSize()[0]; - long linecount = pixelcount/xsize; - unsigned long int totalLabs = CreateConsecutive(); - m_ObjectCount = totalLabs; - ProgressReporter progress(this, 0, linecount); - // check for overflow exception here - if( totalLabs > static_cast<unsigned long int>( - NumericTraits<OutputPixelType>::max() ) ) - { - itkExceptionMacro( - << "Number of objects greater than maximum of output pixel type " ); - } - - for (long ThisIdx = 0; ThisIdx<linecount; ThisIdx++) - { - // now fill the labelled sections - typename lineEncoding::const_iterator cIt; - - for (cIt = m_LineMap[ThisIdx].begin();cIt != m_LineMap[ThisIdx].end();++cIt) - { - unsigned long Ilab = LookupSet( cIt->label); - OutputPixelType lab = m_Consecutive[Ilab]; - output->SetLine( cIt->where, cIt->length, lab ); -// std::cout << cIt->where << " " << cIt->length << " " << lab+0.0 << std::endl; - } - progress.CompletedPixel(); - } - - m_NumberOfLabels.clear(); - m_Barrier = NULL; - m_LineMap.clear(); -} - - -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::SetupLineOffsets(OffsetVec &LineOffsets) -{ - // Create a neighborhood so that we can generate a table of offsets - // to "previous" line indexes - // We are going to mis-use the neighborhood iterators to compute the - // offset for us. All this messing around produces an array of - // offsets that will be used to index the map - typename TOutputImage::Pointer output = this->GetOutput(); - typedef Image<long, TOutputImage::ImageDimension - 1> PretendImageType; - typedef typename PretendImageType::RegionType::SizeType PretendSizeType; - typedef typename PretendImageType::RegionType::IndexType PretendIndexType; - typedef ConstShapedNeighborhoodIterator<PretendImageType> - LineNeighborhoodType; - - typename PretendImageType::Pointer fakeImage; - fakeImage = PretendImageType::New(); - - typename PretendImageType::RegionType LineRegion; - //LineRegion = PretendImageType::RegionType::New(); - - OutSizeType OutSize = output->GetRequestedRegion().GetSize(); - - PretendSizeType PretendSize; - // The first dimension has been collapsed - for (unsigned int i = 0; i<PretendSize.GetSizeDimension(); i++) - { - PretendSize[i] = OutSize[i+1]; - } - - LineRegion.SetSize(PretendSize); - fakeImage->SetRegions( LineRegion ); - PretendSizeType kernelRadius; - kernelRadius.Fill(1); - LineNeighborhoodType lnit(kernelRadius, fakeImage, LineRegion); - - // only activate the indices that are "previous" to the current - // pixel and face connected (exclude the center pixel from the - // neighborhood) - // - setConnectivityPrevious( &lnit, m_FullyConnected ); - - typename LineNeighborhoodType::IndexListType ActiveIndexes; - ActiveIndexes = lnit.GetActiveIndexList(); - - typename LineNeighborhoodType::IndexListType::const_iterator LI; - - PretendIndexType idx = LineRegion.GetIndex(); - long offset = fakeImage->ComputeOffset( idx ); - - for (LI=ActiveIndexes.begin(); LI != ActiveIndexes.end(); LI++) - { - LineOffsets.push_back( fakeImage->ComputeOffset( idx + lnit.GetOffset( *LI ) ) - offset ); - } - - // LineOffsets is the thing we wanted. -} - - -template< class TInputImage, class TOutputImage > -bool -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::CheckNeighbors(const OutputIndexType &A, - const OutputIndexType &B) -{ - // this checks whether the line encodings are really neighbors. The - // first dimension gets ignored because the encodings are along that - // axis - OutputOffsetType Off = A - B; - for (unsigned i = 1; i < OutputImageDimension; i++) - { - if (abs(Off[i]) > 1) - { - return(false); - } - } - return(true); -} - - -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::CompareLines(lineEncoding ¤t, const lineEncoding &Neighbour) -{ - long offset = 0; - if (m_FullyConnected) - { - offset = 1; - } - - typename lineEncoding::const_iterator nIt, mIt; - typename lineEncoding::iterator cIt; - - mIt = Neighbour.begin(); // out marker iterator - - for (cIt = current.begin();cIt != current.end();++cIt) - { - //runLength cL = *cIt; - long cStart = cIt->where[0]; // the start x position - long cLast = cStart + cIt->length - 1; - - for (nIt=mIt; nIt != Neighbour.end(); ++nIt) - { - //runLength nL = *nIt; - long nStart = nIt->where[0]; - long nLast = nStart + nIt->length - 1; - // there are a few ways that neighbouring lines might overlap - // neighbor S E - // current S E - //------------------------------------------ - // neighbor S E - // current S E - //------------------------------------------ - // neighbor S E - // current S E - //------------------------------------------ - // neighbor S E - // current S E - //------------------------------------------ - long ss1 = nStart - offset; - // long ss2 = nStart + offset; - long ee1 = nLast - offset; - long ee2 = nLast + offset; - bool eq = false; - // the logic here can probably be improved a lot - if ((ss1 >= cStart) && (ee2 <= cLast)) - { - // case 1 - eq = true; - } - else - { - if ((ss1 <= cLast) && (ee2 >= cLast)) - { - // case 2 - eq = true; - } - else - { - if ((ss1 <= cStart) && (ee2 >= cStart)) - { - // case 3 - eq = true; - } - else - { - if ((ss1 <= cStart) && (ee2 >= cLast)) - { - // case 4 - eq = true; - } - } - } - } - if (eq) - { - LinkLabels(nIt->label, cIt->label); - } - - if (ee1 >= cLast) - { - // No point looking for more overlaps with the current run - // because the neighbor run is either case 2 or 4 - mIt = nIt; - break; - } - } - } - -} - -// union find related functions -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::InsertSet(const unsigned long int label) -{ - m_UnionFind[label]=label; -} - -template< class TInputImage, class TOutputImage > -unsigned long int -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::CreateConsecutive() -{ - m_Consecutive = UnionFindType(m_UnionFind.size()); - m_Consecutive[m_BackgroundValue] = m_BackgroundValue; - unsigned long int CLab = 0; - for (unsigned long int I = 1; I < m_UnionFind.size(); I++) - { - unsigned long int L = m_UnionFind[I]; - if (L == I) - { - if( CLab == m_BackgroundValue ) - { - ++CLab; - } - m_Consecutive[L] = CLab; - ++CLab; - } - } - return(CLab); -} - -template< class TInputImage, class TOutputImage > -unsigned long int -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::LookupSet(const unsigned long int label) -{ - // recursively set the equivalence if necessary - if (label != m_UnionFind[label]) - { - m_UnionFind[label] = this->LookupSet(m_UnionFind[label]); - } - return(m_UnionFind[label]); -} - -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::LinkLabels(const unsigned long int lab1, const unsigned long int lab2) -{ - unsigned long E1 = this->LookupSet(lab1); - unsigned long E2 = this->LookupSet(lab2); - - if (E1 < E2) - { - m_UnionFind[E2] = E1; - } - else - { - m_UnionFind[E1] = E2; - } - -} - -template< class TInputImage, class TOutputImage > -void -BinaryImageToLabelMapFilter< TInputImage, TOutputImage > -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os,indent); - - os << indent << "FullyConnected: " << m_FullyConnected << std::endl; - os << indent << "ObjectCount: " << m_ObjectCount << std::endl; - os << indent << "ForegroundValue: " << static_cast<typename NumericTraits<InputPixelType>::PrintType>(m_ForegroundValue) << std::endl; - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; -} - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkBinaryImageToShapeLabelMapFilter.h b/Utilities/InsightJournal/itkBinaryImageToShapeLabelMapFilter.h deleted file mode 100644 index 9917bb7de65bec62d6d361b0c2390014e2b677e1..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkBinaryImageToShapeLabelMapFilter.h +++ /dev/null @@ -1,171 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkBinaryImageToShapeLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkBinaryImageToShapeLabelMapFilter_h -#define __itkBinaryImageToShapeLabelMapFilter_h - -#include "itkImageToImageFilter.h" -#include "itkShapeLabelObject.h" -#include "itkLabelMap.h" -#include "itkBinaryImageToLabelMapFilter.h" -#include "itkShapeLabelMapFilter.h" - - -namespace itk { - -/** \class BinaryImageToShapeLabelMapFilter - * \brief a convenient class to convert a binary image to a label map and valuate the shape attributes at once - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ShapeLabelObject, LabelShapeOpeningImageFilter, BinaryStatisticsOpeningImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TOutputImage=LabelMap< ShapeLabelObject< unsigned long, TInputImage::ImageDimension > > > -class ITK_EXPORT BinaryImageToShapeLabelMapFilter : - public ImageToImageFilter<TInputImage, TOutputImage> -{ -public: - /** Standard class typedefs. */ - typedef BinaryImageToShapeLabelMapFilter Self; - typedef ImageToImageFilter<TInputImage, TOutputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - - typedef TOutputImage OutputImageType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - typedef typename OutputImageType::LabelObjectType LabelObjectType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef typename itk::BinaryImageToLabelMapFilter< InputImageType, OutputImageType > LabelizerType; - typedef typename itk::ShapeLabelMapFilter< OutputImageType > LabelObjectValuatorType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(BinaryImageToShapeLabelMapFilter, - ImageToImageFilter); - - /** - * Set/Get whether the connected components are defined strictly by - * face connectivity or by face+edge+vertex connectivity. Default is - * FullyConnectedOff. For objects that are 1 pixel wide, use - * FullyConnectedOn. - */ - itkSetMacro(FullyConnected, bool); - itkGetConstReferenceMacro(FullyConnected, bool); - itkBooleanMacro(FullyConnected); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the value used as "foreground" in the output image. - * Defaults to NumericTraits<PixelType>::max(). - */ - itkSetMacro(ForegroundValue, InputImagePixelType); - itkGetConstMacro(ForegroundValue, InputImagePixelType); - - /** - * Set/Get whether the maximum Feret diameter should be computed or not. The - * defaut value is false, because of the high computation time required. - */ - itkSetMacro(ComputeFeretDiameter, bool); - itkGetConstReferenceMacro(ComputeFeretDiameter, bool); - itkBooleanMacro(ComputeFeretDiameter); - - /** - * Set/Get whether the perimeter should be computed or not. The defaut value - * is false, because of the high computation time required. - */ - itkSetMacro(ComputePerimeter, bool); - itkGetConstReferenceMacro(ComputePerimeter, bool); - itkBooleanMacro(ComputePerimeter); - - -protected: - BinaryImageToShapeLabelMapFilter(); - ~BinaryImageToShapeLabelMapFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** BinaryImageToShapeLabelMapFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** BinaryImageToShapeLabelMapFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - - -private: - BinaryImageToShapeLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - bool m_FullyConnected; - OutputImagePixelType m_BackgroundValue; - InputImagePixelType m_ForegroundValue; - bool m_ComputeFeretDiameter; - bool m_ComputePerimeter; - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkBinaryImageToShapeLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkBinaryImageToShapeLabelMapFilter.txx b/Utilities/InsightJournal/itkBinaryImageToShapeLabelMapFilter.txx deleted file mode 100644 index 61d3dfbfa71527f3b2893a01c013e0d18a49eaf0..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkBinaryImageToShapeLabelMapFilter.txx +++ /dev/null @@ -1,112 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkBinaryImageToShapeLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkBinaryImageToShapeLabelMapFilter_txx -#define __itkBinaryImageToShapeLabelMapFilter_txx - -#include "itkBinaryImageToShapeLabelMapFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage, class TOutputImage> -BinaryImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::BinaryImageToShapeLabelMapFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_ForegroundValue = NumericTraits<OutputImagePixelType>::max(); - m_FullyConnected = false; - m_ComputeFeretDiameter = false; - m_ComputePerimeter = false; -} - -template<class TInputImage, class TOutputImage> -void -BinaryImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage, class TOutputImage> -void -BinaryImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage, class TOutputImage> -void -BinaryImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetForegroundValue( m_ForegroundValue ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetFullyConnected( m_FullyConnected ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .5f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - valuator->SetComputePerimeter( m_ComputePerimeter ); - valuator->SetComputeFeretDiameter( m_ComputeFeretDiameter ); - progress->RegisterInternalFilter(valuator, .5f); - - valuator->GraftOutput( this->GetOutput() ); - valuator->Update(); - this->GraftOutput( valuator->GetOutput() ); -} - - -template<class TInputImage, class TOutputImage> -void -BinaryImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "FullyConnected: " << m_FullyConnected << std::endl; - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "ForegroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_ForegroundValue) << std::endl; - os << indent << "ComputeFeretDiameter: " << m_ComputeFeretDiameter << std::endl; - os << indent << "ComputePerimeter: " << m_ComputePerimeter << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkBinaryImageToStatisticsLabelMapFilter.h b/Utilities/InsightJournal/itkBinaryImageToStatisticsLabelMapFilter.h deleted file mode 100644 index 9e339f4bcb64a5a5b00775c0cacbbb1e14b8fcdb..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkBinaryImageToStatisticsLabelMapFilter.h +++ /dev/null @@ -1,222 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkBinaryImageToStatisticsLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkBinaryImageToStatisticsLabelMapFilter_h -#define __itkBinaryImageToStatisticsLabelMapFilter_h - -#include "itkImageToImageFilter.h" -#include "itkStatisticsLabelObject.h" -#include "itkLabelMap.h" -#include "itkBinaryImageToLabelMapFilter.h" -#include "itkStatisticsLabelMapFilter.h" - - -namespace itk { - -/** \class BinaryImageToStatisticsLabelMapFilter - * \brief a convenient class to convert a binary image to a label map and valuate the statistics attributes at once - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa StatisticsLabelObject, LabelStatisticsOpeningImageFilter, BinaryStatisticsOpeningImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TFeatureImage, class TOutputImage=LabelMap< StatisticsLabelObject< unsigned long, TInputImage::ImageDimension > > > -class ITK_EXPORT BinaryImageToStatisticsLabelMapFilter : - public ImageToImageFilter<TInputImage, TOutputImage> -{ -public: - /** Standard class typedefs. */ - typedef BinaryImageToStatisticsLabelMapFilter Self; - typedef ImageToImageFilter<TInputImage, TOutputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - - typedef TOutputImage OutputImageType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - typedef typename OutputImageType::LabelObjectType LabelObjectType; - - typedef TFeatureImage FeatureImageType; - typedef typename FeatureImageType::Pointer FeatureImagePointer; - typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer; - typedef typename FeatureImageType::PixelType FeatureImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef typename itk::BinaryImageToLabelMapFilter< InputImageType, OutputImageType > LabelizerType; - typedef typename itk::StatisticsLabelMapFilter< OutputImageType, FeatureImageType > LabelObjectValuatorType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(BinaryImageToStatisticsLabelMapFilter, - ImageToImageFilter); - - /** - * Set/Get whether the connected components are defined strictly by - * face connectivity or by face+edge+vertex connectivity. Default is - * FullyConnectedOff. For objects that are 1 pixel wide, use - * FullyConnectedOn. - */ - itkSetMacro(FullyConnected, bool); - itkGetConstReferenceMacro(FullyConnected, bool); - itkBooleanMacro(FullyConnected); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the value used as "foreground" in the output image. - * Defaults to NumericTraits<PixelType>::max(). - */ - itkSetMacro(ForegroundValue, InputImagePixelType); - itkGetConstMacro(ForegroundValue, InputImagePixelType); - - /** - * Set/Get whether the maximum Feret diameter should be computed or not. The - * defaut value is false, because of the high computation time required. - */ - itkSetMacro(ComputeFeretDiameter, bool); - itkGetConstReferenceMacro(ComputeFeretDiameter, bool); - itkBooleanMacro(ComputeFeretDiameter); - - /** - * Set/Get whether the perimeter should be computed or not. The defaut value - * is false, because of the high computation time required. - */ - itkSetMacro(ComputePerimeter, bool); - itkGetConstReferenceMacro(ComputePerimeter, bool); - itkBooleanMacro(ComputePerimeter); - - /** Set the feature image */ - void SetFeatureImage(TFeatureImage *input) - { - // Process object is not const-correct so the const casting is required. - this->SetNthInput( 1, const_cast<TFeatureImage *>(input) ); - } - - /** Get the feature image */ - FeatureImageType * GetFeatureImage() - { - return static_cast<FeatureImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1))); - } - - /** Set the input image */ - void SetInput1(InputImageType *input) - { - this->SetInput( input ); - } - - /** Set the feature image */ - void SetInput2(FeatureImageType *input) - { - this->SetFeatureImage( input ); - } - - /** - * Set/Get whether the histogram should be attached to the label object or not. - * This option defaults to `true`, but because the histogram may take a lot of memory - * compared to the other attributes, this option is useful to reduce the memory usage - * when the histogram is not required. - */ - itkSetMacro(ComputeHistogram, bool); - itkGetConstReferenceMacro(ComputeHistogram, bool); - itkBooleanMacro(ComputeHistogram); - - /** - * Set/Get the number of bins in the histogram. Note that the histogram is used - * to compute the median value, and that this option may have an effect on the - * value of the median. - */ - itkSetMacro(NumberOfBins, unsigned int); - itkGetConstReferenceMacro(NumberOfBins, unsigned int); - - - -protected: - BinaryImageToStatisticsLabelMapFilter(); - ~BinaryImageToStatisticsLabelMapFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** BinaryImageToStatisticsLabelMapFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** BinaryImageToStatisticsLabelMapFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - - -private: - BinaryImageToStatisticsLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - bool m_FullyConnected; - OutputImagePixelType m_BackgroundValue; - InputImagePixelType m_ForegroundValue; - bool m_ComputeFeretDiameter; - bool m_ComputePerimeter; - unsigned int m_NumberOfBins; - bool m_ComputeHistogram; - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkBinaryImageToStatisticsLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkBinaryImageToStatisticsLabelMapFilter.txx b/Utilities/InsightJournal/itkBinaryImageToStatisticsLabelMapFilter.txx deleted file mode 100644 index 914fa7c7a879f10c4b9114bef09aa6a15ea53352..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkBinaryImageToStatisticsLabelMapFilter.txx +++ /dev/null @@ -1,120 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkBinaryImageToStatisticsLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkBinaryImageToStatisticsLabelMapFilter_txx -#define __itkBinaryImageToStatisticsLabelMapFilter_txx - -#include "itkBinaryImageToStatisticsLabelMapFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage, class TFeatureImage, class TOutputImage> -BinaryImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::BinaryImageToStatisticsLabelMapFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_ForegroundValue = NumericTraits<OutputImagePixelType>::max(); - m_FullyConnected = false; - m_ComputeFeretDiameter = false; - m_ComputePerimeter = false; - m_NumberOfBins = 128; - m_ComputeHistogram = true; - this->SetNumberOfRequiredInputs(2); -} - -template<class TInputImage, class TFeatureImage, class TOutputImage> -void -BinaryImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage, class TFeatureImage, class TOutputImage> -void -BinaryImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage, class TFeatureImage, class TOutputImage> -void -BinaryImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetForegroundValue( m_ForegroundValue ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetFullyConnected( m_FullyConnected ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .5f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetFeatureImage( this->GetFeatureImage() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - valuator->SetComputePerimeter( m_ComputePerimeter ); - valuator->SetComputeFeretDiameter( m_ComputeFeretDiameter ); - valuator->SetComputeHistogram( m_ComputeHistogram ); - valuator->SetNumberOfBins( m_NumberOfBins ); - progress->RegisterInternalFilter(valuator, .5f); - - valuator->GraftOutput( this->GetOutput() ); - valuator->Update(); - this->GraftOutput( valuator->GetOutput() ); -} - - -template<class TInputImage, class TFeatureImage, class TOutputImage> -void -BinaryImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "FullyConnected: " << m_FullyConnected << std::endl; - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "ForegroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_ForegroundValue) << std::endl; - os << indent << "ComputeFeretDiameter: " << m_ComputeFeretDiameter << std::endl; - os << indent << "ComputePerimeter: " << m_ComputePerimeter << std::endl; - os << indent << "ComputeHistogram: " << m_ComputeHistogram << std::endl; - os << indent << "NumberOfBins: " << m_NumberOfBins << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkChangeRegionLabelMapFilter.h b/Utilities/InsightJournal/itkChangeRegionLabelMapFilter.h deleted file mode 100644 index d80004758db28cb9977485437490da31f6896c77..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkChangeRegionLabelMapFilter.h +++ /dev/null @@ -1,120 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkChangeRegionLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:38 $ - Version: $Revision: 1.4 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkChangeRegionLabelMapFilter_h -#define __itkChangeRegionLabelMapFilter_h - -#include "itkInPlaceLabelMapFilter.h" - -namespace itk -{ - -/** \class ChangeRegionLabelMapFilter - * \brief Change the region of a label map - * - * Change the region of a label map. If the output can't contain some lines of - * the objects, they are truncated, or remove. All the objects fully outside the - * output region are removed. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa LabelMapMaskImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template <class TInputImage> -class ITK_EXPORT ChangeRegionLabelMapFilter : public InPlaceLabelMapFilter<TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef ChangeRegionLabelMapFilter Self; - typedef InPlaceLabelMapFilter<TInputImage> Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - - /** Run-time type information (and related methods). */ - itkTypeMacro(ChangeRegionLabelMapFilter, InPlaceImageFilter); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Superclass typedefs. */ - typedef typename Superclass::OutputImageType OutputImageType; - typedef typename Superclass::OutputImagePointer OutputImagePointer; - typedef typename Superclass::OutputImageRegionType OutputImageRegionType; - typedef typename Superclass::OutputImagePixelType OutputImagePixelType; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typedef typename InputImageType::PixelType PixelType; - typedef typename InputImageType::IndexType IndexType; - typedef typename InputImageType::SizeType SizeType; - typedef typename InputImageType::RegionType RegionType; - - typedef TInputImage TOutputImage; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TOutputImage::ImageDimension); - - /** The output region to use */ - itkSetMacro(Region, OutputImageRegionType); - itkGetConstReferenceMacro(Region, OutputImageRegionType); - - protected: - ChangeRegionLabelMapFilter() {}; - ~ChangeRegionLabelMapFilter() {}; - - virtual void PrintSelf(std::ostream& os, Indent indent) const; - - virtual void ThreadedGenerateData( LabelObjectType * labelObject ); - - void GenerateInputRequestedRegion() ; - - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - virtual void GenerateOutputInformation(); - - void GenerateData(); - -private: - ChangeRegionLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImageRegionType m_Region; - -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkChangeRegionLabelMapFilter.txx" -#endif - -#endif diff --git a/Utilities/InsightJournal/itkChangeRegionLabelMapFilter.txx b/Utilities/InsightJournal/itkChangeRegionLabelMapFilter.txx deleted file mode 100644 index 2b43e2210c793c07fbbf027bb8f8b59f76aaeaa6..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkChangeRegionLabelMapFilter.txx +++ /dev/null @@ -1,167 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkChangeRegionLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:39 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef _itkChangeRegionLabelMapFilter_txx -#define _itkChangeRegionLabelMapFilter_txx -#include "itkChangeRegionLabelMapFilter.h" - - -namespace itk -{ - - -template <class TInputImage> -void -ChangeRegionLabelMapFilter<TInputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if ( !input ) - { return; } - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); -} - -template <class TInputImage> -void -ChangeRegionLabelMapFilter<TInputImage> -::GenerateOutputInformation() -{ - Superclass::GenerateOutputInformation(); - this->GetOutput()->SetLargestPossibleRegion( m_Region ); -// std::cout << "ChangeRegionLabelMapFilter::GenerateOutputInformation(): " << this->GetOutput()->GetLargestPossibleRegion() << std::endl; -} - -template <class TInputImage> -void -ChangeRegionLabelMapFilter<TInputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - -template <class TInputImage> -void -ChangeRegionLabelMapFilter<TInputImage> -::GenerateData() -{ -// std::cout << "ChangeRegionLabelMapFilter::GenerateData(): " << this->GetOutput()->GetLargestPossibleRegion() << std::endl; - - if( m_Region.IsInside( this->GetInput()->GetLargestPossibleRegion() ) ) - { - // only copy the image, and do nothing much - // oh, we have to pretend we have a progress ! - ProgressReporter progress( this, 0, 1 ); - this->AllocateOutputs(); -// std::cout << "do nothing" << std::endl; - } - else - { - // call the superclass implementation so it will take care to create the threads - Superclass::GenerateData(); - } -} - - -template<class TInputImage> -void -ChangeRegionLabelMapFilter<TInputImage> -::ThreadedGenerateData( LabelObjectType * labelObject ) -{ - typename InputImageType::LabelObjectType::LineContainerType::const_iterator lit; - typename InputImageType::LabelObjectType::LineContainerType lineContainer = labelObject->GetLineContainer(); - labelObject->GetLineContainer().clear(); -// std::cout << "lineContainer.size(): " << lineContainer.size() << std::endl; - - IndexType idxMin = m_Region.GetIndex(); - IndexType idxMax; - for( int i=0; i<ImageDimension; i++ ) - { - idxMax[i] = idxMin[i] + m_Region.GetSize()[i] - 1; - } -// std::cout << "idxMin: " << idxMin << std::endl; -// std::cout << "idxMax: " << idxMax << std::endl; - - for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ ) - { - IndexType idx = lit->GetIndex(); - unsigned long length = lit->GetLength(); - - bool outside = false; - for( int i=1; i<ImageDimension; i++ ) - { - if( idx[i] < idxMin[i] || idx[i] > idxMax[i] ) - { - outside = true; - } - } - // check the axis 0 - if( !outside ) - { - long lastIdx0 = idx[0] + length - 1; - if( !( ( idx[0] < idxMin[0] && lastIdx0 < idxMin[0] ) - || ( idx[0] > idxMax[0] && lastIdx0 > idxMax[0] ) ) ) - { -// std::cout << "!outside" << std::endl; - IndexType newIdx = idx; - long newLength = length; - if( idx[0] < idxMin[0] ) - { - newLength -= idxMin[0] - idx[0]; - newIdx[0] = idxMin[0]; - } - if( lastIdx0 > idxMax[0] ) - { - newLength -= lastIdx0 - idxMax[0]; - } - - labelObject->AddLine( newIdx, newLength ); - } - } - - } - - // remove the object if it is empty - if( labelObject->GetLineContainer().empty() ) - { -// std::cout << "remove: " << labelObject << std::endl; - this->m_LabelObjectContainerLock->Lock(); - this->GetOutput()->RemoveLabelObject( labelObject ); - this->m_LabelObjectContainerLock->Unlock(); - } - -} - -template<class TInputImage> -void -ChangeRegionLabelMapFilter<TInputImage> -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - os << indent << "Region: " << m_Region << std::endl; -} - - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkCropLabelMapFilter.h b/Utilities/InsightJournal/itkCropLabelMapFilter.h deleted file mode 100644 index 7bced2c1274f05d3a7468a8ef0fad8dc8199d266..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkCropLabelMapFilter.h +++ /dev/null @@ -1,130 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkCropLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:38 $ - Version: $Revision: 1.4 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkCropLabelMapFilter_h -#define __itkCropLabelMapFilter_h - -#include "itkChangeRegionLabelMapFilter.h" - -namespace itk -{ - -/** \class CropLabelMapFilter - * \brief Crop a LabelMap image - * - * Crop a label map. If the output can't contain some lines of - * the objects, they are truncated, or remove. All the objects fully outside the - * output region are removed. - * - * The SetCropSize() method can be used to set the crop size of the lower and - * the upper boundaries in a single call. - * By default, the filter doesn't crop anything. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa PadLabelMapFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template <class TInputImage> -class ITK_EXPORT CropLabelMapFilter : public ChangeRegionLabelMapFilter<TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef CropLabelMapFilter Self; - typedef ChangeRegionLabelMapFilter<TInputImage> Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - - /** Run-time type information (and related methods). */ - itkTypeMacro(CropLabelMapFilter, ChangeRegionImageFilter); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Superclass typedefs. */ - typedef typename Superclass::OutputImageType OutputImageType; - typedef typename Superclass::OutputImagePointer OutputImagePointer; - typedef typename Superclass::OutputImageRegionType OutputImageRegionType; - typedef typename Superclass::OutputImagePixelType OutputImagePixelType; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typedef typename InputImageType::PixelType PixelType; - typedef typename InputImageType::IndexType IndexType; - typedef typename InputImageType::SizeType SizeType; - typedef typename InputImageType::RegionType RegionType; - - typedef TInputImage TOutputImage; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TOutputImage::ImageDimension); - - /** Set/Get the cropping sizes for the upper and lower boundaries. */ - itkSetMacro(UpperBoundaryCropSize, SizeType); - itkGetMacro(UpperBoundaryCropSize, SizeType); - itkSetMacro(LowerBoundaryCropSize, SizeType); - itkGetMacro(LowerBoundaryCropSize, SizeType); - - void SetCropSize( const SizeType & size ) - { - this->SetUpperBoundaryCropSize( size ); - this->SetLowerBoundaryCropSize( size ); - } - - - protected: - CropLabelMapFilter() - { - m_UpperBoundaryCropSize.Fill(0); - m_LowerBoundaryCropSize.Fill(0); - }; - ~CropLabelMapFilter() {}; - - virtual void GenerateOutputInformation(); - - void PrintSelf(std::ostream& os, Indent indent) const; - - -private: - CropLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - SizeType m_UpperBoundaryCropSize; - SizeType m_LowerBoundaryCropSize; -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkCropLabelMapFilter.txx" -#endif - -#endif diff --git a/Utilities/InsightJournal/itkCropLabelMapFilter.txx b/Utilities/InsightJournal/itkCropLabelMapFilter.txx deleted file mode 100644 index 55392c65a2217b045729c67d3629a7b75224adae..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkCropLabelMapFilter.txx +++ /dev/null @@ -1,79 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkCropLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:39 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef _itkCropLabelMapFilter_txx -#define _itkCropLabelMapFilter_txx -#include "itkCropLabelMapFilter.h" - - -namespace itk -{ - - -template <class TInputImage> -void -CropLabelMapFilter<TInputImage> -::GenerateOutputInformation() -{ - const TInputImage * inputPtr = this->GetInput(); - if( !inputPtr ) - { - return; - } - - // Compute the new region size. - RegionType croppedRegion; - SizeType sz; - IndexType idx; - - SizeType input_sz = - inputPtr->GetLargestPossibleRegion().GetSize(); - IndexType input_idx = - inputPtr->GetLargestPossibleRegion().GetIndex(); - - idx = input_idx + m_LowerBoundaryCropSize; - sz = input_sz - (m_UpperBoundaryCropSize + m_LowerBoundaryCropSize); - - croppedRegion.SetSize(sz); - croppedRegion.SetIndex(idx); - - // Set extraction region in the superclass. - this->SetRegion(croppedRegion); - - // - Superclass::GenerateOutputInformation(); -} - - -template <class TInputImage> -void -CropLabelMapFilter<TInputImage> -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os,indent); - - os << indent << "UpperBoundaryCropSize: " << m_UpperBoundaryCropSize << - std::endl; - os << indent << "LowerBoundaryCropSize: " << m_LowerBoundaryCropSize << - std::endl; -} - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkInPlaceLabelMapFilter.h b/Utilities/InsightJournal/itkInPlaceLabelMapFilter.h deleted file mode 100644 index 39c22e241e1bec0f9159cf71f219c21fe3a2665d..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkInPlaceLabelMapFilter.h +++ /dev/null @@ -1,179 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkInPlaceLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:38 $ - Version: $Revision: 1.4 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkInPlaceLabelMapFilter_h -#define __itkInPlaceLabelMapFilter_h - -#include "itkLabelMapFilter.h" - -namespace itk -{ - -/** \class InPlaceLabelMapFilter - * \brief Base class for filters that take an image as input and overwrite that image as the output - * - * InPlaceLabelMapFilter is the base class for all process objects whose - * output image data is constructed by overwriting the input image - * data. In other words, the output bulk data is the same block of - * memory as the input bulk data. This filter provides the mechanisms - * for in place image processing while maintaining general pipeline - * mechanics. InPlaceLabelMapFilters use less memory than standard - * ImageToImageFilters because the input buffer is reused as the - * output buffer. However, this benefit does not come without a cost. - * Since the filter overwrites its input, the ownership of the bulk - * data is transitioned from the input data object to the output data - * object. When a data object has multiple consumers with one - * of the consumers being an in place filter, the in place filter - * effectively destroys the bulk data for the data object. Upstream - * filters will then have to re-execute to regenerate the data object's - * bulk data for the remaining consumers. - * - * Since an InPlaceLabelMapFilter reuses the input bulk data memory for the - * output bulk data memory, the input image type must match the output - * image type. If the input and output image types are not identical, - * the filter reverts to a traditional ImageToImageFilter behaviour - * where an output image is allocated. In place operation can also be - * controlled (when the input and output image type match) via the - * methods InPlaceOn() and InPlaceOff(). - * - * Subclasses of InPlaceLabelMapFilter must take extra care in how they - * manage memory using (and perhaps overriding) the implementations of - * ReleaseInputs() and AllocateOutputs() provided here. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa LabelMapToBinaryImageFilter, LabelMapToLabelImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template <class TInputImage> -class ITK_EXPORT InPlaceLabelMapFilter : public LabelMapFilter<TInputImage, TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef InPlaceLabelMapFilter Self; - typedef LabelMapFilter<TInputImage, TInputImage> Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - - /** Run-time type information (and related methods). */ - itkTypeMacro(InPlaceLabelMapFilter, LabelMapFilter); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Superclass typedefs. */ - typedef typename Superclass::OutputImageType OutputImageType; - typedef typename Superclass::OutputImagePointer OutputImagePointer; - typedef typename Superclass::OutputImageRegionType OutputImageRegionType; - typedef typename Superclass::OutputImagePixelType OutputImagePixelType; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typedef typename InputImageType::PixelType PixelType; - typedef typename InputImageType::IndexType IndexType; - typedef typename InputImageType::RegionType RegionType; - - typedef TInputImage TOutputImage; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - - /** In place operation can be turned on and off. This only has an - * effect when the input and output image type match. */ - itkSetMacro(InPlace, bool); - itkGetMacro(InPlace, bool); - itkBooleanMacro(InPlace); - - /** Can the filter run in place? To do so, the filter's first input - * and output must have the same dimension and pixel type. This - * method can be used in conjunction with the InPlace ivar to - * determine whether a particular use of the filter is really - * running in place. Some filters may be able to optimize their - * operation if the InPlace is true and CanRunInPlace is true. */ - bool CanRunInPlace() const - { - return (typeid(TInputImage) == typeid(TOutputImage)); - }; - - protected: - InPlaceLabelMapFilter(); - ~InPlaceLabelMapFilter(); - - virtual void PrintSelf(std::ostream& os, Indent indent) const; - - /** The GenerateData method normally allocates the buffers for all - * of the outputs of a filter. Since InPlaceLabelMapFilter's can use an - * overwritten version of the input for its output, the output - * buffer should not be allocated. When possible, we graft the input - * to the filter to the output. If an InPlaceFilter has multiple - * outputs, then it would need to override this method to graft one - * of its outputs and allocate the remaining. If a filter is - * threaded (i.e. it provides an implementation of - * ThreadedGenerateData()), this method is called automatically. If - * an InPlaceFilter is not threaded (i.e. it provides an - * implementation of GenerateData()), then this method (or - * equivalent) must be called in GenerateData(). */ - virtual void AllocateOutputs(); - - /** InPlaceLabelMapFilter may transfer ownership of the input bulk data - * to the output object. Once the output object owns the bulk data - * (done in AllocateOutputs()), the input object must release its - * hold on the bulk data. ProcessObject::ReleaseInputs() only - * releases the input bulk data when the user has set the - * ReleaseDataFlag. InPlaceLabelMapFilter::ReleaseInputs() also - * releases the input that it has overwritten. - * - * \sa ProcessObject::ReleaseInputs() */ - virtual void ReleaseInputs(); - - - /** - * Return the output label collection image, instead of the input as in the default - * implementation - */ - virtual InputImageType * GetLabelMap() - { - return this->GetOutput(); - } - -private: - InPlaceLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - bool m_InPlace; - -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkInPlaceLabelMapFilter.txx" -#endif - -#endif diff --git a/Utilities/InsightJournal/itkInPlaceLabelMapFilter.txx b/Utilities/InsightJournal/itkInPlaceLabelMapFilter.txx deleted file mode 100644 index 96c6315a5f79147ebc635d9338970383a1648a31..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkInPlaceLabelMapFilter.txx +++ /dev/null @@ -1,146 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkInPlaceLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:39 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef _itkInPlaceLabelMapFilter_txx -#define _itkInPlaceLabelMapFilter_txx -#include "itkInPlaceLabelMapFilter.h" - - -namespace itk -{ - -/** - * - */ -template <class TInputImage> -InPlaceLabelMapFilter<TInputImage> -::InPlaceLabelMapFilter() - : m_InPlace(true) -{ -} - -/** - * - */ -template <class TInputImage> -InPlaceLabelMapFilter<TInputImage> -::~InPlaceLabelMapFilter() -{ -} - - - -template<class TInputImage> -void -InPlaceLabelMapFilter<TInputImage> -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - os << indent << "InPlace: " << (m_InPlace ? "On" : "Off") << std::endl; - if ( this->CanRunInPlace()) - { - os << indent << "The input and output to this filter are the same type. The filter can be run in place." << std::endl; - } - else - { - os << indent << "The input and output to this filter are different types. The filter cannot be run in place." << std::endl; - } -} - -template<class TInputImage> -void -InPlaceLabelMapFilter<TInputImage> -::AllocateOutputs() -{ - // if told to run in place and the types support it, - if( m_InPlace && this->CanRunInPlace() ) - { - // Graft this first input to the output. Later, we'll need to - // remove the input's hold on the bulk data. - // - OutputImagePointer inputAsOutput - = dynamic_cast<TOutputImage *>(const_cast<TInputImage *>(this->GetInput())); - if (inputAsOutput) - { - // save the largest possible region to restore it after the graft output. - // the largest possible region is not that important with LabelMap and - // can be managed by the filter, even when running inplace - RegionType region = this->GetOutput()->GetLargestPossibleRegion(); - this->GraftOutput( inputAsOutput ); - this->GetOutput()->SetRegions( region ); - } - } - else - { - Superclass::AllocateOutputs(); - // copy the content of the input image to the output image - const TInputImage * input = this->GetInput(); - TOutputImage * output = this->GetOutput(); - assert( input != NULL ); - assert( output != NULL ); - - output->SetBackgroundValue( input->GetBackgroundValue() ); - - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typename InputImageType::LabelObjectContainerType::const_iterator it; - const typename InputImageType::LabelObjectContainerType & labelObjectContainer = input->GetLabelObjectContainer(); - for( it = labelObjectContainer.begin(); it != labelObjectContainer.end(); it++ ) - { - const LabelObjectType * labeObject = it->second; - assert( labeObject != NULL ); - assert( labeObject->GetLabel() == it->first ); - - typename LabelObjectType::Pointer newLabelObject = LabelObjectType::New(); - newLabelObject->CopyAllFrom( labeObject ); - - output->AddLabelObject( newLabelObject ); - } - - } -} - -template<class TInputImage> -void -InPlaceLabelMapFilter<TInputImage> -::ReleaseInputs() -{ - // if told to run in place and the types support it, - if (m_InPlace && (typeid(TInputImage) == typeid(TOutputImage))) - { - // Release any input where the ReleaseData flag has been set - ProcessObject::ReleaseInputs(); - - // Release input 0 by default since we overwrote it - TInputImage * ptr = const_cast<TInputImage*>( this->GetInput() ); - if( ptr ) - { - ptr->ReleaseData(); - } - } - else - { - Superclass::ReleaseInputs(); - } -} - - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkLabelImageToShapeLabelMapFilter.h b/Utilities/InsightJournal/itkLabelImageToShapeLabelMapFilter.h deleted file mode 100644 index 6c9e9639d13bc8c58f7d804827e7230c0719e84e..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelImageToShapeLabelMapFilter.h +++ /dev/null @@ -1,151 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelImageToShapeLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelImageToShapeLabelMapFilter_h -#define __itkLabelImageToShapeLabelMapFilter_h - -#include "itkImageToImageFilter.h" -#include "itkShapeLabelObject.h" -#include "itkLabelMap.h" -#include "itkLabelImageToLabelMapFilter.h" -#include "itkShapeLabelMapFilter.h" - - -namespace itk { - -/** \class LabelImageToShapeLabelMapFilter - * \brief a convenient class to convert a label image to a label map and valuate the shape attributes at once - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ShapeLabelObject, LabelShapeOpeningImageFilter, LabelStatisticsOpeningImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TOutputImage=LabelMap< ShapeLabelObject< typename TInputImage::PixelType, TInputImage::ImageDimension > > > -class ITK_EXPORT LabelImageToShapeLabelMapFilter : - public ImageToImageFilter<TInputImage, TOutputImage> -{ -public: - /** Standard class typedefs. */ - typedef LabelImageToShapeLabelMapFilter Self; - typedef ImageToImageFilter<TInputImage, TOutputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - - typedef TOutputImage OutputImageType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - typedef typename OutputImageType::LabelObjectType LabelObjectType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef typename itk::LabelImageToLabelMapFilter< InputImageType, OutputImageType > LabelizerType; - typedef typename itk::ShapeLabelMapFilter< OutputImageType > LabelObjectValuatorType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelImageToShapeLabelMapFilter, - ImageToImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get whether the maximum Feret diameter should be computed or not. The - * defaut value is false, because of the high computation time required. - */ - itkSetMacro(ComputeFeretDiameter, bool); - itkGetConstReferenceMacro(ComputeFeretDiameter, bool); - itkBooleanMacro(ComputeFeretDiameter); - - /** - * Set/Get whether the perimeter should be computed or not. The defaut value - * is false, because of the high computation time required. - */ - itkSetMacro(ComputePerimeter, bool); - itkGetConstReferenceMacro(ComputePerimeter, bool); - itkBooleanMacro(ComputePerimeter); - -protected: - LabelImageToShapeLabelMapFilter(); - ~LabelImageToShapeLabelMapFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** LabelImageToShapeLabelMapFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** LabelImageToShapeLabelMapFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - - -private: - LabelImageToShapeLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - bool m_ComputeFeretDiameter; - bool m_ComputePerimeter; - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelImageToShapeLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelImageToShapeLabelMapFilter.txx b/Utilities/InsightJournal/itkLabelImageToShapeLabelMapFilter.txx deleted file mode 100644 index 53538a575cd74233be4fceea863cbc6b29381cfb..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelImageToShapeLabelMapFilter.txx +++ /dev/null @@ -1,106 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelImageToShapeLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelImageToShapeLabelMapFilter_txx -#define __itkLabelImageToShapeLabelMapFilter_txx - -#include "itkLabelImageToShapeLabelMapFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage, class TOutputImage> -LabelImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::LabelImageToShapeLabelMapFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_ComputeFeretDiameter = false; - m_ComputePerimeter = false; -} - -template<class TInputImage, class TOutputImage> -void -LabelImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage, class TOutputImage> -void -LabelImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage, class TOutputImage> -void -LabelImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .5f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - valuator->SetComputePerimeter( m_ComputePerimeter ); - valuator->SetComputeFeretDiameter( m_ComputeFeretDiameter ); - progress->RegisterInternalFilter(valuator, .5f); - - valuator->GraftOutput( this->GetOutput() ); - valuator->Update(); - this->GraftOutput( valuator->GetOutput() ); -} - - -template<class TInputImage, class TOutputImage> -void -LabelImageToShapeLabelMapFilter<TInputImage, TOutputImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "ComputeFeretDiameter: " << m_ComputeFeretDiameter << std::endl; - os << indent << "ComputePerimeter: " << m_ComputePerimeter << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkLabelImageToStatisticsLabelMapFilter.h b/Utilities/InsightJournal/itkLabelImageToStatisticsLabelMapFilter.h deleted file mode 100644 index 4d2caaf525922b760ec74a2803a5a72e2a8b994b..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelImageToStatisticsLabelMapFilter.h +++ /dev/null @@ -1,202 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelImageToStatisticsLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelImageToStatisticsLabelMapFilter_h -#define __itkLabelImageToStatisticsLabelMapFilter_h - -#include "itkImageToImageFilter.h" -#include "itkStatisticsLabelObject.h" -#include "itkLabelMap.h" -#include "itkLabelImageToLabelMapFilter.h" -#include "itkStatisticsLabelMapFilter.h" - - -namespace itk { - -/** \class LabelImageToStatisticsLabelMapFilter - * \brief a convenient class to convert a label image to a label map and valuate the statistics attributes at once - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa StatisticsLabelObject, LabelStatisticsOpeningImageFilter, LabelStatisticsOpeningImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TFeatureImage, class TOutputImage=LabelMap< StatisticsLabelObject< typename TInputImage::PixelType, TInputImage::ImageDimension > > > -class ITK_EXPORT LabelImageToStatisticsLabelMapFilter : - public ImageToImageFilter<TInputImage, TOutputImage> -{ -public: - /** Standard class typedefs. */ - typedef LabelImageToStatisticsLabelMapFilter Self; - typedef ImageToImageFilter<TInputImage, TOutputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - - typedef TOutputImage OutputImageType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - typedef typename OutputImageType::LabelObjectType LabelObjectType; - - typedef TFeatureImage FeatureImageType; - typedef typename FeatureImageType::Pointer FeatureImagePointer; - typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer; - typedef typename FeatureImageType::PixelType FeatureImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef typename itk::LabelImageToLabelMapFilter< InputImageType, OutputImageType > LabelizerType; - typedef typename itk::StatisticsLabelMapFilter< OutputImageType, FeatureImageType > LabelObjectValuatorType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelImageToStatisticsLabelMapFilter, - ImageToImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get whether the maximum Feret diameter should be computed or not. The - * defaut value is false, because of the high computation time required. - */ - itkSetMacro(ComputeFeretDiameter, bool); - itkGetConstReferenceMacro(ComputeFeretDiameter, bool); - itkBooleanMacro(ComputeFeretDiameter); - - /** - * Set/Get whether the perimeter should be computed or not. The defaut value - * is false, because of the high computation time required. - */ - itkSetMacro(ComputePerimeter, bool); - itkGetConstReferenceMacro(ComputePerimeter, bool); - itkBooleanMacro(ComputePerimeter); - - /** Set the feature image */ - void SetFeatureImage(TFeatureImage *input) - { - // Process object is not const-correct so the const casting is required. - this->SetNthInput( 1, const_cast<TFeatureImage *>(input) ); - } - - /** Get the feature image */ - FeatureImageType * GetFeatureImage() - { - return static_cast<FeatureImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1))); - } - - /** Set the input image */ - void SetInput1(InputImageType *input) - { - this->SetInput( input ); - } - - /** Set the feature image */ - void SetInput2(FeatureImageType *input) - { - this->SetFeatureImage( input ); - } - - /** - * Set/Get whether the histogram should be attached to the label object or not. - * This option defaults to `true`, but because the histogram may take a lot of memory - * compared to the other attributes, this option is useful to reduce the memory usage - * when the histogram is not required. - */ - itkSetMacro(ComputeHistogram, bool); - itkGetConstReferenceMacro(ComputeHistogram, bool); - itkBooleanMacro(ComputeHistogram); - - /** - * Set/Get the number of bins in the histogram. Note that the histogram is used - * to compute the median value, and that this option may have an effect on the - * value of the median. - */ - itkSetMacro(NumberOfBins, unsigned int); - itkGetConstReferenceMacro(NumberOfBins, unsigned int); - - -protected: - LabelImageToStatisticsLabelMapFilter(); - ~LabelImageToStatisticsLabelMapFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** LabelImageToStatisticsLabelMapFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** LabelImageToStatisticsLabelMapFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - - -private: - LabelImageToStatisticsLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - bool m_ComputeFeretDiameter; - bool m_ComputePerimeter; - unsigned int m_NumberOfBins; - bool m_ComputeHistogram; - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelImageToStatisticsLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelImageToStatisticsLabelMapFilter.txx b/Utilities/InsightJournal/itkLabelImageToStatisticsLabelMapFilter.txx deleted file mode 100644 index e3d707809c5e607ab63fb05221765004cdf44c77..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelImageToStatisticsLabelMapFilter.txx +++ /dev/null @@ -1,114 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelImageToStatisticsLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelImageToStatisticsLabelMapFilter_txx -#define __itkLabelImageToStatisticsLabelMapFilter_txx - -#include "itkLabelImageToStatisticsLabelMapFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage, class TFeatureImage, class TOutputImage> -LabelImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::LabelImageToStatisticsLabelMapFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_ComputeFeretDiameter = false; - m_ComputePerimeter = false; - m_NumberOfBins = 128; - m_ComputeHistogram = true; - this->SetNumberOfRequiredInputs(2); -} - -template<class TInputImage, class TFeatureImage, class TOutputImage> -void -LabelImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage, class TFeatureImage, class TOutputImage> -void -LabelImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage, class TFeatureImage, class TOutputImage> -void -LabelImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .5f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetFeatureImage( this->GetFeatureImage() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - valuator->SetComputePerimeter( m_ComputePerimeter ); - valuator->SetComputeFeretDiameter( m_ComputeFeretDiameter ); - valuator->SetComputeHistogram( m_ComputeHistogram ); - valuator->SetNumberOfBins( m_NumberOfBins ); - progress->RegisterInternalFilter(valuator, .5f); - - valuator->GraftOutput( this->GetOutput() ); - valuator->Update(); - this->GraftOutput( valuator->GetOutput() ); -} - - -template<class TInputImage, class TFeatureImage, class TOutputImage> -void -LabelImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "ComputeFeretDiameter: " << m_ComputeFeretDiameter << std::endl; - os << indent << "ComputePerimeter: " << m_ComputePerimeter << std::endl; - os << indent << "ComputeHistogram: " << m_ComputeHistogram << std::endl; - os << indent << "NumberOfBins: " << m_NumberOfBins << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkLabelMapToBinaryImageFilter.h b/Utilities/InsightJournal/itkLabelMapToBinaryImageFilter.h deleted file mode 100644 index 099fc7ef222f6a2dd650294eaa080d0745ce276d..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelMapToBinaryImageFilter.h +++ /dev/null @@ -1,154 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelMapToBinaryImageFilter.h,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.4 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelMapToBinaryImageFilter_h -#define __itkLabelMapToBinaryImageFilter_h - -#include "itkLabelMapFilter.h" -#include "itkBarrier.h" - -namespace itk { - -/** \class LabelMapToBinaryImageFilter - * \brief Convert a LabelMap to a binary image - * - * LabelMapToBinaryImageFilter to a binary image. All the objects in the image - * are used as foreground. - * The background values of the original binary image can be restored by passing this image - * to the filter with the SetBackgroundImage() method. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa LabelMapToLabelImageFilter, LabelMapMaskImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TOutputImage> -class ITK_EXPORT LabelMapToBinaryImageFilter : - public LabelMapFilter<TInputImage, TOutputImage> -{ -public: - /** Standard class typedefs. */ - typedef LabelMapToBinaryImageFilter Self; - typedef LabelMapFilter<TInputImage, TOutputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef TOutputImage OutputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - typedef typename OutputImageType::IndexType IndexType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelMapToBinaryImageFilter, - ImageToImageFilter); - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the value used as "foreground" in the output image. - * Defaults to NumericTraits<PixelType>::max(). - */ - itkSetMacro(ForegroundValue, OutputImagePixelType); - itkGetConstMacro(ForegroundValue, OutputImagePixelType); - - /** Set/Get the background image top be used to restore the background values */ - void SetBackgroundImage( const OutputImageType *input) - { - // Process object is not const-correct so the const casting is required. - this->SetNthInput( 1, const_cast<OutputImageType *>(input) ); - } - - OutputImageType * GetBackgroundImage() - { - return static_cast<OutputImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1))); - } - - /** Set the input image */ - void SetInput1( const InputImageType * input ) - { - this->SetInput( input ); - } - - /** Set the marker image */ - void SetInput2( const OutputImageType * input ) - { - this->SetBackgroundImage( input ); - } - -protected: - LabelMapToBinaryImageFilter(); - ~LabelMapToBinaryImageFilter() {}; - - /** LabelMapToBinaryImageFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** LabelMapToBinaryImageFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - virtual void BeforeThreadedGenerateData(); - - virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId ); - - virtual void ThreadedGenerateData( LabelObjectType * labelObject ); - - -private: - LabelMapToBinaryImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - OutputImagePixelType m_ForegroundValue; - - typename Barrier::Pointer m_Barrier; - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelMapToBinaryImageFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelMapToBinaryImageFilter.txx b/Utilities/InsightJournal/itkLabelMapToBinaryImageFilter.txx deleted file mode 100644 index f9ba51ab8dd2bf6ae42caabf640cb06ba80b4aa7..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelMapToBinaryImageFilter.txx +++ /dev/null @@ -1,147 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelMapToBinaryImageFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelMapToBinaryImageFilter_txx -#define __itkLabelMapToBinaryImageFilter_txx - -#include "itkLabelMapToBinaryImageFilter.h" -#include "itkNumericTraits.h" -#include "itkProgressReporter.h" -#include "itkImageRegionConstIterator.h" -#include "itkImageRegionIterator.h" - -namespace itk { - -template <class TInputImage, class TOutputImage> -LabelMapToBinaryImageFilter<TInputImage, TOutputImage> -::LabelMapToBinaryImageFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_ForegroundValue = NumericTraits<OutputImagePixelType>::max(); -} - -template <class TInputImage, class TOutputImage> -void -LabelMapToBinaryImageFilter<TInputImage, TOutputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if ( !input ) - { return; } - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); -} - - -template <class TInputImage, class TOutputImage> -void -LabelMapToBinaryImageFilter<TInputImage, TOutputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage, class TOutputImage> -void -LabelMapToBinaryImageFilter<TInputImage, TOutputImage> -::BeforeThreadedGenerateData() -{ - m_Barrier = Barrier::New(); - m_Barrier->Initialize( this->GetNumberOfThreads() ); - - Superclass::BeforeThreadedGenerateData(); - -} - - -template<class TInputImage, class TOutputImage> -void -LabelMapToBinaryImageFilter<TInputImage, TOutputImage> -::ThreadedGenerateData( const OutputImageRegionType& outputRegionForThread, int threadId ) -{ - OutputImageType * output = this->GetOutput(); -// const InputImageType * input = this->GetInput(); - - // fill the output with background value - they will be overiden with the foreground value - // later, if there is some objects - if( this->GetNumberOfInputs() == 2 ) - { - // fill the background with the background values from the background image - ImageRegionConstIterator< OutputImageType > bgIt( this->GetBackgroundImage(), outputRegionForThread ); - ImageRegionIterator< OutputImageType > oIt( output, outputRegionForThread ); - for( oIt.GoToBegin(), bgIt.GoToBegin(); - !oIt.IsAtEnd(); - ++oIt, ++bgIt ) - { - const OutputImagePixelType & bg = bgIt.Get(); - if( bg != m_ForegroundValue ) - { - oIt.Set( bg ); - } - else - { - oIt.Set( m_BackgroundValue ); - } - } - } - else - { - // fill the background with the background value - ImageRegionIterator< OutputImageType > oIt( output, outputRegionForThread ); - for( oIt.GoToBegin(); !oIt.IsAtEnd(); ++oIt ) - { - oIt.Set( m_BackgroundValue ); - } - } - - // wait for the other threads to complete that part - m_Barrier->Wait(); - - // and delegate to the superclass implementation to use the thread support for the label objects - Superclass::ThreadedGenerateData( outputRegionForThread, threadId ); - -} - - -template<class TInputImage, class TOutputImage> -void -LabelMapToBinaryImageFilter<TInputImage, TOutputImage> -::ThreadedGenerateData( LabelObjectType * labelObject ) -{ - OutputImageType * output = this->GetOutput(); - - typename InputImageType::LabelObjectType::LineContainerType::const_iterator lit; - typename InputImageType::LabelObjectType::LineContainerType & lineContainer = labelObject->GetLineContainer(); - - for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ ) - { - IndexType idx = lit->GetIndex(); - unsigned long length = lit->GetLength(); - for( unsigned int i=0; i<length; i++) - { - output->SetPixel( idx, m_ForegroundValue ); - idx[0]++; - } - } -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkLabelMapToLabelImageFilter.h b/Utilities/InsightJournal/itkLabelMapToLabelImageFilter.h deleted file mode 100644 index f39b84ddf7cfbaa3b7b1c5c94878c66413d2d268..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelMapToLabelImageFilter.h +++ /dev/null @@ -1,96 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelMapToLabelImageFilter.h,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.4 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelMapToLabelImageFilter_h -#define __itkLabelMapToLabelImageFilter_h - -#include "itkLabelMapFilter.h" - -namespace itk { - -/** \class LabelMapToLabelImageFilter - * \brief Convert a LabelMap to a labeled image - * - * LabelMapToBinaryImageFilter to a label image. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa LabelMapToBinaryImageFilter, LabelMapMaskImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TOutputImage> -class ITK_EXPORT LabelMapToLabelImageFilter : - public LabelMapFilter<TInputImage, TOutputImage> -{ -public: - /** Standard class typedefs. */ - typedef LabelMapToLabelImageFilter Self; - typedef LabelMapFilter<TInputImage, TOutputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef TOutputImage OutputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - typedef typename OutputImageType::IndexType IndexType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelMapToLabelImageFilter, - ImageToImageFilter); - -protected: - LabelMapToLabelImageFilter(); - ~LabelMapToLabelImageFilter() {}; - - virtual void BeforeThreadedGenerateData(); - - virtual void ThreadedGenerateData( LabelObjectType * labelObject ); - -private: - LabelMapToLabelImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelMapToLabelImageFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelMapToLabelImageFilter.txx b/Utilities/InsightJournal/itkLabelMapToLabelImageFilter.txx deleted file mode 100644 index f2e564180a02f9cd4ed5eac2ae595dcf0667d7cf..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelMapToLabelImageFilter.txx +++ /dev/null @@ -1,72 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelMapToLabelImageFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelMapToLabelImageFilter_txx -#define __itkLabelMapToLabelImageFilter_txx - -#include "itkLabelMapToLabelImageFilter.h" -#include "itkNumericTraits.h" -#include "itkProgressReporter.h" -#include "itkImageRegionConstIteratorWithIndex.h" - -namespace itk { - -template <class TInputImage, class TOutputImage> -LabelMapToLabelImageFilter<TInputImage, TOutputImage> -::LabelMapToLabelImageFilter() -{ -} - - -template<class TInputImage, class TOutputImage> -void -LabelMapToLabelImageFilter<TInputImage, TOutputImage> -::BeforeThreadedGenerateData() -{ - OutputImageType * output = this->GetOutput(); - const InputImageType * input = this->GetInput(); - - output->FillBuffer( input->GetBackgroundValue() ); - - Superclass::BeforeThreadedGenerateData(); - -} - - -template<class TInputImage, class TOutputImage> -void -LabelMapToLabelImageFilter<TInputImage, TOutputImage> -::ThreadedGenerateData( LabelObjectType * labelObject ) -{ - const typename LabelObjectType::LabelType & label = labelObject->GetLabel(); - - typename InputImageType::LabelObjectType::LineContainerType::const_iterator lit; - typename InputImageType::LabelObjectType::LineContainerType & lineContainer = labelObject->GetLineContainer(); - - for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ ) - { - IndexType idx = lit->GetIndex(); - unsigned long length = lit->GetLength(); - for( unsigned int i=0; i<length; i++) - { - this->GetOutput()->SetPixel( idx, label ); - idx[0]++; - } - } -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkLabelPerimeterEstimationCalculator.h b/Utilities/InsightJournal/itkLabelPerimeterEstimationCalculator.h deleted file mode 100644 index 9e69defa7880c691d39b9b26b3ae931dc0090b03..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelPerimeterEstimationCalculator.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef __itkLabelPerimeterEstimationCalculator_h -#define __itkLabelPerimeterEstimationCalculator_h - -#include "itkObject.h" - -namespace itk { - -/** \class LabelPerimeterEstimationCalculator - * \brief TODO - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa - */ -template<class TInputImage> -class ITK_EXPORT LabelPerimeterEstimationCalculator : - public Object -{ -public: - /** Standard class typedefs. */ - typedef LabelPerimeterEstimationCalculator Self; - typedef Object Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - - typedef typename InputImageType::RegionType RegionType; - typedef typename InputImageType::SizeType SizeType; - typedef typename InputImageType::IndexType IndexType; - - typedef typename std::map< InputImagePixelType, double > PerimetersType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelPerimeterEstimationCalculator, - Object); - - /** - * Set/Get whether the connected components are defined strictly by - * face connectivity or by face+edge+vertex connectivity. Default is - * FullyConnectedOff. For objects that are 1 pixel wide, use - * FullyConnectedOn. - */ - itkSetMacro(FullyConnected, bool); - itkGetConstReferenceMacro(FullyConnected, bool); - itkBooleanMacro(FullyConnected); - - void SetImage( const InputImageType * img ) - { - m_Image = img; - } - - const InputImageType * GetImage() const - { - return m_Image; - } - - void Compute(); - - const PerimetersType & GetPerimeters() const - { - return m_Perimeters; - } - - const double & GetPerimeter( const InputImagePixelType & label ) const - { - if( m_Perimeters.find( label ) != m_Perimeters.end() ) - { - return m_Perimeters.find( label )->second; - } - itkExceptionMacro( << "Unknown label: " << static_cast<typename NumericTraits<InputImagePixelType>::PrintType>(label) ); - } - - bool HasLabel( const InputImagePixelType & label ) const - { - if( m_Perimeters.find( label ) != m_Perimeters.end() ) - { - return true; - } - return false; - } - -protected: - LabelPerimeterEstimationCalculator(); - ~LabelPerimeterEstimationCalculator() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - -private: - LabelPerimeterEstimationCalculator(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - bool m_FullyConnected; - - const InputImageType * m_Image; - - PerimetersType m_Perimeters; - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelPerimeterEstimationCalculator.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelPerimeterEstimationCalculator.txx b/Utilities/InsightJournal/itkLabelPerimeterEstimationCalculator.txx deleted file mode 100644 index 5b4e13c01ad5fb5d14a83e79cccdd05806c18f7e..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelPerimeterEstimationCalculator.txx +++ /dev/null @@ -1,236 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelPerimeterEstimationCalculator.txx,v $ - Language: C++ - Date: $Date: 2004/12/21 22:47:30 $ - Version: $Revision: 1.12 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelPerimeterEstimationCalculator_txx -#define __itkLabelPerimeterEstimationCalculator_txx - -#include "itkLabelPerimeterEstimationCalculator.h" -#include "itkProgressReporter.h" -#include "itkImageRegionIterator.h" -#include "itkImageRegionConstIteratorWithIndex.h" -#include "itkShapedNeighborhoodIterator.h" -#include "itkConstShapedNeighborhoodIterator.h" -#include "itkConstantBoundaryCondition.h" -#include "itkSize.h" -#include "itkConnectedComponentAlgorithm.h" -#include <set> - -namespace itk { - -template <class TInputImage> -LabelPerimeterEstimationCalculator<TInputImage> -::LabelPerimeterEstimationCalculator() -{ - m_FullyConnected = false; -} - - - -template<class TInputImage> -void -LabelPerimeterEstimationCalculator<TInputImage> -::Compute() -{ - - m_Perimeters.clear(); - - // ProgressReporter progress( this, 0, this->GetImage()->GetRequestedRegion().GetNumberOfPixels() ); - - // reduce the region to avoid reading outside - RegionType region = this->GetImage()->GetRequestedRegion(); - SizeType size = region.GetSize(); - for( int i=0; i<ImageDimension; i++ ) - { - size[i]--; - } - region.SetSize( size ); - - // the radius which will be used for all the shaped iterators - Size< ImageDimension > radius; - radius.Fill(1); - - // set up the iterator - typedef ConstShapedNeighborhoodIterator<InputImageType> IteratorType; - typename IteratorType::ConstIterator nIt; - IteratorType iIt( radius, this->GetImage(), region ); -// ConstantBoundaryCondition<InputImageType> lcbc; -// lcbc.SetConstant( NumericTraits<InputImagePixelType>::max() ); -// iIt.OverrideBoundaryCondition(&lcbc); - // we want to search the neighbors with offset >= 0 - // 2D -> 4 neighbors - // 3D -> 8 neighbors - typename IteratorType::OffsetType offset; - unsigned int centerIndex = iIt.GetCenterNeighborhoodIndex(); - // store the offsets to reuse them to evaluate the contributions of the - // configurations - typename std::vector< IndexType > indexes; - IndexType idx0; - idx0.Fill( 0 ); - for( unsigned int d=centerIndex; d < 2*centerIndex+1; d++ ) - { - offset = iIt.GetOffset( d ); - bool deactivate = false; - for ( int j=0; j<ImageDimension && !deactivate; j++ ) - { - if( offset[j] < 0 ) - { - deactivate = true; - } - } - if( deactivate ) - { -// std::cout << "- " << offset << std::endl; - iIt.DeactivateOffset( offset ); - } - else - { -// std::cout << "+ " << idx0 + offset << std::endl; - iIt.ActivateOffset( offset ); - indexes.push_back( idx0 + offset ); - } - - } - - // to store the configurations count for all the labels - typedef typename std::map< unsigned long, unsigned long > MapType; - typedef typename std::map< InputImagePixelType, MapType > LabelMapType; - LabelMapType confCount; - - for( iIt.GoToBegin(); !iIt.IsAtEnd(); ++iIt ) - { - // 2 pass - find the labels in the neighborhood - // - count the configurations for all the labels - - typedef typename std::set< InputImagePixelType > LabelSetType; - LabelSetType labelSet; - for ( nIt= iIt.Begin(); - nIt != iIt.End(); - nIt++ ) - { - labelSet.insert( nIt.Get() ); - } - - for( typename LabelSetType::const_iterator it=labelSet.begin(); - it!=labelSet.end(); - it++ ) - { - - unsigned long conf = 0; - int i=0; - - for ( nIt= iIt.Begin(); - nIt != iIt.End(); - nIt++, i++ ) - { - if( nIt.Get() == *it ) - { - conf += 1 << i; - } - } - - confCount[ *it ][ conf ]++; - - } - - // progress.CompletedPixel(); - - } - - // compute the participation to the perimeter for all the configurations -// std::cout << "spacing: " << this->GetImage()->GetSpacing() << std::endl; - double physicalSize = 1; - for( int i=0; i<ImageDimension; i++ ) - { - physicalSize *= this->GetImage()->GetSpacing()[i]; - } - typedef typename std::map< unsigned long, double > ContributionMapType; - ContributionMapType contributions; - int numberOfNeighbors = (int)vcl_pow( 2.0, ImageDimension ); - int numberOfConfigurations = (int)vcl_pow( 2.0, numberOfNeighbors ); - // create an image to store the neighbors - typedef typename itk::Image< bool, ImageDimension > ImageType; - typename ImageType::Pointer neighborsImage = ImageType::New(); - // typename ImageType::SizeType size; - size.Fill( 2 ); - neighborsImage->SetRegions( size ); - neighborsImage->Allocate(); - for( int i=0; i<numberOfConfigurations; i++ ) - { - neighborsImage->FillBuffer( false ); - for( int j=0; j<numberOfNeighbors; j++ ) - { - if( i & 1 << j ) - { - neighborsImage->SetPixel( indexes[ j ], true ); - } - } - // the image is created - we can now compute the contributions of the pixels - // for that configuration - contributions[i] = 0; - for( int j=0; j<numberOfNeighbors; j++ ) - { - IndexType currentIdx = indexes[j]; - if( neighborsImage->GetPixel( currentIdx ) ) - { - for( int k=0; k<ImageDimension; k++ ) - { - IndexType idx = currentIdx; - idx[k] = vcl_abs( idx[k] - 1 ); - if( !neighborsImage->GetPixel( idx ) ) - { - contributions[i] += physicalSize / this->GetImage()->GetSpacing()[k] / 2.0; - } - } - } - } - contributions[i] /= ImageDimension; -// std::cout << "configuration: " << i << " contribution: " << contributions[i] << std::endl; - } - - - // and use those contributions to found the perimeter - m_Perimeters.clear(); - for( typename LabelMapType::const_iterator it=confCount.begin(); - it!=confCount.end(); - it++ ) - { - m_Perimeters[ it->first ] = 0; - for( typename MapType::const_iterator it2=it->second.begin(); - it2!=it->second.end(); - it2++ ) - { - m_Perimeters[ it->first ] += contributions[ it2->first ] * it2->second; -// std::cout << it->first+0.0 << " " << it2->first << " " << it2->second << std::endl; - } -// std::cout << "label: " << it->first+0.0 << " perimeter: " << m_Perimeters[ it->first ] << std::endl; - } - -} - - - -template<class TInputImage> -void -LabelPerimeterEstimationCalculator<TInputImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "FullyConnected: " << m_FullyConnected << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkLabelShapeKeepNObjectsImageFilter.h b/Utilities/InsightJournal/itkLabelShapeKeepNObjectsImageFilter.h deleted file mode 100644 index a778dd6b4dfd9203b22de6e7ac18c6943f0e4a32..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelShapeKeepNObjectsImageFilter.h +++ /dev/null @@ -1,170 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelShapeKeepNObjectsImageFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelShapeKeepNObjectsImageFilter_h -#define __itkLabelShapeKeepNObjectsImageFilter_h - -#include "itkImageToImageFilter.h" -#include "itkShapeLabelObject.h" -#include "itkLabelMap.h" -#include "itkLabelImageToLabelMapFilter.h" -#include "itkShapeLabelMapFilter.h" -#include "itkShapeKeepNObjectsLabelMapFilter.h" -#include "itkLabelMapToLabelImageFilter.h" - - -namespace itk { - -/** \class LabelShapeKeepNObjectsImageFilter - * \brief keep N objects according to their shape attributes - * - * LabelShapeKeepNObjectsImageFilter keep the N objects in a labeled image - * with the highest (or lowest) attribute value. The attributes are the ones - * of the ShapeLabelObject. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ShapeLabelObject, BinaryShapeKeepNObjectsImageFilter, LabelStatisticsKeepNObjectsImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage> -class ITK_EXPORT LabelShapeKeepNObjectsImageFilter : - public ImageToImageFilter<TInputImage, TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef LabelShapeKeepNObjectsImageFilter Self; - typedef ImageToImageFilter<TInputImage, TInputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef TInputImage OutputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef ShapeLabelObject<InputImagePixelType, ImageDimension> LabelObjectType; - typedef typename itk::LabelMap< LabelObjectType > LabelMapType; - typedef typename itk::LabelImageToLabelMapFilter< InputImageType, LabelMapType > LabelizerType; - typedef typename itk::ShapeLabelMapFilter< LabelMapType > LabelObjectValuatorType; - typedef typename LabelObjectType::AttributeType AttributeType; - typedef typename itk::ShapeKeepNObjectsLabelMapFilter< LabelMapType > KeepNObjectsType; - typedef typename itk::LabelMapToLabelImageFilter< LabelMapType, OutputImageType > BinarizerType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelShapeKeepNObjectsImageFilter, - ImageToImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the number of objects to keep - */ - itkGetConstMacro(NumberOfObjects, unsigned long); - itkSetMacro(NumberOfObjects, unsigned long); - - /** - * Set/Get the ordering of the objects. By default, the ones with the - * highest value are kept. Turming ReverseOrdering to true make this filter - * keep the objects with the smallest values - */ - itkGetConstMacro( ReverseOrdering, bool ); - itkSetMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the attribute to use to select the object to keep. The default - * is "Size". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - -protected: - LabelShapeKeepNObjectsImageFilter(); - ~LabelShapeKeepNObjectsImageFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** LabelShapeKeepNObjectsImageFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** LabelShapeKeepNObjectsImageFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - -private: - LabelShapeKeepNObjectsImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - unsigned long m_NumberOfObjects; - bool m_ReverseOrdering; - AttributeType m_Attribute; -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelShapeKeepNObjectsImageFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelShapeKeepNObjectsImageFilter.txx b/Utilities/InsightJournal/itkLabelShapeKeepNObjectsImageFilter.txx deleted file mode 100644 index 1c061ba8e595a36cd839731eb2406d09e5bfb10a..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelShapeKeepNObjectsImageFilter.txx +++ /dev/null @@ -1,128 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelShapeKeepNObjectsImageFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelShapeKeepNObjectsImageFilter_txx -#define __itkLabelShapeKeepNObjectsImageFilter_txx - -#include "itkLabelShapeKeepNObjectsImageFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage> -LabelShapeKeepNObjectsImageFilter<TInputImage> -::LabelShapeKeepNObjectsImageFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_NumberOfObjects = 1; - m_ReverseOrdering = false; - m_Attribute = LabelObjectType::SIZE; -} - -template<class TInputImage> -void -LabelShapeKeepNObjectsImageFilter<TInputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage> -void -LabelShapeKeepNObjectsImageFilter<TInputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage> -void -LabelShapeKeepNObjectsImageFilter<TInputImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .3f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetLabelImage( this->GetInput() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - if( m_Attribute == LabelObjectType::PERIMETER || m_Attribute == LabelObjectType::ROUNDNESS ) - { - valuator->SetComputePerimeter( true ); - } - if( m_Attribute == LabelObjectType::FERET_DIAMETER ) - { - valuator->SetComputeFeretDiameter( true ); - } - progress->RegisterInternalFilter(valuator, .3f); - - typename KeepNObjectsType::Pointer opening = KeepNObjectsType::New(); - opening->SetInput( valuator->GetOutput() ); - opening->SetNumberOfObjects( m_NumberOfObjects ); - opening->SetReverseOrdering( m_ReverseOrdering ); - opening->SetAttribute( m_Attribute ); - opening->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(opening, .2f); - - typename BinarizerType::Pointer binarizer = BinarizerType::New(); - binarizer->SetInput( opening->GetOutput() ); - binarizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(binarizer, .2f); - - binarizer->GraftOutput( this->GetOutput() ); - binarizer->Update(); - this->GraftOutput( binarizer->GetOutput() ); -} - - -template<class TInputImage> -void -LabelShapeKeepNObjectsImageFilter<TInputImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "NumberOfObjects: " << m_NumberOfObjects << std::endl; - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkLabelShapeOpeningImageFilter.h b/Utilities/InsightJournal/itkLabelShapeOpeningImageFilter.h deleted file mode 100644 index e58824fb3c630c69fdcfba7ba83aa01c632f32a6..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelShapeOpeningImageFilter.h +++ /dev/null @@ -1,172 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelShapeOpeningImageFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelShapeOpeningImageFilter_h -#define __itkLabelShapeOpeningImageFilter_h - -#include "itkImageToImageFilter.h" -#include "itkShapeLabelObject.h" -#include "itkLabelMap.h" -#include "itkLabelImageToLabelMapFilter.h" -#include "itkShapeLabelMapFilter.h" -#include "itkShapeOpeningLabelMapFilter.h" -#include "itkLabelMapToLabelImageFilter.h" - - -namespace itk { - -/** \class LabelShapeOpeningImageFilter - * \brief remove the objects according to the value of their shape attribute - * - * LabelShapeOpeningImageFilter removes the objects in a labeled image - * with an attribute value smaller or greater than a threshold called Lambda. - * The attributes are the ones of the ShapeLabelObject. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ShapeLabelObject, BinaryShapeOpeningImageFilter, LabelStatisticsOpeningImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage> -class ITK_EXPORT LabelShapeOpeningImageFilter : - public ImageToImageFilter<TInputImage, TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef LabelShapeOpeningImageFilter Self; - typedef ImageToImageFilter<TInputImage, TInputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef TInputImage OutputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef ShapeLabelObject<InputImagePixelType, ImageDimension> LabelObjectType; - typedef typename itk::LabelMap< LabelObjectType > LabelMapType; - typedef typename itk::LabelImageToLabelMapFilter< InputImageType, LabelMapType > LabelizerType; - typedef typename itk::ShapeLabelMapFilter< LabelMapType > LabelObjectValuatorType; - typedef typename LabelObjectType::AttributeType AttributeType; - typedef typename itk::ShapeOpeningLabelMapFilter< LabelMapType > OpeningType; - typedef typename itk::LabelMapToLabelImageFilter< LabelMapType, OutputImageType > BinarizerType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelShapeOpeningImageFilter, - ImageToImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the threshold used to keep or remove the objects. - */ - itkGetConstMacro(Lambda, double); - itkSetMacro(Lambda, double); - - /** - * Set/Get the ordering of the objects. By default, the objects with - * an attribute value smaller than Lamba are removed. Turning ReverseOrdering - * to true make this filter remove the object with an attribute value greater - * than Lambda instead. - */ - itkGetConstMacro( ReverseOrdering, bool ); - itkSetMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the attribute to use to select the object to remove. The default - * is "Size". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - -protected: - LabelShapeOpeningImageFilter(); - ~LabelShapeOpeningImageFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** LabelShapeOpeningImageFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** LabelShapeOpeningImageFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - - -private: - LabelShapeOpeningImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - double m_Lambda; - bool m_ReverseOrdering; - AttributeType m_Attribute; -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelShapeOpeningImageFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelShapeOpeningImageFilter.txx b/Utilities/InsightJournal/itkLabelShapeOpeningImageFilter.txx deleted file mode 100644 index d763a167bbc3c7cdd7640b2557275b3450a1dc3d..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelShapeOpeningImageFilter.txx +++ /dev/null @@ -1,128 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelShapeOpeningImageFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelShapeOpeningImageFilter_txx -#define __itkLabelShapeOpeningImageFilter_txx - -#include "itkLabelShapeOpeningImageFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage> -LabelShapeOpeningImageFilter<TInputImage> -::LabelShapeOpeningImageFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_Lambda = NumericTraits< double >::Zero; - m_ReverseOrdering = false; - m_Attribute = LabelObjectType::SIZE; -} - -template<class TInputImage> -void -LabelShapeOpeningImageFilter<TInputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage> -void -LabelShapeOpeningImageFilter<TInputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage> -void -LabelShapeOpeningImageFilter<TInputImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .3f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetLabelImage( this->GetInput() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - if( m_Attribute == LabelObjectType::PERIMETER || m_Attribute == LabelObjectType::ROUNDNESS ) - { - valuator->SetComputePerimeter( true ); - } - if( m_Attribute == LabelObjectType::FERET_DIAMETER ) - { - valuator->SetComputeFeretDiameter( true ); - } - progress->RegisterInternalFilter(valuator, .3f); - - typename OpeningType::Pointer opening = OpeningType::New(); - opening->SetInput( valuator->GetOutput() ); - opening->SetLambda( m_Lambda ); - opening->SetReverseOrdering( m_ReverseOrdering ); - opening->SetAttribute( m_Attribute ); - opening->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(opening, .2f); - - typename BinarizerType::Pointer binarizer = BinarizerType::New(); - binarizer->SetInput( opening->GetOutput() ); - binarizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(binarizer, .2f); - - binarizer->GraftOutput( this->GetOutput() ); - binarizer->Update(); - this->GraftOutput( binarizer->GetOutput() ); -} - - -template<class TInputImage> -void -LabelShapeOpeningImageFilter<TInputImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "Lambda: " << m_Lambda << std::endl; - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkLabelStatisticsKeepNObjectsImageFilter.h b/Utilities/InsightJournal/itkLabelStatisticsKeepNObjectsImageFilter.h deleted file mode 100644 index 4d601c477dedc91c792e84096c976fa21e4a9836..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelStatisticsKeepNObjectsImageFilter.h +++ /dev/null @@ -1,200 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelStatisticsKeepNObjectsImageFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelStatisticsKeepNObjectsImageFilter_h -#define __itkLabelStatisticsKeepNObjectsImageFilter_h - -#include "itkImageToImageFilter.h" -#include "itkStatisticsLabelObject.h" -#include "itkLabelMap.h" -#include "itkLabelImageToLabelMapFilter.h" -#include "itkStatisticsLabelMapFilter.h" -#include "itkStatisticsKeepNObjectsLabelMapFilter.h" -#include "itkLabelMapToLabelImageFilter.h" - - -namespace itk { - -/** \class LabelStatisticsKeepNObjectsImageFilter - * \brief keep N objects according to their statistics attributes - * - * LabelStatisticsKeepNObjectsImageFilter keep the N objects in a labeled image - * with the highest (or lowest) attribute value. The attributes are the ones - * of the StatisticsLabelObject. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa StatisticsLabelObject, BinaryStatisticsKeepNObjectsImageFilter, LabelShapeKeepNObjectsImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TFeatureImage> -class ITK_EXPORT LabelStatisticsKeepNObjectsImageFilter : - public ImageToImageFilter<TInputImage, TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef LabelStatisticsKeepNObjectsImageFilter Self; - typedef ImageToImageFilter<TInputImage, TInputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef TInputImage OutputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - - typedef TFeatureImage FeatureImageType; - typedef typename FeatureImageType::Pointer FeatureImagePointer; - typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer; - typedef typename FeatureImageType::PixelType FeatureImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef StatisticsLabelObject<InputImagePixelType, ImageDimension> LabelObjectType; - typedef typename itk::LabelMap< LabelObjectType > LabelMapType; - typedef typename itk::LabelImageToLabelMapFilter< InputImageType, LabelMapType > LabelizerType; - typedef typename itk::StatisticsLabelMapFilter< LabelMapType, TFeatureImage > LabelObjectValuatorType; - typedef typename LabelObjectType::AttributeType AttributeType; - typedef typename itk::StatisticsKeepNObjectsLabelMapFilter< LabelMapType > KeepNObjectsType; - typedef typename itk::LabelMapToLabelImageFilter< LabelMapType, OutputImageType > BinarizerType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelStatisticsKeepNObjectsImageFilter, - ImageToImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the number of objects to keep - */ - itkGetConstMacro(NumberOfObjects, unsigned long); - itkSetMacro(NumberOfObjects, unsigned long); - - /** - * Set/Get the ordering of the objects. By default, the ones with the - * highest value are kept. Turming ReverseOrdering to true make this filter - * keep the objects with the smallest values - */ - itkGetConstMacro( ReverseOrdering, bool ); - itkSetMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the attribute to use to select the object to keep. The default - * is "Mean". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - - /** Set the feature image */ - void SetFeatureImage(TFeatureImage *input) - { - // Process object is not const-correct so the const casting is required. - this->SetNthInput( 1, const_cast<TFeatureImage *>(input) ); - } - - /** Get the feature image */ - FeatureImageType * GetFeatureImage() - { - return static_cast<FeatureImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1))); - } - - /** Set the input image */ - void SetInput1(InputImageType *input) - { - this->SetInput( input ); - } - - /** Set the feature image */ - void SetInput2(FeatureImageType *input) - { - this->SetFeatureImage( input ); - } - -protected: - LabelStatisticsKeepNObjectsImageFilter(); - ~LabelStatisticsKeepNObjectsImageFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** LabelStatisticsKeepNObjectsImageFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** LabelStatisticsKeepNObjectsImageFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - -private: - LabelStatisticsKeepNObjectsImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - unsigned long m_NumberOfObjects; - bool m_ReverseOrdering; - AttributeType m_Attribute; -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelStatisticsKeepNObjectsImageFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelStatisticsKeepNObjectsImageFilter.txx b/Utilities/InsightJournal/itkLabelStatisticsKeepNObjectsImageFilter.txx deleted file mode 100644 index dc7c4f75a69b383b417254a032fe35f5da85ad9b..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelStatisticsKeepNObjectsImageFilter.txx +++ /dev/null @@ -1,131 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelStatisticsKeepNObjectsImageFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelStatisticsKeepNObjectsImageFilter_txx -#define __itkLabelStatisticsKeepNObjectsImageFilter_txx - -#include "itkLabelStatisticsKeepNObjectsImageFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage, class TFeatureImage> -LabelStatisticsKeepNObjectsImageFilter<TInputImage, TFeatureImage> -::LabelStatisticsKeepNObjectsImageFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_NumberOfObjects = 1; - m_ReverseOrdering = false; - m_Attribute = LabelObjectType::MEAN; - this->SetNumberOfRequiredInputs(2); -} - -template<class TInputImage, class TFeatureImage> -void -LabelStatisticsKeepNObjectsImageFilter<TInputImage, TFeatureImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage, class TFeatureImage> -void -LabelStatisticsKeepNObjectsImageFilter<TInputImage, TFeatureImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage, class TFeatureImage> -void -LabelStatisticsKeepNObjectsImageFilter<TInputImage, TFeatureImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .3f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetFeatureImage( this->GetFeatureImage() ); - valuator->SetLabelImage( this->GetInput() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - valuator->SetComputeHistogram( false ); - if( m_Attribute == LabelObjectType::PERIMETER || m_Attribute == LabelObjectType::ROUNDNESS ) - { - valuator->SetComputePerimeter( true ); - } - if( m_Attribute == LabelObjectType::FERET_DIAMETER ) - { - valuator->SetComputeFeretDiameter( true ); - } - progress->RegisterInternalFilter(valuator, .3f); - - typename KeepNObjectsType::Pointer opening = KeepNObjectsType::New(); - opening->SetInput( valuator->GetOutput() ); - opening->SetNumberOfObjects( m_NumberOfObjects ); - opening->SetReverseOrdering( m_ReverseOrdering ); - opening->SetAttribute( m_Attribute ); - opening->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(opening, .2f); - - typename BinarizerType::Pointer binarizer = BinarizerType::New(); - binarizer->SetInput( opening->GetOutput() ); - binarizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(binarizer, .2f); - - binarizer->GraftOutput( this->GetOutput() ); - binarizer->Update(); - this->GraftOutput( binarizer->GetOutput() ); -} - - -template<class TInputImage, class TFeatureImage> -void -LabelStatisticsKeepNObjectsImageFilter<TInputImage, TFeatureImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "NumberOfObjects: " << m_NumberOfObjects << std::endl; - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkLabelStatisticsOpeningImageFilter.h b/Utilities/InsightJournal/itkLabelStatisticsOpeningImageFilter.h deleted file mode 100644 index 3adec7082e5b92e841249d8551270bb06436605a..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelStatisticsOpeningImageFilter.h +++ /dev/null @@ -1,202 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelStatisticsOpeningImageFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelStatisticsOpeningImageFilter_h -#define __itkLabelStatisticsOpeningImageFilter_h - -#include "itkImageToImageFilter.h" -#include "itkStatisticsLabelObject.h" -#include "itkLabelMap.h" -#include "itkLabelImageToLabelMapFilter.h" -#include "itkStatisticsLabelMapFilter.h" -#include "itkStatisticsOpeningLabelMapFilter.h" -#include "itkLabelMapToLabelImageFilter.h" - - -namespace itk { - -/** \class LabelStatisticsOpeningImageFilter - * \brief remove the objects according to the value of their statistics attribute - * - * LabelStatisticsOpeningImageFilter removes the objects in a labeled image - * with an attribute value smaller or greater than a threshold called Lambda. - * The attributes are the ones of the StatisticsLabelObject. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa StatisticsLabelObject, BinaryStatisticsOpeningImageFilter, LabelShapeOpeningImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TFeatureImage> -class ITK_EXPORT LabelStatisticsOpeningImageFilter : - public ImageToImageFilter<TInputImage, TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef LabelStatisticsOpeningImageFilter Self; - typedef ImageToImageFilter<TInputImage, TInputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef TInputImage OutputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - - typedef TFeatureImage FeatureImageType; - typedef typename FeatureImageType::Pointer FeatureImagePointer; - typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer; - typedef typename FeatureImageType::PixelType FeatureImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef StatisticsLabelObject<InputImagePixelType, ImageDimension> LabelObjectType; - typedef typename itk::LabelMap< LabelObjectType > LabelMapType; - typedef typename itk::LabelImageToLabelMapFilter< InputImageType, LabelMapType > LabelizerType; - typedef typename itk::StatisticsLabelMapFilter< LabelMapType, TFeatureImage > LabelObjectValuatorType; - typedef typename LabelObjectType::AttributeType AttributeType; - typedef typename itk::StatisticsOpeningLabelMapFilter< LabelMapType > OpeningType; - typedef typename itk::LabelMapToLabelImageFilter< LabelMapType, OutputImageType > BinarizerType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(LabelStatisticsOpeningImageFilter, - ImageToImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the threshold used to keep or remove the objects. - */ - itkGetConstMacro(Lambda, double); - itkSetMacro(Lambda, double); - - /** - * Set/Get the ordering of the objects. By default, the objects with - * an attribute value smaller than Lamba are removed. Turning ReverseOrdering - * to true make this filter remove the object with an attribute value greater - * than Lambda instead. - */ - itkGetConstMacro( ReverseOrdering, bool ); - itkSetMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the attribute to use to select the object to remove. The default - * is "Mean". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - - /** Set the feature image */ - void SetFeatureImage(TFeatureImage *input) - { - // Process object is not const-correct so the const casting is required. - this->SetNthInput( 1, const_cast<TFeatureImage *>(input) ); - } - - /** Get the feature image */ - FeatureImageType * GetFeatureImage() - { - return static_cast<FeatureImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1))); - } - - /** Set the input image */ - void SetInput1(InputImageType *input) - { - this->SetInput( input ); - } - - /** Set the feature image */ - void SetInput2(FeatureImageType *input) - { - this->SetFeatureImage( input ); - } - -protected: - LabelStatisticsOpeningImageFilter(); - ~LabelStatisticsOpeningImageFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** LabelStatisticsOpeningImageFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** LabelStatisticsOpeningImageFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - - -private: - LabelStatisticsOpeningImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - double m_Lambda; - bool m_ReverseOrdering; - AttributeType m_Attribute; -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkLabelStatisticsOpeningImageFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkLabelStatisticsOpeningImageFilter.txx b/Utilities/InsightJournal/itkLabelStatisticsOpeningImageFilter.txx deleted file mode 100644 index 008b0abf2fbcebd1df2c7018ee0856209856e93a..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkLabelStatisticsOpeningImageFilter.txx +++ /dev/null @@ -1,131 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelStatisticsOpeningImageFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkLabelStatisticsOpeningImageFilter_txx -#define __itkLabelStatisticsOpeningImageFilter_txx - -#include "itkLabelStatisticsOpeningImageFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage, class TFeatureImage> -LabelStatisticsOpeningImageFilter<TInputImage, TFeatureImage> -::LabelStatisticsOpeningImageFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_Lambda = NumericTraits< double >::Zero; - m_ReverseOrdering = false; - m_Attribute = LabelObjectType::MEAN; - this->SetNumberOfRequiredInputs(2); -} - -template<class TInputImage, class TFeatureImage> -void -LabelStatisticsOpeningImageFilter<TInputImage, TFeatureImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage, class TFeatureImage> -void -LabelStatisticsOpeningImageFilter<TInputImage, TFeatureImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage, class TFeatureImage> -void -LabelStatisticsOpeningImageFilter<TInputImage, TFeatureImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .3f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetFeatureImage( this->GetFeatureImage() ); - valuator->SetLabelImage( this->GetInput() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - valuator->SetComputeHistogram( false ); - if( m_Attribute == LabelObjectType::PERIMETER || m_Attribute == LabelObjectType::ROUNDNESS ) - { - valuator->SetComputePerimeter( true ); - } - if( m_Attribute == LabelObjectType::FERET_DIAMETER ) - { - valuator->SetComputeFeretDiameter( true ); - } - progress->RegisterInternalFilter(valuator, .3f); - - typename OpeningType::Pointer opening = OpeningType::New(); - opening->SetInput( valuator->GetOutput() ); - opening->SetLambda( m_Lambda ); - opening->SetReverseOrdering( m_ReverseOrdering ); - opening->SetAttribute( m_Attribute ); - opening->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(opening, .2f); - - typename BinarizerType::Pointer binarizer = BinarizerType::New(); - binarizer->SetInput( opening->GetOutput() ); - binarizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(binarizer, .2f); - - binarizer->GraftOutput( this->GetOutput() ); - binarizer->Update(); - this->GraftOutput( binarizer->GetOutput() ); -} - - -template<class TInputImage, class TFeatureImage> -void -LabelStatisticsOpeningImageFilter<TInputImage, TFeatureImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "Lambda: " << m_Lambda << std::endl; - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkPadLabelMapFilter.h b/Utilities/InsightJournal/itkPadLabelMapFilter.h deleted file mode 100644 index 01b734171b8a8412d0f7c00c5a65d7a9097ed855..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkPadLabelMapFilter.h +++ /dev/null @@ -1,128 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkPadLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:38 $ - Version: $Revision: 1.4 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkPadLabelMapFilter_h -#define __itkPadLabelMapFilter_h - -#include "itkChangeRegionLabelMapFilter.h" - -namespace itk -{ - -/** \class PadLabelMapFilter - * \brief Pad a LabelMap image - * - * Pad a label map. - * - * The SetPadSize() method can be used to set the pad size of the lower and - * the upper boundaries in a single call. - * By default, the filter doesn't pad anything. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa CropLabelMapFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template <class TInputImage> -class ITK_EXPORT PadLabelMapFilter : public ChangeRegionLabelMapFilter<TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef PadLabelMapFilter Self; - typedef ChangeRegionLabelMapFilter<TInputImage> Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - - /** Run-time type information (and related methods). */ - itkTypeMacro(PadLabelMapFilter, ChangeRegionImageFilter); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Superclass typedefs. */ - typedef typename Superclass::OutputImageType OutputImageType; - typedef typename Superclass::OutputImagePointer OutputImagePointer; - typedef typename Superclass::OutputImageRegionType OutputImageRegionType; - typedef typename Superclass::OutputImagePixelType OutputImagePixelType; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typedef typename InputImageType::PixelType PixelType; - typedef typename InputImageType::IndexType IndexType; - typedef typename InputImageType::SizeType SizeType; - typedef typename InputImageType::RegionType RegionType; - - typedef TInputImage TOutputImage; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TOutputImage::ImageDimension); - - /** Set/Get the cropping sizes for the upper and lower boundaries. */ - itkSetMacro(UpperBoundaryPadSize, SizeType); - itkGetMacro(UpperBoundaryPadSize, SizeType); - itkSetMacro(LowerBoundaryPadSize, SizeType); - itkGetMacro(LowerBoundaryPadSize, SizeType); - - void SetPadSize( const SizeType & size ) - { - this->SetUpperBoundaryPadSize( size ); - this->SetLowerBoundaryPadSize( size ); - } - - - protected: - PadLabelMapFilter() - { - m_UpperBoundaryPadSize.Fill(0); - m_LowerBoundaryPadSize.Fill(0); - }; - ~PadLabelMapFilter() {}; - - virtual void GenerateOutputInformation(); - - void PrintSelf(std::ostream& os, Indent indent) const; - - -private: - PadLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - SizeType m_UpperBoundaryPadSize; - SizeType m_LowerBoundaryPadSize; -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkPadLabelMapFilter.txx" -#endif - -#endif diff --git a/Utilities/InsightJournal/itkPadLabelMapFilter.txx b/Utilities/InsightJournal/itkPadLabelMapFilter.txx deleted file mode 100644 index 7a18554bbbf09198c9358bc66983eaf28113859b..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkPadLabelMapFilter.txx +++ /dev/null @@ -1,79 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkPadLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:39 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef _itkPadLabelMapFilter_txx -#define _itkPadLabelMapFilter_txx -#include "itkPadLabelMapFilter.h" - - -namespace itk -{ - - -template <class TInputImage> -void -PadLabelMapFilter<TInputImage> -::GenerateOutputInformation() -{ - const TInputImage * inputPtr = this->GetInput(); - if( !inputPtr ) - { - return; - } - - // Compute the new region size. - RegionType croppedRegion; - SizeType sz; - IndexType idx; - - SizeType input_sz = - inputPtr->GetLargestPossibleRegion().GetSize(); - IndexType input_idx = - inputPtr->GetLargestPossibleRegion().GetIndex(); - - idx = input_idx - m_LowerBoundaryPadSize; - sz = input_sz + (m_UpperBoundaryPadSize + m_LowerBoundaryPadSize); - - croppedRegion.SetSize(sz); - croppedRegion.SetIndex(idx); - - // Set extraction region in the superclass. - this->SetRegion(croppedRegion); - - // - Superclass::GenerateOutputInformation(); -} - - -template <class TInputImage> -void -PadLabelMapFilter<TInputImage> -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os,indent); - - os << indent << "UpperBoundaryPadSize: " << m_UpperBoundaryPadSize << - std::endl; - os << indent << "LowerBoundaryPadSize: " << m_LowerBoundaryPadSize << - std::endl; -} - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkRegionFromReferenceLabelMapFilter.h b/Utilities/InsightJournal/itkRegionFromReferenceLabelMapFilter.h deleted file mode 100644 index 3185af5934464a41d074a55825e9612a112e8612..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkRegionFromReferenceLabelMapFilter.h +++ /dev/null @@ -1,136 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkRegionFromReferenceLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:38 $ - Version: $Revision: 1.4 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkRegionFromReferenceLabelMapFilter_h -#define __itkRegionFromReferenceLabelMapFilter_h - -#include "itkChangeRegionLabelMapFilter.h" - -namespace itk -{ - -/** \class RegionFromReferenceLabelMapFilter - * \brief Set the region from a reference image - * - * Change the region of a label map to be the same than the one of a reference image. - * This filter implement the same feature than its superclass, but with the input region - * well integrated in the pipeline architecture. - * If the output can't contain some lines of the objects, they are truncated, or remove. - * All the objects fully outside the output region are removed. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template <class TInputImage> -class ITK_EXPORT RegionFromReferenceLabelMapFilter : public ChangeRegionLabelMapFilter<TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef RegionFromReferenceLabelMapFilter Self; - typedef ChangeRegionLabelMapFilter<TInputImage> Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - - /** Run-time type information (and related methods). */ - itkTypeMacro(RegionFromReferenceLabelMapFilter, ChangeRegionImageFilter); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Superclass typedefs. */ - typedef typename Superclass::OutputImageType OutputImageType; - typedef typename Superclass::OutputImagePointer OutputImagePointer; - typedef typename Superclass::OutputImageRegionType OutputImageRegionType; - typedef typename Superclass::OutputImagePixelType OutputImagePixelType; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename InputImageType::LabelObjectType LabelObjectType; - - typedef typename InputImageType::PixelType PixelType; - typedef typename InputImageType::IndexType IndexType; - typedef typename InputImageType::SizeType SizeType; - typedef typename InputImageType::RegionType RegionType; - - typedef TInputImage TOutputImage; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TOutputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TOutputImage::ImageDimension); - - typedef ImageBase< ImageDimension > ReferenceImageType; - - /** Copy the output information from another Image. */ - void SetReferenceImage ( const ReferenceImageType *image ) - { - itkDebugMacro("setting input ReferenceImage to " << image); - if( image != static_cast<const ReferenceImageType *>(this->GetInput( 1 )) ) - { - this->ProcessObject::SetNthInput(1, const_cast< ReferenceImageType *>( image ) ); - this->Modified(); - } - } - const ReferenceImageType * GetReferenceImage() const; - - /** Set the input image */ - void SetInput1(const TInputImage *input) - { - this->SetInput( input ); - } - - /** Set the reference image */ - void SetInput2(const ReferenceImageType *input) - { - this->SetReferenceImage( input ); - } - - - - protected: - RegionFromReferenceLabelMapFilter() - { - this->SetNumberOfRequiredInputs(2); - }; - ~RegionFromReferenceLabelMapFilter() {}; - - virtual void GenerateOutputInformation(); - -private: - RegionFromReferenceLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -}; - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkRegionFromReferenceLabelMapFilter.txx" -#endif - -#endif diff --git a/Utilities/InsightJournal/itkRegionFromReferenceLabelMapFilter.txx b/Utilities/InsightJournal/itkRegionFromReferenceLabelMapFilter.txx deleted file mode 100644 index 687e4988f166af8244da54f3f32d63576c3c992c..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkRegionFromReferenceLabelMapFilter.txx +++ /dev/null @@ -1,54 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkRegionFromReferenceLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2004/07/11 14:56:39 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef _itkRegionFromReferenceLabelMapFilter_txx -#define _itkRegionFromReferenceLabelMapFilter_txx -#include "itkRegionFromReferenceLabelMapFilter.h" - - -namespace itk -{ - - -template <class TInputImage> -void -RegionFromReferenceLabelMapFilter<TInputImage> -::GenerateOutputInformation() -{ - Superclass::GenerateOutputInformation(); - this->SetRegion( this->GetReferenceImage()->GetLargestPossibleRegion() ); - this->GetOutput()->SetLargestPossibleRegion( this->GetRegion() ); -} - - -template <class TInputImage> -const typename RegionFromReferenceLabelMapFilter<TInputImage>::ReferenceImageType * -RegionFromReferenceLabelMapFilter<TInputImage> -::GetReferenceImage() const -{ - Self * surrogate = const_cast< Self * >( this ); - const ReferenceImageType * referenceImage = - static_cast<const ReferenceImageType *>(surrogate->ProcessObject::GetInput(1)); - return referenceImage; -} - - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkShapeKeepNObjectsLabelMapFilter.h b/Utilities/InsightJournal/itkShapeKeepNObjectsLabelMapFilter.h deleted file mode 100644 index 14ce3d8eb91ed86c6fa56e2f4d93a1873ea4793c..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeKeepNObjectsLabelMapFilter.h +++ /dev/null @@ -1,134 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeKeepNObjectsLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeKeepNObjectsLabelMapFilter_h -#define __itkShapeKeepNObjectsLabelMapFilter_h - -#include "itkInPlaceLabelMapFilter.h" - -namespace itk { -/** \class ShapeKeepNObjectsLabelMapFilter - * \brief keep N objects according to their shape attributes - * - * ShapeKeepNObjectsLabelMapFilter keep the N objects in a label collection image - * with the highest (or lowest) attribute value. The attributes are the ones - * of the ShapeLabelObject. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ShapeLabelObject, BinaryShapeKeepNObjectsImageFilter, LabelStatisticsKeepNObjectsImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TImage> -class ITK_EXPORT ShapeKeepNObjectsLabelMapFilter : - public InPlaceLabelMapFilter<TImage> -{ -public: - /** Standard class typedefs. */ - typedef ShapeKeepNObjectsLabelMapFilter Self; - typedef InPlaceLabelMapFilter<TImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::LabelObjectType LabelObjectType; - - typedef typename LabelObjectType::AttributeType AttributeType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(ShapeKeepNObjectsLabelMapFilter, - InPlaceLabelMapFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ -/* itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>));*/ - /** End concept checking */ -#endif - - /** - * Set/Get the ordering of the objects. By default, the ones with the - * highest value are kept. Turming ReverseOrdering to true make this filter - * keep the objects with the smallest values - */ - itkSetMacro( ReverseOrdering, bool ); - itkGetConstReferenceMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the number of objects to keep - */ - itkSetMacro( NumberOfObjects, unsigned long ); - itkGetConstReferenceMacro( NumberOfObjects, unsigned long ); - - /** - * Set/Get the attribute to use to select the object to keep. The default - * is "Size". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - -protected: - ShapeKeepNObjectsLabelMapFilter(); - ~ShapeKeepNObjectsLabelMapFilter() {}; - - void GenerateData(); - - template <class TAttributeAccessor> void TemplatedGenerateData(); - - void PrintSelf(std::ostream& os, Indent indent) const; - - bool m_ReverseOrdering; - unsigned long m_NumberOfObjects; - AttributeType m_Attribute; - -private: - ShapeKeepNObjectsLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkShapeKeepNObjectsLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkShapeKeepNObjectsLabelMapFilter.txx b/Utilities/InsightJournal/itkShapeKeepNObjectsLabelMapFilter.txx deleted file mode 100644 index b6216bb6071b09d7845b085d5b59bec726208690..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeKeepNObjectsLabelMapFilter.txx +++ /dev/null @@ -1,150 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeKeepNObjectsLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeKeepNObjectsLabelMapFilter_txx -#define __itkShapeKeepNObjectsLabelMapFilter_txx - -#include "itkShapeKeepNObjectsLabelMapFilter.h" -#include "itkProgressReporter.h" -#include "itkLabelObjectUtils.h" - - -namespace itk { - -template <class TImage> -ShapeKeepNObjectsLabelMapFilter<TImage> -::ShapeKeepNObjectsLabelMapFilter() -{ - m_ReverseOrdering = false; - m_NumberOfObjects = 1; - m_Attribute = LabelObjectType::SIZE; -} - - -template <class TImage> -void -ShapeKeepNObjectsLabelMapFilter<TImage> -::GenerateData() -{ - switch( m_Attribute ) - { - case LabelObjectType::SIZE: - TemplatedGenerateData< typename Functor::SizeLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PHYSICAL_SIZE: - TemplatedGenerateData< typename Functor::PhysicalSizeLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIZE_REGION_RATIO: - TemplatedGenerateData< typename Functor::SizeRegionRatioLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::REGION_ELONGATION: - TemplatedGenerateData< typename Functor::RegionElongationLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIZE_ON_BORDER: - TemplatedGenerateData< typename Functor::SizeOnBorderLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PHYSICAL_SIZE_ON_BORDER: - TemplatedGenerateData< typename Functor::PhysicalSizeOnBorderLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::FERET_DIAMETER: - TemplatedGenerateData< typename Functor::FeretDiameterLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::BINARY_ELONGATION: - TemplatedGenerateData< typename Functor::BinaryElongationLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PERIMETER: - TemplatedGenerateData< typename Functor::PerimeterLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::ROUNDNESS: - TemplatedGenerateData< typename Functor::RoundnessLabelObjectAccessor< LabelObjectType > >(); - break; - default: - itkExceptionMacro(<< "Unknown attribute type"); - break; - } -} - - -template <class TImage> -template <class TAttributeAccessor> -void -ShapeKeepNObjectsLabelMapFilter<TImage> -::TemplatedGenerateData() -{ - // Allocate the output - this->AllocateOutputs(); - - ImageType * output = this->GetOutput(); - - typedef typename ImageType::LabelObjectContainerType LabelObjectContainerType; - const LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer(); - typedef typename std::vector< typename LabelObjectType::Pointer > VectorType; - - ProgressReporter progress( this, 0, 2 * labelObjectContainer.size() ); - - // get the label objects in a vector, so they can be sorted - VectorType labelObjects; - labelObjects.reserve( labelObjectContainer.size() ); - for( typename LabelObjectContainerType::const_iterator it = labelObjectContainer.begin(); - it != labelObjectContainer.end(); - it++ ) - { - labelObjects.push_back( it->second ); - progress.CompletedPixel(); - } - - // instantiate the comparator and sort the vector - if( m_NumberOfObjects < labelObjectContainer.size() ) - { - typename VectorType::iterator end = labelObjects.begin() + m_NumberOfObjects; - if( m_ReverseOrdering ) - { - Functor::LabelObjectReverseComparator< LabelObjectType, TAttributeAccessor > comparator; - std::nth_element( labelObjects.begin(), end, labelObjects.end(), comparator ); - } - else - { - Functor::LabelObjectComparator< LabelObjectType, TAttributeAccessor > comparator; - std::nth_element( labelObjects.begin(), end, labelObjects.end(), comparator ); - } -// progress.CompletedPixel(); - - // and remove the last objects of the map - for( typename VectorType::const_iterator it = end; - it != labelObjects.end(); - it++ ) - { - output->RemoveLabelObject( *it ); - progress.CompletedPixel(); - } - } -} - - -template <class TImage> -void -ShapeKeepNObjectsLabelMapFilter<TImage> -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os,indent); - - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "NumberOfObjects: " << m_NumberOfObjects << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkShapeLabelMapFilter.h b/Utilities/InsightJournal/itkShapeLabelMapFilter.h deleted file mode 100644 index cc8aa86d41a7380b87771f61e67ca325eb24ba85..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeLabelMapFilter.h +++ /dev/null @@ -1,172 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeLabelMapFilter_h -#define __itkShapeLabelMapFilter_h -#include "itkLabelPerimeterEstimationCalculator.h" - -#include "itkInPlaceLabelMapFilter.h" - -#define PI 3.14159265358979323846 - -namespace itk { -/** \class ShapeLabelMapFilter - * \brief The valuator class for the ShapeLabelObject - * - * ShapeLabelMapFilter can be used to set the attributes values - * of the ShapeLabelObject in a LabelMap. - * - * ShapeLabelMapFilter take an optional parameter, used only to optimize - * the computation time and the memory usage when the perimeter or the feret diameter - * are used: the exact copy of the input LabelMap but stored in an Image. - * It can be set with SetLabelImage(). It is cleared at the end of the computation, and - * so must be reset before running Update() again. It is not part of the pipeline management - * design, to let the subclasses of ShapeLabelMapFilter use the - * pipeline desing to specify a really required input. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TImage, class TLabelImage=Image< typename TImage::PixelType, TImage::ImageDimension > > -class ITK_EXPORT ShapeLabelMapFilter : - public InPlaceLabelMapFilter<TImage> -{ -public: - /** Standard class typedefs. */ - typedef ShapeLabelMapFilter Self; - typedef InPlaceLabelMapFilter<TImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::SizeType SizeType; - typedef typename ImageType::LabelObjectType LabelObjectType; - typedef typename LabelObjectType::MatrixType MatrixType; - typedef typename LabelObjectType::VectorType VectorType; - - typedef TLabelImage LabelImageType; - typedef typename LabelImageType::Pointer LabelImagePointer; - typedef typename LabelImageType::ConstPointer LabelImageConstPointer; - typedef typename LabelImageType::PixelType LabelPixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); - - typedef LabelPerimeterEstimationCalculator< LabelImageType > PerimeterCalculatorType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(ShapeLabelMapFilter, - InPlaceLabelMapFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ -/* itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>));*/ - /** End concept checking */ -#endif - - /** - * Set/Get whether the maximum Feret diameter should be computed or not. The - * defaut value is false, because of the high computation time required. - */ - itkSetMacro(ComputeFeretDiameter, bool); - itkGetConstReferenceMacro(ComputeFeretDiameter, bool); - itkBooleanMacro(ComputeFeretDiameter); - - /** - * Set/Get whether the perimeter should be computed or not. The defaut value - * is false, because of the high computation time required. - */ - itkSetMacro(ComputePerimeter, bool); - itkGetConstReferenceMacro(ComputePerimeter, bool); - itkBooleanMacro(ComputePerimeter); - - - /** Set the label image */ - void SetLabelImage( const TLabelImage *input ) - { - m_LabelImage = input; - } - - /** */ - static long factorial( long n ); - - /** */ - static long doubleFactorial( long n ); - - /** */ - static double gammaN2p1( long n ); - - /** */ - static double hyperSphereVolume( double radius ); - - /** */ - static double hyperSpherePerimeter( double radius ); - - /** */ - static double hyperSphereRadiusFromVolume( double volume ); - - -protected: - ShapeLabelMapFilter(); - ~ShapeLabelMapFilter() {}; - - virtual void ThreadedGenerateData( LabelObjectType * labelObject ); - - virtual void BeforeThreadedGenerateData(); - - virtual void AfterThreadedGenerateData(); - - void PrintSelf(std::ostream& os, Indent indent) const; - -private: - ShapeLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - bool m_ComputeFeretDiameter; - - bool m_ComputePerimeter; - - LabelImageConstPointer m_LabelImage; - - typename PerimeterCalculatorType::Pointer m_PerimeterCalculator; - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkShapeLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkShapeLabelMapFilter.txx b/Utilities/InsightJournal/itkShapeLabelMapFilter.txx deleted file mode 100644 index 27b3e54bea4d32643602dfcd7a0103bc0f3350a4..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeLabelMapFilter.txx +++ /dev/null @@ -1,566 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeLabelMapFilter_txx -#define __itkShapeLabelMapFilter_txx - -#include "itkShapeLabelMapFilter.h" -#include "itkProgressReporter.h" -#include "itkNeighborhoodIterator.h" -#include "itkLabelMapToLabelImageFilter.h" -#include "itkConstantBoundaryCondition.h" -#include "vnl/algo/vnl_real_eigensystem.h" -#include "vnl/algo/vnl_symmetric_eigensystem.h" - - -namespace itk { - -template <class TImage, class TLabelImage> -ShapeLabelMapFilter<TImage, TLabelImage> -::ShapeLabelMapFilter() -{ - m_ComputeFeretDiameter = false; - m_ComputePerimeter = false; -} - - -template<class TImage, class TLabelImage> -void -ShapeLabelMapFilter<TImage, TLabelImage> -::BeforeThreadedGenerateData() -{ - Superclass::BeforeThreadedGenerateData(); - - // generate the label image, if needed - if( m_ComputeFeretDiameter || m_ComputePerimeter ) - { - if( !m_LabelImage ) - { - // generate an image of the labelized image - typedef LabelMapToLabelImageFilter< TImage, LabelImageType > LCI2IType; - typename LCI2IType::Pointer lci2i = LCI2IType::New(); - lci2i->SetInput( this->GetOutput() ); - // respect the number of threads of the filter - lci2i->SetNumberOfThreads( this->GetNumberOfThreads() ); - lci2i->Update(); - m_LabelImage = lci2i->GetOutput(); - } - } - - // delegate the computation of the perimeter to a dedicated calculator - if( m_ComputePerimeter ) - { - m_PerimeterCalculator = PerimeterCalculatorType::New(); - m_PerimeterCalculator->SetImage( m_LabelImage ); -// m_PerimeterCalculator->SetNumberOfThreads( this->GetNumberOfThreads() ); - m_PerimeterCalculator->Compute(); - } - -} - - -template<class TImage, class TLabelImage> -void -ShapeLabelMapFilter<TImage, TLabelImage> -::ThreadedGenerateData( LabelObjectType * labelObject ) -{ - ImageType * output = this->GetOutput(); - const LabelPixelType & label = labelObject->GetLabel(); - - // TODO: compute sizePerPixel, borderMin and borderMax in BeforeThreadedGenerateData() ? - - // compute the size per pixel, to be used later - double sizePerPixel = 1; - for( int i=0; i<ImageDimension; i++ ) - { - sizePerPixel *= output->GetSpacing()[i]; - } - - typename std::vector< double > sizePerPixelPerDimension; - for( int i=0; i<ImageDimension; i++ ) - { - sizePerPixelPerDimension.push_back( sizePerPixel / output->GetSpacing()[i] ); - } - - // compute the max the index on the border of the image - IndexType borderMin = output->GetLargestPossibleRegion().GetIndex(); - IndexType borderMax = borderMin; - for( int i=0; i<ImageDimension; i++ ) - { - borderMax[i] += borderMin[i] + output->GetLargestPossibleRegion().GetSize()[i] - 1; - } - - // init the vars - unsigned long size = 0; - ContinuousIndex< double, ImageDimension> centroid; - centroid.Fill( 0 ); - IndexType mins; - mins.Fill( NumericTraits< long >::max() ); - IndexType maxs; - maxs.Fill( NumericTraits< long >::NonpositiveMin() ); - unsigned long sizeOnBorder = 0; - double physicalSizeOnBorder = 0; - MatrixType centralMoments; - centralMoments.Fill( 0 ); - - typename LabelObjectType::LineContainerType::const_iterator lit; - typename LabelObjectType::LineContainerType & lineContainer = labelObject->GetLineContainer(); - - // iterate over all the lines - for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ ) - { - const IndexType & idx = lit->GetIndex(); - unsigned long length = lit->GetLength(); - - // update the size - size += length; - - // update the centroid - and report the progress - // first, update the axes which are not 0 - for( int i=1; i<ImageDimension; i++ ) - { - centroid[i] += length * idx[i]; - } - // then, update the axis 0 - centroid[0] += idx[0] * length + ( length * ( length - 1 ) ) / 2.0; - - // update the mins and maxs - for( int i=0; i<ImageDimension; i++) - { - if( idx[i] < mins[i] ) - { - mins[i] = idx[i]; - } - if( idx[i] > maxs[i] ) - { - maxs[i] = idx[i]; - } - } - // must fix the max for the axis 0 - if( idx[0] + (long)length > maxs[0] ) - { - maxs[0] = idx[0] + length - 1; - } - - // object is on a border ? - bool isOnBorder = false; - for( int i=1; i<ImageDimension; i++) - { - if( idx[i] == borderMin[i] || idx[i] == borderMax[i]) - { - isOnBorder = true; - break; - } - } - if( isOnBorder ) - { - // the line touch a border on a dimension other than 0, so - // all the line touch a border - sizeOnBorder += length; - } - else - { - // we must check for the dimension 0 - bool isOnBorder0 = false; - if( idx[0] == borderMin[0] ) - { - // one more pixel on the border - sizeOnBorder++; - isOnBorder0 = true; - } - if( !isOnBorder0 || length > 1 ) - { - // we can check for the end of the line - if( idx[0] + (long)length - 1 == borderMax[0] ) - { - // one more pixel on the border - sizeOnBorder++; - } - } - } - - // physical size on border - // first, the dimension 0 - if( idx[0] == borderMin[0] ) - { - // the begining of the line - physicalSizeOnBorder += sizePerPixelPerDimension[0]; - } - if( idx[0] + (long)length - 1 == borderMax[0] ) - { - // and the end of the line - physicalSizeOnBorder += sizePerPixelPerDimension[0]; - } - // then the other dimensions - for( int i=1; i<ImageDimension; i++ ) - { - if( idx[i] == borderMin[i] ) - { - // one border - physicalSizeOnBorder += sizePerPixelPerDimension[i] * length; - } - if( idx[i] == borderMax[i] ) - { - // and the other - physicalSizeOnBorder += sizePerPixelPerDimension[i] * length; - } - } - - // moments computation -// **************************************************************** -// that commented code is the basic implementation. The next peace of code -// give the same result in a much efficient way, by using expended formulae -// allowed by the binary case instead of loops. -// **************************************************************** -// long endIdx0 = idx[0] + length; -// for( IndexType iidx = idx; iidx[0]<endIdx0; iidx[0]++) -// { -// typename LabelObjectType::CentroidType pP; -// output->TransformIndexToPhysicalPoint(iidx, pP); -// -// for(unsigned int i=0; i<ImageDimension; i++) -// { -// for(unsigned int j=0; j<ImageDimension; j++) -// { -// centralMoments[i][j] += pP[i] * pP[j]; -// } -// } -// } - // get the physical position and the spacing - they are used several times later - typename LabelObjectType::CentroidType physicalPosition; - output->TransformIndexToPhysicalPoint( idx, physicalPosition ); - const typename ImageType::SpacingType & spacing = output->GetSpacing(); - // the sum of x positions, also reused several times - double sumX = length * ( physicalPosition[0] + ( spacing[0] * ( length - 1 ) ) / 2.0 ); - // the real job - the sum of square of x positions - // that's the central moments for dims 0, 0 - centralMoments[0][0] += length * ( physicalPosition[0] * physicalPosition[0] - + spacing[0] * ( length - 1 ) * ( ( spacing[0] * ( 2 * length - 1 ) ) / 6.0 + physicalPosition[0] ) ); - // the other ones - for( int i=1; i<ImageDimension; i++ ) - { - // do this one here to avoid the double assigment in the following loop - // when i == j - centralMoments[i][i] += length * physicalPosition[i] * physicalPosition[i]; - // central moments are symetrics, so avoid to compute them 2 times - for( int j=i+1; j<ImageDimension; j++ ) - { - // note that we won't use that code if the image dimension is less than 3 - // --> the tests should be in 3D at least - double cm = length * physicalPosition[i] * physicalPosition[j]; - centralMoments[i][j] += cm; - centralMoments[j][i] += cm; - } - // the last moments: the ones for the dimension 0 - double cm = sumX * physicalPosition[i]; - centralMoments[i][0] += cm; - centralMoments[0][i] += cm; - } - - } - - // final computation - typename LabelObjectType::RegionType::SizeType regionSize; - double minSize = NumericTraits< double >::max(); - double maxSize = NumericTraits< double >::NonpositiveMin(); - for( int i=0; i<ImageDimension; i++ ) - { - centroid[i] /= size; - regionSize[i] = maxs[i] - mins[i] + 1; - double s = regionSize[i] * output->GetSpacing()[i]; - minSize = std::min( s, minSize ); - maxSize = std::max( s, maxSize ); - for(unsigned int j=0; j<ImageDimension; j++) - { - centralMoments[i][j] /= size; - } - } - typename LabelObjectType::RegionType region( mins, regionSize ); - typename LabelObjectType::CentroidType physicalCentroid; - output->TransformContinuousIndexToPhysicalPoint( centroid, physicalCentroid ); - - // Center the second order moments - for(unsigned int i=0; i<ImageDimension; i++) - { - for(unsigned int j=0; j<ImageDimension; j++) - { - centralMoments[i][j] -= physicalCentroid[i] * physicalCentroid[j]; - } - } - - // Compute principal moments and axes - VectorType principalMoments; - vnl_symmetric_eigensystem<double> eigen( centralMoments.GetVnlMatrix() ); - vnl_diag_matrix<double> pm = eigen.D; - for(unsigned int i=0; i<ImageDimension; i++) - { -// principalMoments[i] = 4 * vcl_sqrt( pm(i,i) ); - principalMoments[i] = pm(i,i); - } - MatrixType principalAxes = eigen.V.transpose(); - - // Add a final reflection if needed for a proper rotation, - // by multiplying the last row by the determinant - vnl_real_eigensystem eigenrot( principalAxes.GetVnlMatrix() ); - vnl_diag_matrix< vcl_complex<double> > eigenval = eigenrot.D; - vcl_complex<double> det( 1.0, 0.0 ); - - for(unsigned int i=0; i<ImageDimension; i++) - { - det *= eigenval( i, i ); - } - - for(unsigned int i=0; i<ImageDimension; i++) - { - principalAxes[ ImageDimension-1 ][i] *= std::real( det ); - } - - double elongation = 0; - if( principalMoments[0] != 0 ) - { -// elongation = principalMoments[ImageDimension-1] / principalMoments[0]; - elongation = vcl_sqrt(principalMoments[ImageDimension-1] / principalMoments[0]); - } - - double physicalSize = size * sizePerPixel; - double equivalentRadius = hyperSphereRadiusFromVolume( physicalSize ); - double equivalentPerimeter = hyperSpherePerimeter( equivalentRadius ); - - // compute equilalent ellipsoid radius - VectorType ellipsoidSize; - double edet = 1.0; - for(unsigned int i=0; i<ImageDimension; i++) - { - edet *= principalMoments[i]; - } - edet = vcl_pow( edet, 1.0/ImageDimension ); - for(unsigned int i=0; i<ImageDimension; i++) - { - ellipsoidSize[i] = 2.0 * equivalentRadius * vcl_sqrt( principalMoments[i] / edet ); - } - - // set the values in the object - labelObject->SetSize( size ); - labelObject->SetPhysicalSize( physicalSize ); - labelObject->SetRegion( region ); - labelObject->SetCentroid( physicalCentroid ); - labelObject->SetRegionElongation( maxSize / minSize ); - labelObject->SetSizeRegionRatio( size / (double)region.GetNumberOfPixels() ); - labelObject->SetSizeOnBorder( sizeOnBorder ); - labelObject->SetPhysicalSizeOnBorder( physicalSizeOnBorder ); - labelObject->SetBinaryPrincipalMoments( principalMoments ); - labelObject->SetBinaryPrincipalAxes( principalAxes ); - labelObject->SetBinaryElongation( elongation ); - labelObject->SetEquivalentRadius( equivalentRadius ); - labelObject->SetEquivalentPerimeter( equivalentPerimeter ); - labelObject->SetEquivalentEllipsoidSize( ellipsoidSize ); - - if( m_ComputeFeretDiameter ) - { - const PixelType & label = labelObject->GetLabel(); - - // init the vars - unsigned long size = 0; - typedef typename std::deque< IndexType > IndexListType; - IndexListType idxList; - - // the iterators - typename LabelObjectType::LineContainerType::const_iterator lit; - typename LabelObjectType::LineContainerType & lineContainer = labelObject->GetLineContainer(); - - typedef typename itk::ConstNeighborhoodIterator< LabelImageType > NeighborIteratorType; - SizeType neighborHoodRadius; - neighborHoodRadius.Fill( 1 ); - NeighborIteratorType it( neighborHoodRadius, m_LabelImage, m_LabelImage->GetBufferedRegion() ); - ConstantBoundaryCondition<LabelImageType> lcbc; - // use label + 1 to have a label different of the current label on the border - lcbc.SetConstant( label + 1 ); - it.OverrideBoundaryCondition( &lcbc ); - it.GoToBegin(); - - // iterate over all the lines - for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ ) - { - const IndexType & firstIdx = lit->GetIndex(); - unsigned long length = lit->GetLength(); - - long endIdx0 = firstIdx[0] + length; - for( IndexType idx = firstIdx; idx[0]<endIdx0; idx[0]++) - { - - // move the iterator to the new location - it += idx - it.GetIndex(); - - // push the pixel in the list if it is on the border of the object - for (unsigned i = 0; i < it.Size(); i++) - { - if( it.GetPixel(i) != label ) - { - idxList.push_back( idx ); - size++; - break; - } - } - } - } - - // we can now search the feret diameter - double feretDiameter = 0; - for( typename IndexListType::const_iterator iIt1 = idxList.begin(); - iIt1 != idxList.end(); - iIt1++ ) - { - typename IndexListType::const_iterator iIt2 = iIt1; - for( iIt2++; iIt2 != idxList.end(); iIt2++ ) - { - // Compute the length between the 2 indexes - double length = 0; - for( int i=0; i<ImageDimension; i++ ) - { - length += vcl_pow( ( iIt1->operator[]( i ) - iIt2->operator[]( i ) ) * output->GetSpacing()[i], 2 ); - } - if( feretDiameter < length ) - { - feretDiameter = length; - } - } - } - // final computation - feretDiameter = vcl_sqrt( feretDiameter ); - - // finally put the values in the label object - labelObject->SetFeretDiameter( feretDiameter ); - - } - - - // be sure tha the calculator has the perimeter estimation for that label. - // The calculator may not have the label if the object is only on a border. - // It will occurre for sure when processing a 2D image with a 3D filter. - if( m_ComputePerimeter && m_PerimeterCalculator->HasLabel( label ) ) - { - double perimeter = m_PerimeterCalculator->GetPerimeter( label ); - labelObject->SetPerimeter( perimeter ); - labelObject->SetRoundness( equivalentPerimeter / perimeter ); - } - -// std::cout << std::endl; -// labelObject->Print( std::cout ); -// std::cout << std::endl; - -} - - -template<class TImage, class TLabelImage> -void -ShapeLabelMapFilter<TImage, TLabelImage> -::AfterThreadedGenerateData() -{ - Superclass::AfterThreadedGenerateData(); - - // release the label image - m_LabelImage = NULL; - // and the perimeter calculator - m_PerimeterCalculator = NULL; -} - - -template<class TImage, class TLabelImage> -void -ShapeLabelMapFilter<TImage, TLabelImage> -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os,indent); - - os << indent << "ComputeFeretDiameter: " << m_ComputeFeretDiameter << std::endl; - os << indent << "ComputePerimeter: " << m_ComputePerimeter << std::endl; -} - - -template<class TImage, class TLabelImage> -long -ShapeLabelMapFilter<TImage, TLabelImage> -::factorial( long n ) -{ - if( n < 1 ) - { - return 1; - } - return n * factorial( n - 1 ); -} - - -template<class TImage, class TLabelImage> -long -ShapeLabelMapFilter<TImage, TLabelImage> -::doubleFactorial( long n ) -{ - if( n < 2 ) - { - return 1; - } - return n * doubleFactorial( n - 2 ); -} - - -template<class TImage, class TLabelImage> -double -ShapeLabelMapFilter<TImage, TLabelImage> -::gammaN2p1( long n ) -{ - bool even = n % 2 == 0; - if( even ) - { - return factorial( n / 2 ); - } - else - { - return vcl_sqrt( PI ) * doubleFactorial( n ) / vcl_pow( 2, ( n + 1 ) / 2.0 ); - } -} - - -template<class TImage, class TLabelImage> -double -ShapeLabelMapFilter<TImage, TLabelImage> -::hyperSphereVolume( double radius ) -{ - return vcl_pow( PI, ImageDimension / 2.0 ) * vcl_pow( radius, ImageDimension ) / gammaN2p1( ImageDimension ); -} - - -template<class TImage, class TLabelImage> -double -ShapeLabelMapFilter<TImage, TLabelImage> -::hyperSpherePerimeter( double radius ) -{ - return ImageDimension * hyperSphereVolume( radius ) / radius; -} - - -template<class TImage, class TLabelImage> -double -ShapeLabelMapFilter<TImage, TLabelImage> -::hyperSphereRadiusFromVolume( double volume ) -{ - return vcl_pow( volume * gammaN2p1( ImageDimension ) / vcl_pow( PI, ImageDimension / 2.0 ), 1.0 / ImageDimension ); -} - - - - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkShapeLabelObject.h b/Utilities/InsightJournal/itkShapeLabelObject.h deleted file mode 100644 index d264f820d98513e151c75a9006ecc2ef2b11e7bf..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeLabelObject.h +++ /dev/null @@ -1,801 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelObject.h,v $ - Language: C++ - Date: $Date: 2005/01/21 20:13:31 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeLabelObject_h -#define __itkShapeLabelObject_h - -#include "itkLabelObject.h" -#include "itkLabelMap.h" -#include "itkAffineTransform.h" -#include "itkMatrix.h" - -namespace itk -{ - - -namespace Functor { - -template< class TLabelObject > -class ITK_EXPORT SizeLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef unsigned long AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetSize(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT PhysicalSizeLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetPhysicalSize(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT RegionElongationLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetRegionElongation(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT SizeRegionRatioLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetSizeRegionRatio(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT SizeOnBorderLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef unsigned long AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetSizeOnBorder(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT PhysicalSizeOnBorderLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetPhysicalSizeOnBorder(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT CentroidLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::CentroidType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetCentroid(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT FeretDiameterLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetFeretDiameter(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT BinaryPrincipalMomentsLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::VectorType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetBinaryPrincipalMoments(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT BinaryPrincipalAxesLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::MatrixType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetBinaryPrincipalAxes(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT BinaryElongationLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetBinaryElongation(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT PerimeterLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetPerimeter(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT RoundnessLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetRoundness(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT EquivalentRadiusLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetEquivalentRadius(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT EquivalentPerimeterLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetEquivalentPerimeter(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT EquivalentEllipsoidSizeLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::VectorType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetEquivalentEllipsoidSize(); - } -}; - -} - - -/** \class ShapeLabelObject - * \brief A Label object to store the common attributes related to the shape of the object - * - * ShapeLabelObject stores the common attributes related to the shape of the object - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \ingroup DataRepresentation - */ -template < class TLabel, unsigned int VImageDimension > -class ITK_EXPORT ShapeLabelObject : public LabelObject< TLabel, VImageDimension > -{ -public: - /** Standard class typedefs */ - typedef ShapeLabelObject Self; - typedef LabelObject< TLabel, VImageDimension > Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - typedef WeakPointer<const Self> ConstWeakPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(ShapeLabelObject, LabelObject); - - typedef LabelMap< Self > LabelMapType; - - itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension); - - typedef typename Superclass::IndexType IndexType; - - typedef TLabel LabelType; - - typedef typename Superclass::LineType LineType; - - typedef typename Superclass::LengthType LengthType; - - typedef typename Superclass::LineContainerType LineContainerType; - - typedef unsigned int AttributeType; - static const AttributeType SIZE=0; - static const AttributeType PHYSICAL_SIZE=1; - static const AttributeType REGION_ELONGATION=2; - static const AttributeType SIZE_REGION_RATIO=3; - static const AttributeType CENTROID=4; - static const AttributeType REGION=5; - static const AttributeType SIZE_ON_BORDER=6; - static const AttributeType PHYSICAL_SIZE_ON_BORDER=7; - static const AttributeType FERET_DIAMETER=8; - static const AttributeType BINARY_PRINCIPAL_MOMENTS=9; - static const AttributeType BINARY_PRINCIPAL_AXES=10; - static const AttributeType BINARY_ELONGATION=11; - static const AttributeType PERIMETER=12; - static const AttributeType ROUNDNESS=13; - static const AttributeType EQUIVALENT_RADIUS=14; - static const AttributeType EQUIVALENT_PERIMETER=15; - static const AttributeType EQUIVALENT_ELLIPSOID_RADIUS=16; - - static AttributeType GetAttributeFromName( const std::string & s ) - { - if( s == "Size" ) - { - return SIZE; - } - else if( s == "PhysicalSize" ) - { - return PHYSICAL_SIZE; - } - else if( s == "RegionElongation" ) - { - return REGION_ELONGATION; - } - else if( s == "SizeRegionRatio" ) - { - return SIZE_REGION_RATIO; - } - else if( s == "Centroid" ) - { - return CENTROID; - } - else if( s == "Region" ) - { - return REGION; - } - else if( s == "SizeOnBorder" ) - { - return SIZE_ON_BORDER; - } - else if( s == "PhysicalSizeOnBorder" ) - { - return PHYSICAL_SIZE_ON_BORDER; - } - else if( s == "FeretDiameter" ) - { - return FERET_DIAMETER; - } - else if( s == "BinaryPrincipalMoments" ) - { - return BINARY_PRINCIPAL_MOMENTS; - } - else if( s == "BinaryPrincipalAxes" ) - { - return BINARY_PRINCIPAL_AXES; - } - else if( s == "BinaryElongation" ) - { - return BINARY_ELONGATION; - } - else if( s == "Perimeter" ) - { - return PERIMETER; - } - else if( s == "Roundness" ) - { - return ROUNDNESS; - } - else if( s == "EquivalentRadius" ) - { - return EQUIVALENT_RADIUS; - } - else if( s == "EquivalentPerimeter" ) - { - return EQUIVALENT_PERIMETER; - } - else if( s == "EquivalentEllipsoidSize" ) - { - return EQUIVALENT_ELLIPSOID_RADIUS; - } - // can't recognize the namespace - throw std::runtime_error("Unknown attribute."); - } - - static std::string GetNameFromAttribute( const AttributeType & a ) - { - switch( a ) - { - case SIZE: - return "Size"; - break; - case PHYSICAL_SIZE: - return "PhysicalSize"; - break; - case REGION_ELONGATION: - return "RegionElongation"; - break; - case SIZE_REGION_RATIO: - return "SizeRegionRatio"; - break; - case CENTROID: - return "Centroid"; - case REGION: - return "Region"; - break; - case SIZE_ON_BORDER: - return "SizeOnBorder"; - break; - case PHYSICAL_SIZE_ON_BORDER: - return "PhysicalSizeOnBorder"; - break; - case FERET_DIAMETER: - return "FeretDiameter"; - break; - case BINARY_PRINCIPAL_MOMENTS: - return "BinaryPrincipalMoments"; - break; - case BINARY_PRINCIPAL_AXES: - return "BinaryPrincipalAxes"; - break; - case BINARY_ELONGATION: - return "BinaryElongation"; - break; - case PERIMETER: - return "Perimeter"; - break; - case ROUNDNESS: - return "Roundness"; - break; - case EQUIVALENT_RADIUS: - return "EquivalentRadius"; - break; - case EQUIVALENT_PERIMETER: - return "EquivalentPerimeter"; - break; - case EQUIVALENT_ELLIPSOID_RADIUS: - return "EquivalentEllipsoidSize"; - break; - } - // can't recognize the namespace - throw std::runtime_error("Unknown attribute."); - } - - typedef ImageRegion< ImageDimension > RegionType; - - typedef typename itk::Point<double, ImageDimension> CentroidType; - - typedef Matrix< double, ImageDimension, ImageDimension > MatrixType; - - typedef Vector< double, ImageDimension > VectorType; - -/* itkGetConstMacro( Region, RegionType ); - itkSetMacro( Region, RegionType );*/ - const RegionType & GetRegion() const - { - return m_Region; - } - - void SetRegion( const RegionType & v ) - { - m_Region = v; - } - -// itkGetConstMacro( PhysicalSize, double ); -// itkSetMacro( PhysicalSize, double ); - const double & GetPhysicalSize() const - { - return m_PhysicalSize; - } - - void SetPhysicalSize( const double & v ) - { - m_PhysicalSize = v; - } - -// itkGetConstMacro( Size, unsigned long ); -// itkSetMacro( Size, unsigned long ); - const unsigned long & GetSize() const - { - return m_Size; - } - - void SetSize( const unsigned long & v ) - { - m_Size = v; - } - -// itkGetConstMacro( Centroid, CentroidType ); -// itkSetMacro( Centroid, CentroidType ); - const CentroidType & GetCentroid() const - { - return m_Centroid; - } - - void SetCentroid( const CentroidType & centroid ) - { - m_Centroid = centroid; - } - -// itkGetConstMacro( RegionElongation, double ); -// itkSetMacro( RegionElongation, double ); - const double & GetRegionElongation() const - { - return m_RegionElongation; - } - - void SetRegionElongation( const double & v ) - { - m_RegionElongation = v; - } - -// itkGetConstMacro( SizeRegionRatio, double ); -// itkSetMacro( SizeRegionRatio, double ); - const double & GetSizeRegionRatio() const - { - return m_SizeRegionRatio; - } - - void SetSizeRegionRatio( const double & v ) - { - m_SizeRegionRatio = v; - } - -// itkGetConstMacro( SizeOnBorder, bool ); -// itkSetMacro( SizeOnBorder, bool ); - const unsigned long & GetSizeOnBorder() const - { - return m_SizeOnBorder; - } - - void SetSizeOnBorder( const unsigned long & v ) - { - m_SizeOnBorder = v; - } - -// itkGetConstMacro( PhysicalSizeOnBorder, double ); -// itkSetMacro( PhysicalSizeOnBorder, double ); - const double & GetPhysicalSizeOnBorder() const - { - return m_PhysicalSizeOnBorder; - } - - void SetPhysicalSizeOnBorder( const double & v ) - { - m_PhysicalSizeOnBorder = v; - } - -// itkGetConstMacro( FeretDiameter, double ); -// itkSetMacro( FeretDiameter, double ); - const double & GetFeretDiameter() const - { - return m_FeretDiameter; - } - - void SetFeretDiameter( const double & v ) - { - m_FeretDiameter = v; - } - -// itkGetConstMacro( BinaryPrincipalMoments, VectorType ); -// itkSetMacro( BinaryPrincipalMoments, VectorType ); - const VectorType & GetBinaryPrincipalMoments() const - { - return m_BinaryPrincipalMoments; - } - - void SetBinaryPrincipalMoments( const VectorType & v ) - { - m_BinaryPrincipalMoments = v; - } - -// itkGetConstMacro( BinaryPrincipalAxes, MatrixType ); -// itkSetMacro( BinaryPrincipalAxes, MatrixType ); - const MatrixType & GetBinaryPrincipalAxes() const - { - return m_BinaryPrincipalAxes; - } - - void SetBinaryPrincipalAxes( const MatrixType & v ) - { - m_BinaryPrincipalAxes = v; - } - -// itkGetConstMacro( BinaryElongation, double ); -// itkSetMacro( BinaryElongation, double ); - const double & GetBinaryElongation() const - { - return m_BinaryElongation; - } - - void SetBinaryElongation( const double & v ) - { - m_BinaryElongation = v; - } - -// itkGetConstMacro( Perimeter, double ); -// itkSetMacro( Perimeter, double ); - const double & GetPerimeter() const - { - return m_Perimeter; - } - - void SetPerimeter( const double & v ) - { - m_Perimeter = v; - } - -// itkGetConstMacro( Roundness, double ); -// itkSetMacro( Roundness, double ); - const double & GetRoundness() const - { - return m_Roundness; - } - - void SetRoundness( const double & v ) - { - m_Roundness = v; - } - -// itkGetConstMacro( EquivalentRadius, double ); -// itkSetMacro( EquivalentRadius, double ); - const double & GetEquivalentRadius() const - { - return m_EquivalentRadius; - } - - void SetEquivalentRadius( const double & v ) - { - m_EquivalentRadius = v; - } - -// itkGetConstMacro( EquivalentPerimeter, double ); -// itkSetMacro( EquivalentPerimeter, double ); - const double & GetEquivalentPerimeter() const - { - return m_EquivalentPerimeter; - } - - void SetEquivalentPerimeter( const double & v ) - { - m_EquivalentPerimeter = v; - } - -// itkGetConstMacro( EquivalentEllipsoidSize, VectorType ); -// itkSetMacro( EquivalentEllipsoidSize, VectorType ); - const VectorType & GetEquivalentEllipsoidSize() const - { - return m_EquivalentEllipsoidSize; - } - - void SetEquivalentEllipsoidSize( const VectorType & v ) - { - m_EquivalentEllipsoidSize = v; - } - - -// some helper methods - not really required, but really useful! - - /** Affine transform for mapping to and from principal axis */ - typedef AffineTransform<double,itkGetStaticConstMacro(ImageDimension)> AffineTransformType; - typedef typename AffineTransformType::Pointer AffineTransformPointer; - - /** Get the affine transform from principal axes to physical axes - * This method returns an affine transform which transforms from - * the principal axes coordinate system to physical coordinates. */ - AffineTransformPointer GetBinaryPrincipalAxesToPhysicalAxesTransform() const - { - typename AffineTransformType::MatrixType matrix; - typename AffineTransformType::OffsetType offset; - for (unsigned int i = 0; i < ImageDimension; i++) - { - offset[i] = m_Centroid[i]; - for (unsigned int j = 0; j < ImageDimension; j++) - { - matrix[j][i] = m_BinaryPrincipalAxes[i][j]; // Note the transposition - } - } - - AffineTransformPointer result = AffineTransformType::New(); - - result->SetMatrix(matrix); - result->SetOffset(offset); - - return result; - } - - /** Get the affine transform from physical axes to principal axes - * This method returns an affine transform which transforms from - * the physical coordinate system to the principal axes coordinate - * system. */ - AffineTransformPointer GetPhysicalAxesToBinaryPrincipalAxesTransform(void) const - { - typename AffineTransformType::MatrixType matrix; - typename AffineTransformType::OffsetType offset; - for (unsigned int i = 0; i < ImageDimension; i++) - { - offset[i] = m_Centroid[i]; - for (unsigned int j = 0; j < ImageDimension; j++) - { - matrix[j][i] = m_BinaryPrincipalAxes[i][j]; // Note the transposition - } - } - - AffineTransformPointer result = AffineTransformType::New(); - result->SetMatrix(matrix); - result->SetOffset(offset); - - AffineTransformPointer inverse = AffineTransformType::New(); - result->GetInverse(inverse); - - return inverse; - } - - - - virtual void CopyAttributesFrom( const Self * src ) - { - Superclass::CopyAttributesFrom( src ); - - m_Region = src->m_Region; - m_Size = src->m_Size; - m_PhysicalSize = src->m_PhysicalSize; - m_Centroid = src->m_Centroid; - m_RegionElongation = src->m_RegionElongation; - m_SizeRegionRatio = src->m_SizeRegionRatio; - m_SizeOnBorder = src->m_SizeOnBorder; - m_PhysicalSizeOnBorder = src->m_PhysicalSizeOnBorder; - m_FeretDiameter = src->m_FeretDiameter; - m_BinaryPrincipalMoments = src->m_BinaryPrincipalMoments; - m_BinaryPrincipalAxes = src->m_BinaryPrincipalAxes; - m_BinaryElongation = src->m_BinaryElongation; - m_Perimeter = src->m_Perimeter; - m_Roundness = src->m_Roundness; - m_EquivalentRadius = src->m_EquivalentRadius; - m_EquivalentPerimeter = src->m_EquivalentPerimeter; - m_EquivalentEllipsoidSize = src->m_EquivalentEllipsoidSize; - } - -protected: - ShapeLabelObject() - { - m_Size = 0; - m_PhysicalSize = 0; - m_Centroid.Fill(0); - m_RegionElongation = 0; - m_SizeRegionRatio = 0; - m_SizeOnBorder = false; - m_PhysicalSizeOnBorder = 0; - m_FeretDiameter = false; - m_BinaryPrincipalMoments.Fill(0); - m_BinaryPrincipalAxes.Fill(0); - m_BinaryElongation = 0; - m_Perimeter = 0; - m_Roundness = 0; - m_EquivalentRadius = 0; - m_EquivalentPerimeter = 0; - m_EquivalentEllipsoidSize.Fill(0); - } - - - void PrintSelf(std::ostream& os, Indent indent) const - { - Superclass::PrintSelf( os, indent ); - - os << indent << "Centroid: " << m_Centroid << std::endl; - os << indent << "Region: "; - m_Region.Print( os, indent ); - os << indent << "PhysicalSize: " << m_PhysicalSize << std::endl; - os << indent << "Size: " << m_Size << std::endl; - os << indent << "RegionElongation: " << m_RegionElongation << std::endl; - os << indent << "SizeRegionRatio: " << m_SizeRegionRatio << std::endl; - os << indent << "SizeOnBorder: " << m_SizeOnBorder << std::endl; - os << indent << "PhysicalSizeOnBorder: " << m_PhysicalSizeOnBorder << std::endl; - os << indent << "FeretDiameter: " << m_FeretDiameter << std::endl; - os << indent << "BinaryPrincipalMoments: " << m_BinaryPrincipalMoments << std::endl; - os << indent << "BinaryPrincipalAxes: " << std::endl << m_BinaryPrincipalAxes; - os << indent << "BinaryElongation: " << m_BinaryElongation << std::endl; - os << indent << "Perimeter: " << m_Perimeter << std::endl; - os << indent << "Roundness: " << m_Roundness << std::endl; - os << indent << "EquivalentRadius: " << m_EquivalentRadius << std::endl; - os << indent << "EquivalentPerimeter: " << m_EquivalentPerimeter << std::endl; - os << indent << "EquivalentEllipsoidSize: " << m_EquivalentEllipsoidSize << std::endl; - } - -private: - ShapeLabelObject(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - RegionType m_Region; - unsigned long m_Size; - double m_PhysicalSize; - CentroidType m_Centroid; - double m_RegionElongation; - double m_SizeRegionRatio; - unsigned long m_SizeOnBorder; - double m_PhysicalSizeOnBorder; - double m_FeretDiameter; - VectorType m_BinaryPrincipalMoments; - MatrixType m_BinaryPrincipalAxes; - double m_BinaryElongation; - double m_Perimeter; - double m_Roundness; - double m_EquivalentRadius; - double m_EquivalentPerimeter; - VectorType m_EquivalentEllipsoidSize; - -}; - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkShapeOpeningLabelMapFilter.h b/Utilities/InsightJournal/itkShapeOpeningLabelMapFilter.h deleted file mode 100644 index 84aaebb6c5918da1496af7bc6cbfef4749bd0af5..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeOpeningLabelMapFilter.h +++ /dev/null @@ -1,135 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeOpeningLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeOpeningLabelMapFilter_h -#define __itkShapeOpeningLabelMapFilter_h - -#include "itkInPlaceLabelMapFilter.h" - -namespace itk { -/** \class ShapeOpeningLabelMapFilter - * \brief remove the objects according to the value of their shape attribute - * - * ShapeOpeningLabelMapFilter removes the objects in a label collection image - * with an attribute value smaller or greater than a threshold called Lambda. - * The attributes are the ones of the ShapeLabelObject. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ShapeLabelObject, BinaryShapeOpeningImageFilter, LabelStatisticsOpeningImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TImage> -class ITK_EXPORT ShapeOpeningLabelMapFilter : - public InPlaceLabelMapFilter<TImage> -{ -public: - /** Standard class typedefs. */ - typedef ShapeOpeningLabelMapFilter Self; - typedef InPlaceLabelMapFilter<TImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::LabelObjectType LabelObjectType; - - typedef typename LabelObjectType::AttributeType AttributeType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(ShapeOpeningLabelMapFilter, - InPlaceLabelMapFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ -/* itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>));*/ - /** End concept checking */ -#endif - - /** - * Set/Get the threshold used to keep or remove the objects. - */ - itkGetConstMacro(Lambda, double); - itkSetMacro(Lambda, double); - - /** - * Set/Get the ordering of the objects. By default, the objects with - * an attribute value smaller than Lamba are removed. Turning ReverseOrdering - * to true make this filter remove the object with an attribute value greater - * than Lambda instead. - */ - itkGetConstMacro( ReverseOrdering, bool ); - itkSetMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the attribute to use to select the object to remove. The default - * is "Size". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - -protected: - ShapeOpeningLabelMapFilter(); - ~ShapeOpeningLabelMapFilter() {}; - - void GenerateData(); - - template <class TAttributeAccessor> void TemplatedGenerateData(); - - void PrintSelf(std::ostream& os, Indent indent) const; - - double m_Lambda; - bool m_ReverseOrdering; - AttributeType m_Attribute; - -private: - ShapeOpeningLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkShapeOpeningLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkShapeOpeningLabelMapFilter.txx b/Utilities/InsightJournal/itkShapeOpeningLabelMapFilter.txx deleted file mode 100644 index f2413d78a348c112d6a65156539f1eae3664d5ae..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeOpeningLabelMapFilter.txx +++ /dev/null @@ -1,139 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeOpeningLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeOpeningLabelMapFilter_txx -#define __itkShapeOpeningLabelMapFilter_txx - -#include "itkShapeOpeningLabelMapFilter.h" -#include "itkProgressReporter.h" - - -namespace itk { - -template <class TImage> -ShapeOpeningLabelMapFilter<TImage> -::ShapeOpeningLabelMapFilter() -{ - m_Lambda = NumericTraits< double >::Zero; - m_ReverseOrdering = false; - m_Attribute = LabelObjectType::SIZE; -} - - -template <class TImage> -void -ShapeOpeningLabelMapFilter<TImage> -::GenerateData() -{ - switch( m_Attribute ) - { - case LabelObjectType::SIZE: - TemplatedGenerateData< typename Functor::SizeLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PHYSICAL_SIZE: - TemplatedGenerateData< typename Functor::PhysicalSizeLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIZE_REGION_RATIO: - TemplatedGenerateData< typename Functor::SizeRegionRatioLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::REGION_ELONGATION: - TemplatedGenerateData< typename Functor::RegionElongationLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIZE_ON_BORDER: - TemplatedGenerateData< typename Functor::SizeOnBorderLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PHYSICAL_SIZE_ON_BORDER: - TemplatedGenerateData< typename Functor::PhysicalSizeOnBorderLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::FERET_DIAMETER: - TemplatedGenerateData< typename Functor::FeretDiameterLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::BINARY_ELONGATION: - TemplatedGenerateData< typename Functor::BinaryElongationLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PERIMETER: - TemplatedGenerateData< typename Functor::PerimeterLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::ROUNDNESS: - TemplatedGenerateData< typename Functor::RoundnessLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::EQUIVALENT_RADIUS: - TemplatedGenerateData< typename Functor::EquivalentRadiusLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::EQUIVALENT_PERIMETER: - TemplatedGenerateData< typename Functor::EquivalentPerimeterLabelObjectAccessor< LabelObjectType > >(); - break; - default: - itkExceptionMacro(<< "Unknown attribute type"); - break; - } -} - -template <class TImage> -template <class TAttributeAccessor> -void -ShapeOpeningLabelMapFilter<TImage> -::TemplatedGenerateData() -{ - // Allocate the output - this->AllocateOutputs(); - - ImageType * output = this->GetOutput(); - - TAttributeAccessor accessor; - - const typename ImageType::LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer(); - - ProgressReporter progress( this, 0, labelObjectContainer.size() ); - - typename ImageType::LabelObjectContainerType::const_iterator it = labelObjectContainer.begin(); - while( it != labelObjectContainer.end() ) - { - typedef typename ImageType::LabelObjectType LabelObjectType; - typename LabelObjectType::LabelType label = it->first; - LabelObjectType * labelObject = it->second; - - if( ( !m_ReverseOrdering && accessor( labelObject ) < m_Lambda ) - || ( m_ReverseOrdering && accessor( labelObject ) > m_Lambda ) ) - { - // must increment the iterator before removing the object to avoid invalidating the iterator - it++; - output->RemoveLabel( label ); - } - else - { - it++; - } - - progress.CompletedPixel(); - } -} - - -template <class TImage> -void -ShapeOpeningLabelMapFilter<TImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "Lambda: " << m_Lambda << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkShapeRelabelImageFilter.h b/Utilities/InsightJournal/itkShapeRelabelImageFilter.h deleted file mode 100644 index 140ee9b668a0fab068233b61eb78ffdae9829ddb..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeRelabelImageFilter.h +++ /dev/null @@ -1,161 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeRelabelImageFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeRelabelImageFilter_h -#define __itkShapeRelabelImageFilter_h - -#include "itkImageToImageFilter.h" -#include "itkShapeLabelObject.h" -#include "itkLabelMap.h" -#include "itkLabelImageToLabelMapFilter.h" -#include "itkShapeLabelMapFilter.h" -#include "itkShapeRelabelLabelMapFilter.h" -#include "itkLabelMapToLabelImageFilter.h" - - -namespace itk { - -/** \class ShapeRelabelImageFilter - * \brief relabel objects according to their shape attributes - * - * ShapeRelabelImageFilter relabel a labeled image according to the shape attributes of - * the objects. The label produced are always consecutives. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ShapeLabelObject, RelabelComponentImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage> -class ITK_EXPORT ShapeRelabelImageFilter : - public ImageToImageFilter<TInputImage, TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef ShapeRelabelImageFilter Self; - typedef ImageToImageFilter<TInputImage, TInputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef TInputImage OutputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef ShapeLabelObject<InputImagePixelType, ImageDimension> LabelObjectType; - typedef typename itk::LabelMap< LabelObjectType > LabelMapType; - typedef typename itk::LabelImageToLabelMapFilter< InputImageType, LabelMapType > LabelizerType; - typedef typename itk::ShapeLabelMapFilter< LabelMapType > LabelObjectValuatorType; - typedef typename LabelObjectType::AttributeType AttributeType; - typedef typename itk::ShapeRelabelLabelMapFilter< LabelMapType > RelabelType; - typedef typename itk::LabelMapToLabelImageFilter< LabelMapType, OutputImageType > BinarizerType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(ShapeRelabelImageFilter, - ImageToImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the order of labeling of the objects. By default, the objects with - * the highest attribute values are labeled first. Set ReverseOrdering to true - * make the one with the smallest attributes be labeled first. - */ - itkGetConstMacro( ReverseOrdering, bool ); - itkSetMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the attribute to use. Default is "Size". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - -protected: - ShapeRelabelImageFilter(); - ~ShapeRelabelImageFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** ShapeRelabelImageFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** ShapeRelabelImageFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - -private: - ShapeRelabelImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - bool m_ReverseOrdering; - AttributeType m_Attribute; -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkShapeRelabelImageFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkShapeRelabelImageFilter.txx b/Utilities/InsightJournal/itkShapeRelabelImageFilter.txx deleted file mode 100644 index c9010a9fe0fcff7f21061536abc3396d0a15d74a..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeRelabelImageFilter.txx +++ /dev/null @@ -1,125 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeRelabelImageFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeRelabelImageFilter_txx -#define __itkShapeRelabelImageFilter_txx - -#include "itkShapeRelabelImageFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage> -ShapeRelabelImageFilter<TInputImage> -::ShapeRelabelImageFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_ReverseOrdering = false; - m_Attribute = LabelObjectType::SIZE; -} - -template<class TInputImage> -void -ShapeRelabelImageFilter<TInputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage> -void -ShapeRelabelImageFilter<TInputImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage> -void -ShapeRelabelImageFilter<TInputImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .3f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetLabelImage( this->GetInput() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - if( m_Attribute == LabelObjectType::PERIMETER || m_Attribute == LabelObjectType::ROUNDNESS ) - { - valuator->SetComputePerimeter( true ); - } - if( m_Attribute == LabelObjectType::FERET_DIAMETER ) - { - valuator->SetComputeFeretDiameter( true ); - } - progress->RegisterInternalFilter(valuator, .3f); - - typename RelabelType::Pointer opening = RelabelType::New(); - opening->SetInput( valuator->GetOutput() ); - opening->SetReverseOrdering( m_ReverseOrdering ); - opening->SetAttribute( m_Attribute ); - opening->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(opening, .2f); - - typename BinarizerType::Pointer binarizer = BinarizerType::New(); - binarizer->SetInput( opening->GetOutput() ); - binarizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(binarizer, .2f); - - binarizer->GraftOutput( this->GetOutput() ); - binarizer->Update(); - this->GraftOutput( binarizer->GetOutput() ); -} - - -template<class TInputImage> -void -ShapeRelabelImageFilter<TInputImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkShapeRelabelLabelMapFilter.h b/Utilities/InsightJournal/itkShapeRelabelLabelMapFilter.h deleted file mode 100644 index 3dbbd57794c368f69b2d6b71400f170acb1b9fdb..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeRelabelLabelMapFilter.h +++ /dev/null @@ -1,125 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeRelabelLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeRelabelLabelMapFilter_h -#define __itkShapeRelabelLabelMapFilter_h - -#include "itkInPlaceLabelMapFilter.h" - -namespace itk { -/** \class ShapeRelabelLabelMapFilter - * \brief relabel objects according to their shape attributes - * - * ShapeRelabelImageFilter relabel a label collection image according to the shape attributes of - * the objects. The label produced are always consecutives. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa ShapeLabelObject, RelabelComponentImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TImage > -class ITK_EXPORT ShapeRelabelLabelMapFilter : - public InPlaceLabelMapFilter<TImage> -{ -public: - /** Standard class typedefs. */ - typedef ShapeRelabelLabelMapFilter Self; - typedef InPlaceLabelMapFilter<TImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::LabelObjectType LabelObjectType; - - typedef typename LabelObjectType::AttributeType AttributeType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(ShapeRelabelLabelMapFilter, - InPlaceLabelMapFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ -/* itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>));*/ - /** End concept checking */ -#endif - - /** - * Set/Get the order of labeling of the objects. By default, the objects with - * the highest attribute values are labeled first. Set ReverseOrdering to true - * make the one with the smallest attributes be labeled first. - */ - itkSetMacro( ReverseOrdering, bool ); - itkGetConstReferenceMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the attribute to use. Default is "Size". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - -protected: - ShapeRelabelLabelMapFilter(); - ~ShapeRelabelLabelMapFilter() {}; - - void GenerateData(); - - template <class TAttributeAccessor> void TemplatedGenerateData(); - - void PrintSelf(std::ostream& os, Indent indent) const; - - bool m_ReverseOrdering; - AttributeType m_Attribute; - -private: - ShapeRelabelLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkShapeRelabelLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkShapeRelabelLabelMapFilter.txx b/Utilities/InsightJournal/itkShapeRelabelLabelMapFilter.txx deleted file mode 100644 index fa6957413363301f60f8cbcc4a2d3fd5ae6a68bb..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkShapeRelabelLabelMapFilter.txx +++ /dev/null @@ -1,161 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkShapeRelabelLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkShapeRelabelLabelMapFilter_txx -#define __itkShapeRelabelLabelMapFilter_txx - -#include "itkShapeRelabelLabelMapFilter.h" -#include "itkProgressReporter.h" - - -namespace itk { - -template <class TImage> -ShapeRelabelLabelMapFilter<TImage> -::ShapeRelabelLabelMapFilter() -{ - m_ReverseOrdering = false; - m_Attribute = LabelObjectType::SIZE; -} - - -template <class TImage> -void -ShapeRelabelLabelMapFilter<TImage> -::GenerateData() -{ - switch( m_Attribute ) - { - case LabelObjectType::SIZE: - TemplatedGenerateData< typename Functor::SizeLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PHYSICAL_SIZE: - TemplatedGenerateData< typename Functor::PhysicalSizeLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIZE_REGION_RATIO: - TemplatedGenerateData< typename Functor::SizeRegionRatioLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::REGION_ELONGATION: - TemplatedGenerateData< typename Functor::RegionElongationLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIZE_ON_BORDER: - TemplatedGenerateData< typename Functor::SizeOnBorderLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PHYSICAL_SIZE_ON_BORDER: - TemplatedGenerateData< typename Functor::PhysicalSizeOnBorderLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::FERET_DIAMETER: - TemplatedGenerateData< typename Functor::FeretDiameterLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::BINARY_ELONGATION: - TemplatedGenerateData< typename Functor::BinaryElongationLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::PERIMETER: - TemplatedGenerateData< typename Functor::PerimeterLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::ROUNDNESS: - TemplatedGenerateData< typename Functor::RoundnessLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::EQUIVALENT_RADIUS: - TemplatedGenerateData< typename Functor::EquivalentRadiusLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::EQUIVALENT_PERIMETER: - TemplatedGenerateData< typename Functor::EquivalentPerimeterLabelObjectAccessor< LabelObjectType > >(); - break; - default: - itkExceptionMacro(<< "Unknown attribute type"); - break; - } -} - - -template <class TImage> -template <class TAttributeAccessor> -void -ShapeRelabelLabelMapFilter<TImage> -::TemplatedGenerateData() -{ - // Allocate the output - this->AllocateOutputs(); - - ImageType * output = this->GetOutput(); - - typedef typename ImageType::LabelObjectContainerType LabelObjectContainerType; - const LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer(); - typedef typename std::vector< typename LabelObjectType::Pointer > VectorType; - - ProgressReporter progress( this, 0, 2 * labelObjectContainer.size() ); - - // get the label objects in a vector, so they can be sorted - VectorType labelObjects; - labelObjects.reserve( labelObjectContainer.size() ); - for( typename LabelObjectContainerType::const_iterator it = labelObjectContainer.begin(); - it != labelObjectContainer.end(); - it++ ) - { - labelObjects.push_back( it->second ); - progress.CompletedPixel(); - } - - // instantiate the comparator and sort the vector - if( m_ReverseOrdering ) - { - Functor::LabelObjectReverseComparator< LabelObjectType, TAttributeAccessor > comparator; - std::sort( labelObjects.begin(), labelObjects.end(), comparator ); - } - else - { - Functor::LabelObjectComparator< LabelObjectType, TAttributeAccessor > comparator; - std::sort( labelObjects.begin(), labelObjects.end(), comparator ); - } -// progress.CompletedPixel(); - - // and put back the objects in the map - typedef typename ImageType::LabelObjectType LabelObjectType; - output->ClearLabels(); - unsigned int label = 0; - for( typename VectorType::const_iterator it = labelObjects.begin(); - it != labelObjects.end(); - it++ ) - { - // avoid the background label if it is used - if( label == output->GetBackgroundValue() ) - { - label++; - } - (*it)->SetLabel( label ); - output->AddLabelObject( *it ); - - // go to the nex label - label++; - progress.CompletedPixel(); - } -} - - -template <class TImage> -void -ShapeRelabelLabelMapFilter<TImage> -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os,indent); - - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkStatisticsKeepNObjectsLabelMapFilter.h b/Utilities/InsightJournal/itkStatisticsKeepNObjectsLabelMapFilter.h deleted file mode 100644 index c3996617e0a636ce7b8df56a856e35b1079198b4..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsKeepNObjectsLabelMapFilter.h +++ /dev/null @@ -1,101 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsKeepNObjectsLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsKeepNObjectsLabelMapFilter_h -#define __itkStatisticsKeepNObjectsLabelMapFilter_h - -#include "itkShapeKeepNObjectsLabelMapFilter.h" -#include "itkStatisticsLabelObject.h" - -namespace itk { -/** \class StatisticsKeepNObjectsLabelMapFilter - * \brief keep N objects according to their statistics attributes - * - * StatisticsKeepNObjectsLabelMapFilter keep the N objects in a label collection image - * with the highest (or lowest) attribute value. The attributes are the ones - * of the StatisticsLabelObject. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa StatisticsLabelObject, BinaryStatisticsKeepNObjectsImageFilter, LabelShapeKeepNObjectsImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TImage> -class ITK_EXPORT StatisticsKeepNObjectsLabelMapFilter : - public ShapeKeepNObjectsLabelMapFilter<TImage> -{ -public: - /** Standard class typedefs. */ - typedef StatisticsKeepNObjectsLabelMapFilter Self; - typedef ShapeKeepNObjectsLabelMapFilter<TImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::LabelObjectType LabelObjectType; - - typedef typename LabelObjectType::AttributeType AttributeType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(StatisticsKeepNObjectsLabelMapFilter, - ShapeKeepNObjectsLabelMapFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ -/* itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>));*/ - /** End concept checking */ -#endif -protected: - StatisticsKeepNObjectsLabelMapFilter(); - ~StatisticsKeepNObjectsLabelMapFilter() {}; - - void GenerateData(); - - template <class TAttributeAccessor> void TemplatedGenerateData(); - -private: - StatisticsKeepNObjectsLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkStatisticsKeepNObjectsLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkStatisticsKeepNObjectsLabelMapFilter.txx b/Utilities/InsightJournal/itkStatisticsKeepNObjectsLabelMapFilter.txx deleted file mode 100644 index 435ba468bceabd866fafa5215ad368f7be71e5f8..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsKeepNObjectsLabelMapFilter.txx +++ /dev/null @@ -1,135 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsKeepNObjectsLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsKeepNObjectsLabelMapFilter_txx -#define __itkStatisticsKeepNObjectsLabelMapFilter_txx - -#include "itkStatisticsKeepNObjectsLabelMapFilter.h" -#include "itkProgressReporter.h" -#include "itkLabelObjectUtils.h" - - -namespace itk { - -template <class TImage> -StatisticsKeepNObjectsLabelMapFilter<TImage> -::StatisticsKeepNObjectsLabelMapFilter() -{ - this->m_Attribute = LabelObjectType::MEAN; -} - - -template <class TImage> -void -StatisticsKeepNObjectsLabelMapFilter<TImage> -::GenerateData() -{ - switch( this->m_Attribute ) - { - case LabelObjectType::MINIMUM: - TemplatedGenerateData< typename Functor::MinimumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MAXIMUM: - TemplatedGenerateData< typename Functor::MaximumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MEAN: - TemplatedGenerateData< typename Functor::MeanLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SUM: - TemplatedGenerateData< typename Functor::SumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIGMA: - TemplatedGenerateData< typename Functor::SigmaLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::VARIANCE: - TemplatedGenerateData< typename Functor::VarianceLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MEDIAN: - TemplatedGenerateData< typename Functor::MedianLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::KURTOSIS: - TemplatedGenerateData< typename Functor::KurtosisLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SKEWNESS: - TemplatedGenerateData< typename Functor::SkewnessLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::ELONGATION: - TemplatedGenerateData< typename Functor::ElongationLabelObjectAccessor< LabelObjectType > >(); - break; - default: - Superclass::GenerateData(); - break; - } -} - - -template <class TImage> -template <class TAttributeAccessor> -void -StatisticsKeepNObjectsLabelMapFilter<TImage> -::TemplatedGenerateData() -{ - // Allocate the output - this->AllocateOutputs(); - - ImageType * output = this->GetOutput(); - - typedef typename ImageType::LabelObjectContainerType LabelObjectContainerType; - const LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer(); - typedef typename std::vector< typename LabelObjectType::Pointer > VectorType; - - ProgressReporter progress( this, 0, 2 * labelObjectContainer.size() ); - - // get the label objects in a vector, so they can be sorted - VectorType labelObjects; - labelObjects.reserve( labelObjectContainer.size() ); - for( typename LabelObjectContainerType::const_iterator it = labelObjectContainer.begin(); - it != labelObjectContainer.end(); - it++ ) - { - labelObjects.push_back( it->second ); - progress.CompletedPixel(); - } - - // instantiate the comparator and sort the vector - if( this->m_NumberOfObjects < labelObjectContainer.size() ) - { - typename VectorType::iterator end = labelObjects.begin() + this->m_NumberOfObjects; - if( this->m_ReverseOrdering ) - { - Functor::LabelObjectReverseComparator< LabelObjectType, TAttributeAccessor > comparator; - std::nth_element( labelObjects.begin(), end, labelObjects.end(), comparator ); - } - else - { - Functor::LabelObjectComparator< LabelObjectType, TAttributeAccessor > comparator; - std::nth_element( labelObjects.begin(), end, labelObjects.end(), comparator ); - } -// progress.CompletedPixel(); - - // and remove the last objects of the map - for( typename VectorType::const_iterator it = end; - it != labelObjects.end(); - it++ ) - { - output->RemoveLabelObject( *it ); - progress.CompletedPixel(); - } - } -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkStatisticsLabelMapFilter.h b/Utilities/InsightJournal/itkStatisticsLabelMapFilter.h deleted file mode 100644 index ee81b7de6d0bc35f3cc5985e4b31258066fe8513..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsLabelMapFilter.h +++ /dev/null @@ -1,156 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsLabelMapFilter_h -#define __itkStatisticsLabelMapFilter_h - -#include "itkShapeLabelMapFilter.h" - -namespace itk { -/** \class StatisticsLabelMapFilter - * \brief The valuator class for the ShapeLabelObject - * - * StatisticsCollectionImageFilter can be used to set the attributes values - * of the StatisticsLabelObject in a LabelMap. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TImage, class TFeatureImage> -class ITK_EXPORT StatisticsLabelMapFilter : - public ShapeLabelMapFilter<TImage> -{ -public: - /** Standard class typedefs. */ - typedef StatisticsLabelMapFilter Self; - typedef ShapeLabelMapFilter<TImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::PointType PointType; - typedef typename ImageType::LabelObjectType LabelObjectType; - typedef typename LabelObjectType::MatrixType MatrixType; - typedef typename LabelObjectType::VectorType VectorType; - - typedef TFeatureImage FeatureImageType; - typedef typename FeatureImageType::Pointer FeatureImagePointer; - typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer; - typedef typename FeatureImageType::PixelType FeatureImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(StatisticsLabelMapFilter, - ShapeLabelMapFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ -/* itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>));*/ - /** End concept checking */ -#endif - - /** Set the feature image */ - void SetFeatureImage(TFeatureImage *input) - { - // Process object is not const-correct so the const casting is required. - this->SetNthInput( 1, const_cast<TFeatureImage *>(input) ); - } - - /** Get the feature image */ - FeatureImageType * GetFeatureImage() - { - return static_cast<FeatureImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1))); - } - - /** Set the input image */ - void SetInput1(TImage *input) - { - this->SetInput( input ); - } - - /** Set the feature image */ - void SetInput2(TFeatureImage *input) - { - this->SetFeatureImage( input ); - } - - /** - * Set/Get whether the histogram should be attached to the label object or not. - * This option defaults to `true`, but because the histogram may take a lot of memory - * compared to the other attributes, this option is useful to reduce the memory usage - * when the histogram is not required. - */ - itkSetMacro(ComputeHistogram, bool); - itkGetConstReferenceMacro(ComputeHistogram, bool); - itkBooleanMacro(ComputeHistogram); - - /** - * Set/Get the number of bins in the histogram. Note that the histogram is used - * to compute the median value, and that this option may have an effect on the - * value of the median. - */ - itkSetMacro(NumberOfBins, unsigned int); - itkGetConstReferenceMacro(NumberOfBins, unsigned int); - - -protected: - StatisticsLabelMapFilter(); - ~StatisticsLabelMapFilter() {}; - - virtual void ThreadedGenerateData( LabelObjectType * labelObject ); - - virtual void BeforeThreadedGenerateData(); - - void PrintSelf(std::ostream& os, Indent indent) const; - -private: - StatisticsLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - FeatureImagePixelType m_Minimum; - FeatureImagePixelType m_Maximum; - unsigned int m_NumberOfBins; - bool m_ComputeHistogram; - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkStatisticsLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkStatisticsLabelMapFilter.txx b/Utilities/InsightJournal/itkStatisticsLabelMapFilter.txx deleted file mode 100644 index 6a784b3a18b198ee6fa91cfd90d91b334af93e65..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsLabelMapFilter.txx +++ /dev/null @@ -1,290 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsLabelMapFilter_txx -#define __itkStatisticsLabelMapFilter_txx - -#include "itkStatisticsLabelMapFilter.h" -#include "itkMinimumMaximumImageCalculator.h" -#include "itkProgressReporter.h" -#include "vnl/algo/vnl_real_eigensystem.h" -#include "vnl/algo/vnl_symmetric_eigensystem.h" - - -namespace itk { - -template <class TImage, class TFeatureImage> -StatisticsLabelMapFilter<TImage, TFeatureImage> -::StatisticsLabelMapFilter() -{ - m_NumberOfBins = 128; - m_ComputeHistogram = true; - this->SetNumberOfRequiredInputs(2); -} - - -template <class TImage, class TFeatureImage> -void -StatisticsLabelMapFilter<TImage, TFeatureImage> -::BeforeThreadedGenerateData() -{ - Superclass::BeforeThreadedGenerateData(); - - // get the min and max of the feature image, to use those value as the bounds of our - // histograms - typedef MinimumMaximumImageCalculator< FeatureImageType > MinMaxCalculatorType; - typename MinMaxCalculatorType::Pointer minMax = MinMaxCalculatorType::New(); - minMax->SetImage( this->GetFeatureImage() ); - minMax->Compute(); - - m_Minimum = minMax->GetMinimum(); - m_Maximum = minMax->GetMaximum(); - -} - - -template <class TImage, class TFeatureImage> -void -StatisticsLabelMapFilter<TImage, TFeatureImage> -::ThreadedGenerateData( LabelObjectType * labelObject ) -{ - Superclass::ThreadedGenerateData( labelObject ); - - ImageType * output = this->GetOutput(); - const FeatureImageType * featureImage = this->GetFeatureImage(); - - typedef typename LabelObjectType::HistogramType HistogramType; - - typename HistogramType::SizeType histogramSize; - histogramSize.Fill( m_NumberOfBins ); - typename HistogramType::MeasurementVectorType featureImageMin; - featureImageMin.Fill( m_Minimum ); - typename HistogramType::MeasurementVectorType featureImageMax; - featureImageMax.Fill( m_Maximum ); - - typename HistogramType::Pointer histogram = HistogramType::New(); - histogram->SetClipBinsAtEnds( false ); - histogram->Initialize( histogramSize, featureImageMin, featureImageMax ); - - typename LabelObjectType::LineContainerType::const_iterator lit; - typename LabelObjectType::LineContainerType & lineContainer = labelObject->GetLineContainer(); - - FeatureImagePixelType min = NumericTraits< FeatureImagePixelType >::max(); - FeatureImagePixelType max = NumericTraits< FeatureImagePixelType >::NonpositiveMin(); - double sum = 0; - double sum2 = 0; - double sum3 = 0; - double sum4 = 0; - IndexType minIdx; - minIdx.Fill( 0 ); - IndexType maxIdx; - maxIdx.Fill( 0 ); - PointType centerOfGravity; - centerOfGravity.Fill( 0 ); - MatrixType centralMoments; - centralMoments.Fill( 0 ); - MatrixType principalAxes; - principalAxes.Fill( 0 ); - VectorType principalMoments; - principalMoments.Fill( 0 ); - - // iterate over all the lines - for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ ) - { - const IndexType & firstIdx = lit->GetIndex(); - unsigned long length = lit->GetLength(); - - typename HistogramType::MeasurementVectorType mv; - long endIdx0 = firstIdx[0] + length; - for( IndexType idx = firstIdx; idx[0]<endIdx0; idx[0]++) - { - const FeatureImagePixelType & v = featureImage->GetPixel( idx ); - mv[0] = v; - histogram->IncreaseFrequency( mv, 1 ); - - // update min and max - if( v <= min ) - { - min = v; - minIdx = idx; - } - if( v >= max ) - { - max = v; - maxIdx = idx; - } - - //increase the sums - sum += v; - sum2 += vcl_pow( (double)v, 2 ); - sum3 += vcl_pow( (double)v, 3 ); - sum4 += vcl_pow( (double)v, 4 ); - - // moments - PointType physicalPosition; - output->TransformIndexToPhysicalPoint(idx, physicalPosition); - for(unsigned int i=0; i<ImageDimension; i++) - { - centerOfGravity[i] += physicalPosition[i] * v; - centralMoments[i][i] += v * physicalPosition[i] * physicalPosition[i]; - for(unsigned int j=i+1; j<ImageDimension; j++) - { - double weight = v * physicalPosition[i] * physicalPosition[j]; - centralMoments[i][j] += weight; - centralMoments[j][i] += weight; - } - } - - } - } - - // final computations - const typename HistogramType::FrequencyType & totalFreq = histogram->GetTotalFrequency(); - double mean = sum / totalFreq; - double variance = ( sum2 - ( vcl_pow( sum, 2 ) / totalFreq ) ) / ( totalFreq - 1 ); - double sigma = vcl_sqrt( variance ); - double mean2 = mean * mean; - double skewness = ( ( sum3 - 3.0 * mean * sum2) / totalFreq + 2.0 * mean * mean2 ) / ( variance * sigma ); - double kurtosis = ( ( sum4 - 4.0 * mean * sum3 + 6.0 * mean2 * sum2) / totalFreq - 3.0 * mean2 * mean2 ) / ( variance * variance ) - 3.0; - - // the median - double median = 0; - double count = 0; // will not be fully set, so do not use later ! - for( unsigned long i=0; - i<histogram->Size(); - i++) - { - count += histogram->GetFrequency( i ); - - if( count >= ( totalFreq / 2 ) ) - { - median = histogram->GetMeasurementVector( i )[0]; - break; - } - } - - double elongation = 0; - if( sum != 0 ) - { - // Normalize using the total mass - for(unsigned int i=0; i<ImageDimension; i++) - { - centerOfGravity[i] /= sum; - for(unsigned int j=0; j<ImageDimension; j++) - { - centralMoments[i][j] /= sum; - } - } - - // Center the second order moments - for(unsigned int i=0; i<ImageDimension; i++) - { - for(unsigned int j=0; j<ImageDimension; j++) - { - centralMoments[i][j] -= centerOfGravity[i] * centerOfGravity[j]; - } - } - - // Compute principal moments and axes - vnl_symmetric_eigensystem<double> eigen( centralMoments.GetVnlMatrix() ); - vnl_diag_matrix<double> pm = eigen.D; - for(unsigned int i=0; i<ImageDimension; i++) - { - // principalMoments[i] = 4 * vcl_sqrt( pm(i,i) ); - principalMoments[i] = pm(i,i); - } - principalAxes = eigen.V.transpose(); - - // Add a final reflection if needed for a proper rotation, - // by multiplying the last row by the determinant - vnl_real_eigensystem eigenrot( principalAxes.GetVnlMatrix() ); - vnl_diag_matrix< vcl_complex<double> > eigenval = eigenrot.D; - vcl_complex<double> det( 1.0, 0.0 ); - - for(unsigned int i=0; i<ImageDimension; i++) - { - det *= eigenval( i, i ); - } - - for(unsigned int i=0; i<ImageDimension; i++) - { - principalAxes[ ImageDimension-1 ][i] *= std::real( det ); - } - - if( principalMoments[0] != 0 ) - { - // elongation = principalMoments[ImageDimension-1] / principalMoments[0]; - elongation = vcl_sqrt(principalMoments[ImageDimension-1] / principalMoments[0]); - } - } - else - { - // can't compute anything in that case - just set everything to a default value - // Normalize using the total mass - for(unsigned int i=0; i<ImageDimension; i++) - { - centerOfGravity[i] = 0; - principalMoments[i] = 0; - for(unsigned int j=0; j<ImageDimension; j++) - { - principalAxes[i][j] = 0; - } - } - } - - // finally put the values in the label object - labelObject->SetMinimum( (double)min ); - labelObject->SetMaximum( (double)max ); - labelObject->SetSum( sum ); - labelObject->SetMean( mean ); - labelObject->SetMedian( median ); - labelObject->SetVariance( variance ); - labelObject->SetSigma( sigma ); - labelObject->SetMinimumIndex( minIdx ); - labelObject->SetMaximumIndex( maxIdx ); - labelObject->SetCenterOfGravity( centerOfGravity ); - labelObject->SetPrincipalAxes( principalAxes ); - labelObject->SetPrincipalMoments( principalMoments ); -// labelObject->SetCentralMoments( centralMoments ); - labelObject->SetSkewness( skewness ); - labelObject->SetKurtosis( kurtosis ); - labelObject->SetElongation( elongation ); - if( m_ComputeHistogram ) - { - labelObject->SetHistogram( histogram ); - } - -// std::cout << std::endl; -// labelObject->Print( std::cout ); -// std::cout << std::endl; - -} - - -template <class TImage, class TFeatureImage> -void -StatisticsLabelMapFilter<TImage, TFeatureImage> -::PrintSelf(std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf(os,indent); - - os << indent << "ComputeHistogram: " << m_ComputeHistogram << std::endl; - os << indent << "NumberOfBins: " << m_NumberOfBins << std::endl; -} - - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkStatisticsLabelObject.h b/Utilities/InsightJournal/itkStatisticsLabelObject.h deleted file mode 100644 index a6c59cdf6ecb791f75c61302cdb64807a351139d..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsLabelObject.h +++ /dev/null @@ -1,827 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkLabelObject.h,v $ - Language: C++ - Date: $Date: 2005/01/21 20:13:31 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsLabelObject_h -#define __itkStatisticsLabelObject_h - -#include "itkShapeLabelObject.h" -#include "itkHistogram.h" - -namespace itk -{ - - -namespace Functor { - -template< class TLabelObject > -class ITK_EXPORT MinimumLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetMinimum(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT MaximumLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetMaximum(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT MeanLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetMean(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT SumLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetSum(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT SigmaLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetSigma(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT VarianceLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetVariance(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT MedianLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetMedian(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT MaximumIndexLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::IndexType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetMaximumIndex(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT MinimumIndexLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::IndexType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetMinimumIndex(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT CenterOfGravityLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::PointType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetCenterOfGravity(); - } -}; - - -/*template< class TLabelObject > -class ITK_EXPORT CentralMomentsLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::MatrixType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetCentralMoments(); - } -};*/ - -template< class TLabelObject > -class ITK_EXPORT PrincipalMomentsLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::VectorType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetPrincipalMoments(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT PrincipalAxesLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::MatrixType AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetPrincipalAxes(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT KurtosisLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetKurtosis(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT SkewnessLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetSkewness(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT ElongationLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef double AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetElongation(); - } -}; - -template< class TLabelObject > -class ITK_EXPORT HistogramLabelObjectAccessor -{ -public: - typedef TLabelObject LabelObjectType; - typedef typename LabelObjectType::HistogramType * AttributeValueType; - - inline const AttributeValueType operator()( const LabelObjectType * labelObject ) - { - return labelObject->GetHistogram(); - } -}; - -} - - -/** \class ShapeLabelObject - * \brief A Label object to store the common attributes related to the statistics of the object - * - * StatisticsLabelObject stores the common attributes related to the statistics of the object - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \ingroup DataRepresentation - */ -template < class TLabel, unsigned int VImageDimension > -class ITK_EXPORT StatisticsLabelObject : public ShapeLabelObject< TLabel, VImageDimension > -{ -public: - /** Standard class typedefs */ - typedef StatisticsLabelObject Self; - typedef ShapeLabelObject< TLabel, VImageDimension > Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - typedef WeakPointer<const Self> ConstWeakPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(StatisticsLabelObject, LabelObject); - - typedef LabelMap< Self > LabelMapType; - - itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension); - - typedef typename Superclass::IndexType IndexType; - - typedef Point< double, ImageDimension > PointType; - - typedef TLabel LabelType; - - typedef typename Superclass::LineType LineType; - - typedef typename Superclass::LengthType LengthType; - - typedef typename Superclass::LineContainerType LineContainerType; - - typedef Matrix< double, ImageDimension, ImageDimension > MatrixType; - - typedef Vector< double, ImageDimension > VectorType; - - typedef typename itk::Statistics::Histogram< double > HistogramType; - - typedef typename Superclass::AttributeType AttributeType; - static const AttributeType MINIMUM=100; - static const AttributeType MAXIMUM=101; - static const AttributeType MEAN=102; - static const AttributeType SUM=103; - static const AttributeType SIGMA=104; - static const AttributeType VARIANCE=105; - static const AttributeType MEDIAN=106; - static const AttributeType MAXIMUM_INDEX=107; - static const AttributeType MINIMUM_INDEX=108; - static const AttributeType CENTER_OF_GRAVITY=109; -// static const AttributeType CENTRAL_MOMENTS=110; - static const AttributeType PRINCIPAL_MOMENTS=111; - static const AttributeType PRINCIPAL_AXES=112; - static const AttributeType KURTOSIS=113; - static const AttributeType SKEWNESS=114; - static const AttributeType ELONGATION=115; - static const AttributeType HISTOGRAM=116; - - static AttributeType GetAttributeFromName( const std::string & s ) - { - if( s == "Minimum" ) - { - return MINIMUM; - } - else if( s == "Maximum" ) - { - return MAXIMUM; - } - else if( s == "Mean" ) - { - return MEAN; - } - else if( s == "Sum" ) - { - return SUM; - } - else if( s == "Sigma" ) - { - return SIGMA; - } - else if( s == "Variance" ) - { - return VARIANCE; - } - else if( s == "Median" ) - { - return MEDIAN; - } - else if( s == "MaximumIndex" ) - { - return MAXIMUM_INDEX; - } - else if( s == "MinimumIndex" ) - { - return MINIMUM_INDEX; - } - else if( s == "CenterOfGravity" ) - { - return CENTER_OF_GRAVITY; - } -/* else if( s == "CentralMoments" ) - { - return CENTRAL_MOMENTS; - }*/ - else if( s == "PrincipalMoments" ) - { - return PRINCIPAL_MOMENTS; - } - else if( s == "PrincipalAxes" ) - { - return PRINCIPAL_AXES; - } - else if( s == "Kurtosis" ) - { - return KURTOSIS; - } - else if( s == "Skewness" ) - { - return SKEWNESS; - } - else if( s == "Elongation" ) - { - return ELONGATION; - } - else if( s == "Histogram" ) - { - return HISTOGRAM; - } - // can't recognize the namespace - return Superclass::GetAttributeFromName( s ); - } - - static std::string GetNameFromAttribute( const AttributeType & a ) - { - switch( a ) - { - case MINIMUM: - return "Minimum"; - break; - case MAXIMUM: - return "Maximum"; - break; - case MEAN: - return "Mean"; - break; - case SUM: - return "Sum"; - break; - case SIGMA: - return "Sigma"; - break; - case VARIANCE: - return "Variance"; - break; - case MEDIAN: - return "Median"; - break; - case MAXIMUM_INDEX: - return "MaximumIndex"; - break; - case MINIMUM_INDEX: - return "MinimumIndex"; - break; - case CENTER_OF_GRAVITY: - return "CenterOfGravity"; - break; -/* case CENTRAL_MOMENTS: - return "CentralMoments"; - break;*/ - case PRINCIPAL_MOMENTS: - return "PrincipalMoments"; - break; - case PRINCIPAL_AXES: - return "PrincipalAxes"; - break; - case KURTOSIS: - return "Kurtosis"; - break; - case SKEWNESS: - return "Skewness"; - break; - case ELONGATION: - return "Elongation"; - break; - case HISTOGRAM: - return "Histogram"; - break; - } - // can't recognize the namespace - return Superclass::GetNameFromAttribute( a ); - } - - typedef ImageRegion< ImageDimension > RegionType; - - typedef typename Superclass::CentroidType CentroidType; - - - virtual void CopyAttributesFrom( const Self * src ) - { - Superclass::CopyAttributesFrom( src ); - - m_Minimum = src->m_Minimum; - m_Maximum = src->m_Maximum; - m_Mean = src->m_Mean; - m_Sum = src->m_Sum; - m_Sigma = src->m_Sigma; - m_Variance = src->m_Variance; - m_Median = src->m_Median; - m_MaximumIndex = src->m_MaximumIndex; - m_MinimumIndex = src->m_MinimumIndex; - m_CenterOfGravity = src->m_CenterOfGravity; -// m_CentralMoments = src->m_CentralMoments; - m_PrincipalMoments = src->m_PrincipalMoments; - m_PrincipalAxes = src->m_PrincipalAxes; - m_Kurtosis = src->m_Kurtosis; - m_Skewness = src->m_Skewness; - m_Elongation = src->m_Elongation; - m_Histogram = src->m_Histogram; - } - -// itkGetConstMacro( Minimum, double ); -// itkSetMacro( Minimum, double ); - const double & GetMinimum() const - { - return m_Minimum; - } - - void SetMinimum( const double & v ) - { - m_Minimum = v; - } - -// itkGetConstMacro( Maximum, double ); -// itkSetMacro( Maximum, double ); - const double & GetMaximum() const - { - return m_Maximum; - } - - void SetMaximum( const double & v ) - { - m_Maximum = v; - } - -// itkGetConstMacro( Mean, double ); -// itkSetMacro( Mean, double ); - const double & GetMean() const - { - return m_Mean; - } - - void SetMean( const double & v ) - { - m_Mean = v; - } - -// itkGetConstMacro( Sum, double ); -// itkSetMacro( Sum, double ); - const double & GetSum() const - { - return m_Sum; - } - - void SetSum( const double & v ) - { - m_Sum = v; - } - -// itkGetConstMacro( Sigma, double ); -// itkSetMacro( Sigma, double ); - const double & GetSigma() const - { - return m_Sigma; - } - - void SetSigma( const double & v ) - { - m_Sigma = v; - } - -// itkGetConstMacro( Variance, double ); -// itkSetMacro( Variance, double ); - const double & GetVariance() const - { - return m_Variance; - } - - void SetVariance( const double & v ) - { - m_Variance = v; - } - -// itkGetConstMacro( Median, double ); -// itkSetMacro( Median, double ); - const double & GetMedian() const - { - return m_Median; - } - - void SetMedian( const double & v ) - { - m_Median = v; - } - -// itkGetConstMacro( MaximumIndex, IndexType ); -// itkSetMacro( MaximumIndex, IndexType ); - const IndexType & GetMaximumIndex() const - { - return m_MaximumIndex; - } - - void SetMaximumIndex( const IndexType & v ) - { - m_MaximumIndex = v; - } - -// itkGetConstMacro( MinimumIndex, IndexType ); -// itkSetMacro( MinimumIndex, IndexType ); - const IndexType & GetMinimumIndex() const - { - return m_MinimumIndex; - } - - void SetMinimumIndex( const IndexType & v ) - { - m_MinimumIndex = v; - } - -// itkGetConstMacro( CenterOfGravity, PointType ); -// itkSetMacro( CenterOfGravity, PointType ); - const PointType & GetCenterOfGravity() const - { - return m_CenterOfGravity; - } - - void SetCenterOfGravity( const PointType & v ) - { - m_CenterOfGravity = v; - } - -// itkGetConstMacro( CentralMoments, MatrixType ); -// itkSetMacro( CentralMoments, MatrixType ); -/* const MatrixType & GetCentralMoments() const - { - return m_CentralMoments; - } - - void SetCentralMoments( const MatrixType & v ) - { - m_CentralMoments = v; - }*/ - -// itkGetConstMacro( PrincipalMoments, VectorType ); -// itkSetMacro( PrincipalMoments, VectorType ); - const VectorType & GetPrincipalMoments() const - { - return m_PrincipalMoments; - } - - void SetPrincipalMoments( const VectorType & v ) - { - m_PrincipalMoments = v; - } - -// itkGetConstMacro( PrincipalAxes, MatrixType ); -// itkSetMacro( PrincipalAxes, MatrixType ); - const MatrixType & GetPrincipalAxes() const - { - return m_PrincipalAxes; - } - - void SetPrincipalAxes( const MatrixType & v ) - { - m_PrincipalAxes = v; - } - -// itkGetConstMacro( Skewness, double ); -// itkSetMacro( Skewness, double ); - const double & GetSkewness() const - { - return m_Skewness; - } - - void SetSkewness( const double & v ) - { - m_Skewness = v; - } - -// itkGetConstMacro( Kurtosis, double ); -// itkSetMacro( Kurtosis, double ); - const double & GetKurtosis() const - { - return m_Kurtosis; - } - - void SetKurtosis( const double & v ) - { - m_Kurtosis = v; - } - -// itkGetConstMacro( Elongation, double ); -// itkSetMacro( Elongation, double ); - const double & GetElongation() const - { - return m_Elongation; - } - - void SetElongation( const double & v ) - { - m_Elongation = v; - } - -// itkGetConstMacro( Histogram, double ); -// itkSetMacro( Histogram, double ); - const HistogramType * GetHistogram() const - { - return m_Histogram; - } - - void SetHistogram( const HistogramType * v ) - { - m_Histogram = v; - } - - -// some helper methods - not really required, but really useful! - - /** Affine transform for mapping to and from principal axis */ - typedef AffineTransform<double,itkGetStaticConstMacro(ImageDimension)> AffineTransformType; - typedef typename AffineTransformType::Pointer AffineTransformPointer; - - /** Get the affine transform from principal axes to physical axes - * This method returns an affine transform which transforms from - * the principal axes coordinate system to physical coordinates. */ - AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform() const - { - typename AffineTransformType::MatrixType matrix; - typename AffineTransformType::OffsetType offset; - for (unsigned int i = 0; i < ImageDimension; i++) - { - offset[i] = m_CenterOfGravity[i]; - for (unsigned int j = 0; j < ImageDimension; j++) - { - matrix[j][i] = m_PrincipalAxes[i][j]; // Note the transposition - } - } - - AffineTransformPointer result = AffineTransformType::New(); - - result->SetMatrix(matrix); - result->SetOffset(offset); - - return result; - } - - /** Get the affine transform from physical axes to principal axes - * This method returns an affine transform which transforms from - * the physical coordinate system to the principal axes coordinate - * system. */ - AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform(void) const - { - typename AffineTransformType::MatrixType matrix; - typename AffineTransformType::OffsetType offset; - for (unsigned int i = 0; i < ImageDimension; i++) - { - offset[i] = m_CenterOfGravity[i]; - for (unsigned int j = 0; j < ImageDimension; j++) - { - matrix[j][i] = m_PrincipalAxes[i][j]; // Note the transposition - } - } - - AffineTransformPointer result = AffineTransformType::New(); - result->SetMatrix(matrix); - result->SetOffset(offset); - - AffineTransformPointer inverse = AffineTransformType::New(); - result->GetInverse(inverse); - - return inverse; - } - - - -protected: - StatisticsLabelObject() - { - m_Minimum = 0; - m_Maximum = 0; - m_Mean = 0; - m_Sum = 0; - m_Sigma = 0; - m_Variance = 0; - m_Median = 0; - m_MaximumIndex.Fill(0); - m_MinimumIndex.Fill(0); - m_CenterOfGravity.Fill(0); -// m_CentralMoments.Fill(0); - m_PrincipalMoments.Fill(0); - m_PrincipalAxes.Fill(0); - m_Kurtosis = 0; - m_Skewness = 0; - m_Elongation = 0; - m_Histogram = NULL; - } - - - void PrintSelf(std::ostream& os, Indent indent) const - { - Superclass::PrintSelf( os, indent ); - - os << indent << "Minimum: " << m_Minimum << std::endl; - os << indent << "Maximum: " << m_Maximum << std::endl; - os << indent << "Mean: " << m_Mean << std::endl; - os << indent << "Sum: " << m_Sum << std::endl; - os << indent << "Sigma: " << m_Sigma << std::endl; - os << indent << "Variance: " << m_Variance << std::endl; - os << indent << "Median: " << m_Median << std::endl; - os << indent << "MaximumIndex: " << m_MaximumIndex << std::endl; - os << indent << "MinimumIndex: " << m_MinimumIndex << std::endl; - os << indent << "CenterOfGravity: " << m_CenterOfGravity << std::endl; -// os << indent << "CentralMoments: " << std::endl << m_CentralMoments; - os << indent << "PrincipalMoments: " << m_PrincipalMoments << std::endl; - os << indent << "PrincipalAxes: " << std::endl << m_PrincipalAxes; - os << indent << "Skewness: " << m_Skewness << std::endl; - os << indent << "Kurtosis: " << m_Kurtosis << std::endl; - os << indent << "Elongation: " << m_Elongation << std::endl; - os << indent << "Histogram: "; - if( m_Histogram ) - { - os << "NULL" << std::endl; - } - else - { - m_Histogram->Print( os, indent ); - } - } - -private: - StatisticsLabelObject(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - double m_Minimum; - double m_Maximum; - double m_Mean; - double m_Sum; - double m_Sigma; - double m_Variance; - double m_Median; - IndexType m_MaximumIndex; - IndexType m_MinimumIndex; - PointType m_CenterOfGravity; -// MatrixType m_CentralMoments; - VectorType m_PrincipalMoments; - MatrixType m_PrincipalAxes; - double m_Skewness; - double m_Kurtosis; - double m_Elongation; - typename HistogramType::ConstPointer m_Histogram; - -}; - -} // end namespace itk - -#endif diff --git a/Utilities/InsightJournal/itkStatisticsOpeningLabelMapFilter.h b/Utilities/InsightJournal/itkStatisticsOpeningLabelMapFilter.h deleted file mode 100644 index 24960ff7eccf2b8592a120f7f7368bae2118eecc..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsOpeningLabelMapFilter.h +++ /dev/null @@ -1,104 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsOpeningLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsOpeningLabelMapFilter_h -#define __itkStatisticsOpeningLabelMapFilter_h - -#include "itkShapeOpeningLabelMapFilter.h" -#include "itkStatisticsLabelObject.h" - -namespace itk { -/** \class StatisticsOpeningLabelMapFilter - * \brief remove the objects according to the value of their statistics attribute - * - * StatisticsOpeningLabelMapFilter removes the objects in a lavbel collection image - * with an attribute value smaller or greater than a threshold called Lambda. - * The attributes are the ones of the StatisticsLabelObject. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa StatisticsLabelObject, BinaryStatisticsOpeningImageFilter, LabelShapeOpeningImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TImage> -class ITK_EXPORT StatisticsOpeningLabelMapFilter : - public ShapeOpeningLabelMapFilter<TImage> -{ -public: - /** Standard class typedefs. */ - typedef StatisticsOpeningLabelMapFilter Self; - typedef ShapeOpeningLabelMapFilter<TImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::LabelObjectType LabelObjectType; - - typedef typename LabelObjectType::AttributeType AttributeType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(StatisticsOpeningLabelMapFilter, - ShapeOpeningLabelMapFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ -/* itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>));*/ - /** End concept checking */ -#endif - - - -protected: - StatisticsOpeningLabelMapFilter(); - ~StatisticsOpeningLabelMapFilter() {}; - - void GenerateData(); - - template <class TAttributeAccessor> void TemplatedGenerateData(); - -private: - StatisticsOpeningLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkStatisticsOpeningLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkStatisticsOpeningLabelMapFilter.txx b/Utilities/InsightJournal/itkStatisticsOpeningLabelMapFilter.txx deleted file mode 100644 index d5efa85e04aad69254d468f9f48d760fe7fd571d..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsOpeningLabelMapFilter.txx +++ /dev/null @@ -1,118 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsOpeningLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsOpeningLabelMapFilter_txx -#define __itkStatisticsOpeningLabelMapFilter_txx - -#include "itkStatisticsOpeningLabelMapFilter.h" -#include "itkProgressReporter.h" - - -namespace itk { - -template <class TImage> -StatisticsOpeningLabelMapFilter<TImage> -::StatisticsOpeningLabelMapFilter() -{ - this->m_Attribute = LabelObjectType::MEAN; -} - - -template <class TImage> -void -StatisticsOpeningLabelMapFilter<TImage> -::GenerateData() -{ - switch( this->m_Attribute ) - { - case LabelObjectType::MINIMUM: - TemplatedGenerateData< typename Functor::MinimumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MAXIMUM: - TemplatedGenerateData< typename Functor::MaximumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MEAN: - TemplatedGenerateData< typename Functor::MeanLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SUM: - TemplatedGenerateData< typename Functor::SumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIGMA: - TemplatedGenerateData< typename Functor::SigmaLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::VARIANCE: - TemplatedGenerateData< typename Functor::VarianceLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MEDIAN: - TemplatedGenerateData< typename Functor::MedianLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::KURTOSIS: - TemplatedGenerateData< typename Functor::KurtosisLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SKEWNESS: - TemplatedGenerateData< typename Functor::SkewnessLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::ELONGATION: - TemplatedGenerateData< typename Functor::ElongationLabelObjectAccessor< LabelObjectType > >(); - break; - default: - Superclass::GenerateData(); - break; - } -} - -template <class TImage> -template <class TAttributeAccessor> -void -StatisticsOpeningLabelMapFilter<TImage> -::TemplatedGenerateData() -{ - // Allocate the output - this->AllocateOutputs(); - - ImageType * output = this->GetOutput(); - - TAttributeAccessor accessor; - - const typename ImageType::LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer(); - - ProgressReporter progress( this, 0, labelObjectContainer.size() ); - - typename ImageType::LabelObjectContainerType::const_iterator it = labelObjectContainer.begin(); - while( it != labelObjectContainer.end() ) - { - typedef typename ImageType::LabelObjectType LabelObjectType; - typename LabelObjectType::LabelType label = it->first; - LabelObjectType * labelObject = it->second; - - if( ( !this->m_ReverseOrdering && accessor( labelObject ) < this->m_Lambda ) - || ( this->m_ReverseOrdering && accessor( labelObject ) > this->m_Lambda ) ) - { - // must increment the iterator before removing the object to avoid invalidating the iterator - it++; - output->RemoveLabel( label ); - } - else - { - it++; - } - - progress.CompletedPixel(); - } -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkStatisticsRelabelImageFilter.h b/Utilities/InsightJournal/itkStatisticsRelabelImageFilter.h deleted file mode 100644 index 34b0ce0befba6d7b55ce6a015c7cc24186979a62..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsRelabelImageFilter.h +++ /dev/null @@ -1,191 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsRelabelImageFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsRelabelImageFilter_h -#define __itkStatisticsRelabelImageFilter_h - -#include "itkImageToImageFilter.h" -#include "itkStatisticsLabelObject.h" -#include "itkLabelMap.h" -#include "itkLabelImageToLabelMapFilter.h" -#include "itkStatisticsLabelMapFilter.h" -#include "itkStatisticsRelabelLabelMapFilter.h" -#include "itkLabelMapToLabelImageFilter.h" - - -namespace itk { - -/** \class StatisticsRelabelImageFilter - * \brief relabel objects according to their shape attributes - * - * StatisticsRelabelImageFilter relabel a labeled image according to the statistics attributes of - * the objects. The label produced are always consecutives. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa StatisticsLabelObject, RelabelComponentImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TInputImage, class TFeatureImage> -class ITK_EXPORT StatisticsRelabelImageFilter : - public ImageToImageFilter<TInputImage, TInputImage> -{ -public: - /** Standard class typedefs. */ - typedef StatisticsRelabelImageFilter Self; - typedef ImageToImageFilter<TInputImage, TInputImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef TInputImage OutputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - - typedef TFeatureImage FeatureImageType; - typedef typename FeatureImageType::Pointer FeatureImagePointer; - typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer; - typedef typename FeatureImageType::PixelType FeatureImagePixelType; - - /** ImageDimension constants */ - itkStaticConstMacro(InputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(OutputImageDimension, unsigned int, - TInputImage::ImageDimension); - itkStaticConstMacro(ImageDimension, unsigned int, - TInputImage::ImageDimension); - - typedef StatisticsLabelObject<InputImagePixelType, ImageDimension> LabelObjectType; - typedef typename itk::LabelMap< LabelObjectType > LabelMapType; - typedef typename itk::LabelImageToLabelMapFilter< InputImageType, LabelMapType > LabelizerType; - typedef typename itk::StatisticsLabelMapFilter< LabelMapType, TFeatureImage > LabelObjectValuatorType; - typedef typename LabelObjectType::AttributeType AttributeType; - typedef typename itk::StatisticsRelabelLabelMapFilter< LabelMapType > RelabelType; - typedef typename itk::LabelMapToLabelImageFilter< LabelMapType, OutputImageType > BinarizerType; - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(StatisticsRelabelImageFilter, - ImageToImageFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>)); - /** End concept checking */ -#endif - - /** - * Set/Get the value used as "background" in the output image. - * Defaults to NumericTraits<PixelType>::NonpositiveMin(). - */ - itkSetMacro(BackgroundValue, OutputImagePixelType); - itkGetConstMacro(BackgroundValue, OutputImagePixelType); - - /** - * Set/Get the order of labeling of the objects. By default, the objects with - * the highest attribute values are labeled first. Set ReverseOrdering to true - * make the one with the smallest attributes be labeled first. - */ - itkGetConstMacro( ReverseOrdering, bool ); - itkSetMacro( ReverseOrdering, bool ); - itkBooleanMacro( ReverseOrdering ); - - /** - * Set/Get the attribute to use. Default is "Mean". - */ - itkGetConstMacro( Attribute, AttributeType ); - itkSetMacro( Attribute, AttributeType ); - void SetAttribute( const std::string & s ) - { - this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); - } - - - /** Set the feature image */ - void SetFeatureImage(TFeatureImage *input) - { - // Process object is not const-correct so the const casting is required. - this->SetNthInput( 1, const_cast<TFeatureImage *>(input) ); - } - - /** Get the feature image */ - FeatureImageType * GetFeatureImage() - { - return static_cast<FeatureImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1))); - } - - /** Set the input image */ - void SetInput1(InputImageType *input) - { - this->SetInput( input ); - } - - /** Set the feature image */ - void SetInput2(FeatureImageType *input) - { - this->SetFeatureImage( input ); - } - -protected: - StatisticsRelabelImageFilter(); - ~StatisticsRelabelImageFilter() {}; - void PrintSelf(std::ostream& os, Indent indent) const; - - /** StatisticsRelabelImageFilter needs the entire input be - * available. Thus, it needs to provide an implementation of - * GenerateInputRequestedRegion(). */ - void GenerateInputRequestedRegion() ; - - /** StatisticsRelabelImageFilter will produce the entire output. */ - void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output)); - - /** Single-threaded version of GenerateData. This filter delegates - * to GrayscaleGeodesicErodeImageFilter. */ - void GenerateData(); - -private: - StatisticsRelabelImageFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - OutputImagePixelType m_BackgroundValue; - bool m_ReverseOrdering; - AttributeType m_Attribute; -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkStatisticsRelabelImageFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkStatisticsRelabelImageFilter.txx b/Utilities/InsightJournal/itkStatisticsRelabelImageFilter.txx deleted file mode 100644 index 7fb471ab73b2a33363d0e476c7e4f3a8fe62d3c9..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsRelabelImageFilter.txx +++ /dev/null @@ -1,128 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsRelabelImageFilter.txx,v $ - Language: C++ - Date: $Date: 2006/08/01 19:16:18 $ - Version: $Revision: 1.7 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsRelabelImageFilter_txx -#define __itkStatisticsRelabelImageFilter_txx - -#include "itkStatisticsRelabelImageFilter.h" -#include "itkProgressAccumulator.h" - - -namespace itk { - -template<class TInputImage, class TFeatureImage> -StatisticsRelabelImageFilter<TInputImage, TFeatureImage> -::StatisticsRelabelImageFilter() -{ - m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin(); - m_ReverseOrdering = false; - m_Attribute = LabelObjectType::MEAN; - this->SetNumberOfRequiredInputs(2); -} - -template<class TInputImage, class TFeatureImage> -void -StatisticsRelabelImageFilter<TInputImage, TFeatureImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - - // We need all the input. - InputImagePointer input = const_cast<InputImageType *>(this->GetInput()); - if( input ) - { - input->SetRequestedRegion( input->GetLargestPossibleRegion() ); - } -} - - -template<class TInputImage, class TFeatureImage> -void -StatisticsRelabelImageFilter<TInputImage, TFeatureImage> -::EnlargeOutputRequestedRegion(DataObject *) -{ - this->GetOutput() - ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); -} - - -template<class TInputImage, class TFeatureImage> -void -StatisticsRelabelImageFilter<TInputImage, TFeatureImage> -::GenerateData() -{ - // Create a process accumulator for tracking the progress of this minipipeline - ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); - progress->SetMiniPipelineFilter(this); - - // Allocate the output - this->AllocateOutputs(); - - typename LabelizerType::Pointer labelizer = LabelizerType::New(); - labelizer->SetInput( this->GetInput() ); - labelizer->SetBackgroundValue( m_BackgroundValue ); - labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(labelizer, .3f); - - typename LabelObjectValuatorType::Pointer valuator = LabelObjectValuatorType::New(); - valuator->SetInput( labelizer->GetOutput() ); - valuator->SetFeatureImage( this->GetFeatureImage() ); - valuator->SetLabelImage( this->GetInput() ); - valuator->SetNumberOfThreads( this->GetNumberOfThreads() ); - valuator->SetComputeHistogram( false ); - if( m_Attribute == LabelObjectType::PERIMETER || m_Attribute == LabelObjectType::ROUNDNESS ) - { - valuator->SetComputePerimeter( true ); - } - if( m_Attribute == LabelObjectType::FERET_DIAMETER ) - { - valuator->SetComputeFeretDiameter( true ); - } - progress->RegisterInternalFilter(valuator, .3f); - - typename RelabelType::Pointer opening = RelabelType::New(); - opening->SetInput( valuator->GetOutput() ); - opening->SetReverseOrdering( m_ReverseOrdering ); - opening->SetAttribute( m_Attribute ); - opening->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(opening, .2f); - - typename BinarizerType::Pointer binarizer = BinarizerType::New(); - binarizer->SetInput( opening->GetOutput() ); - binarizer->SetNumberOfThreads( this->GetNumberOfThreads() ); - progress->RegisterInternalFilter(binarizer, .2f); - - binarizer->GraftOutput( this->GetOutput() ); - binarizer->Update(); - this->GraftOutput( binarizer->GetOutput() ); -} - - -template<class TInputImage, class TFeatureImage> -void -StatisticsRelabelImageFilter<TInputImage, TFeatureImage> -::PrintSelf(std::ostream &os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "ReverseOrdering: " << m_ReverseOrdering << std::endl; - os << indent << "BackgroundValue: " << static_cast<typename NumericTraits<OutputImagePixelType>::PrintType>(m_BackgroundValue) << std::endl; - os << indent << "Attribute: " << LabelObjectType::GetNameFromAttribute(m_Attribute) << " (" << m_Attribute << ")" << std::endl; -} - -}// end namespace itk -#endif diff --git a/Utilities/InsightJournal/itkStatisticsRelabelLabelMapFilter.h b/Utilities/InsightJournal/itkStatisticsRelabelLabelMapFilter.h deleted file mode 100644 index 3b92a789943f5a05efb91fed8b047d9a64f5ee21..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsRelabelLabelMapFilter.h +++ /dev/null @@ -1,102 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsRelabelLabelMapFilter.h,v $ - Language: C++ - Date: $Date: 2006/03/28 19:59:05 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsRelabelLabelMapFilter_h -#define __itkStatisticsRelabelLabelMapFilter_h - -#include "itkShapeRelabelLabelMapFilter.h" -#include "itkStatisticsLabelObject.h" - -namespace itk { -/** \class StatisticsRelabelLabelMapFilter - * \brief relabel objects according to their shape attributes - * - * StatisticsRelabelLabelMapFilter relabel a label collection image according to the statistics attributes of - * the objects. The label produced are always consecutives. - * - * \author Ga�tan Lehmann. Biologie du D�veloppement et de la Reproduction, INRA de Jouy-en-Josas, France. - * - * \sa StatisticsLabelObject, RelabelComponentImageFilter - * \ingroup ImageEnhancement MathematicalMorphologyImageFilters - */ -template<class TImage > -class ITK_EXPORT StatisticsRelabelLabelMapFilter : - public ShapeRelabelLabelMapFilter<TImage> -{ -public: - /** Standard class typedefs. */ - typedef StatisticsRelabelLabelMapFilter Self; - typedef ShapeRelabelLabelMapFilter<TImage> - Superclass; - typedef SmartPointer<Self> Pointer; - typedef SmartPointer<const Self> ConstPointer; - - /** Some convenient typedefs. */ - typedef TImage ImageType; - typedef typename ImageType::Pointer ImagePointer; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::PixelType PixelType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::LabelObjectType LabelObjectType; - - typedef typename LabelObjectType::AttributeType AttributeType; - - /** ImageDimension constants */ - itkStaticConstMacro(ImageDimension, unsigned int, - TImage::ImageDimension); - - /** Standard New method. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(StatisticsRelabelLabelMapFilter, - ShapeRelabelLabelMapFilter); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ -/* itkConceptMacro(InputEqualityComparableCheck, - (Concept::EqualityComparable<InputImagePixelType>)); - itkConceptMacro(IntConvertibleToInputCheck, - (Concept::Convertible<int, InputImagePixelType>)); - itkConceptMacro(InputOStreamWritableCheck, - (Concept::OStreamWritable<InputImagePixelType>));*/ - /** End concept checking */ -#endif - - -protected: - StatisticsRelabelLabelMapFilter(); - ~StatisticsRelabelLabelMapFilter() {}; - - void GenerateData(); - - template <class TAttributeAccessor> void TemplatedGenerateData(); - -private: - StatisticsRelabelLabelMapFilter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -} ; // end of class - -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkStatisticsRelabelLabelMapFilter.txx" -#endif - -#endif - - diff --git a/Utilities/InsightJournal/itkStatisticsRelabelLabelMapFilter.txx b/Utilities/InsightJournal/itkStatisticsRelabelLabelMapFilter.txx deleted file mode 100644 index fa3ce6caeb33c6220e0d3d6a79f7b46e46b45de2..0000000000000000000000000000000000000000 --- a/Utilities/InsightJournal/itkStatisticsRelabelLabelMapFilter.txx +++ /dev/null @@ -1,142 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkStatisticsRelabelLabelMapFilter.txx,v $ - Language: C++ - Date: $Date: 2005/08/23 15:09:03 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkStatisticsRelabelLabelMapFilter_txx -#define __itkStatisticsRelabelLabelMapFilter_txx - -#include "itkStatisticsRelabelLabelMapFilter.h" -#include "itkProgressReporter.h" - - -namespace itk { - -template <class TImage> -StatisticsRelabelLabelMapFilter<TImage> -::StatisticsRelabelLabelMapFilter() -{ - this->m_Attribute = LabelObjectType::MEAN; -} - - -template <class TImage> -void -StatisticsRelabelLabelMapFilter<TImage> -::GenerateData() -{ - switch( this->m_Attribute ) - { - case LabelObjectType::MINIMUM: - TemplatedGenerateData< typename Functor::MinimumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MAXIMUM: - TemplatedGenerateData< typename Functor::MaximumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MEAN: - TemplatedGenerateData< typename Functor::MeanLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SUM: - TemplatedGenerateData< typename Functor::SumLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SIGMA: - TemplatedGenerateData< typename Functor::SigmaLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::VARIANCE: - TemplatedGenerateData< typename Functor::VarianceLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::MEDIAN: - TemplatedGenerateData< typename Functor::MedianLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::KURTOSIS: - TemplatedGenerateData< typename Functor::KurtosisLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::SKEWNESS: - TemplatedGenerateData< typename Functor::SkewnessLabelObjectAccessor< LabelObjectType > >(); - break; - case LabelObjectType::ELONGATION: - TemplatedGenerateData< typename Functor::ElongationLabelObjectAccessor< LabelObjectType > >(); - break; - default: - Superclass::GenerateData(); - break; - } -} - - -template <class TImage> -template <class TAttributeAccessor> -void -StatisticsRelabelLabelMapFilter<TImage> -::TemplatedGenerateData() -{ - // Allocate the output - this->AllocateOutputs(); - - ImageType * output = this->GetOutput(); - - typedef typename ImageType::LabelObjectContainerType LabelObjectContainerType; - const LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer(); - typedef typename std::vector< typename LabelObjectType::Pointer > VectorType; - - ProgressReporter progress( this, 0, 2 * labelObjectContainer.size() ); - - // get the label objects in a vector, so they can be sorted - VectorType labelObjects; - labelObjects.reserve( labelObjectContainer.size() ); - for( typename LabelObjectContainerType::const_iterator it = labelObjectContainer.begin(); - it != labelObjectContainer.end(); - it++ ) - { - labelObjects.push_back( it->second ); - progress.CompletedPixel(); - } - - // instantiate the comparator and sort the vector - if( this->m_ReverseOrdering ) - { - Functor::LabelObjectReverseComparator< LabelObjectType, TAttributeAccessor > comparator; - std::sort( labelObjects.begin(), labelObjects.end(), comparator ); - } - else - { - Functor::LabelObjectComparator< LabelObjectType, TAttributeAccessor > comparator; - std::sort( labelObjects.begin(), labelObjects.end(), comparator ); - } -// progress.CompletedPixel(); - - // and put back the objects in the map - typedef typename ImageType::LabelObjectType LabelObjectType; - output->ClearLabels(); - unsigned int label = 0; - for( typename VectorType::const_iterator it = labelObjects.begin(); - it != labelObjects.end(); - it++ ) - { - // avoid the background label if it is used - if( label == output->GetBackgroundValue() ) - { - label++; - } - (*it)->SetLabel( label ); - output->AddLabelObject( *it ); - - // go to the nex label - label++; - progress.CompletedPixel(); - } -} - -}// end namespace itk -#endif