Commit d558a061 authored by Emmanuel Christophe's avatar Emmanuel Christophe

Backed out changeset 73150364e018

parent 7bd2e1c6
......@@ -36,23 +36,23 @@ namespace otb
* If called with a ContinuousIndex or Point, the calculation is performed
* at the nearest neighbor.
*
* This class is templated over the input image type and the
* This class is templated over the input image type and the
* coordinate representation type (e.g. float or double ).
*
* \ingroup ImageFunctions
*/
template <class TInputImage, class TCoordRep = float >
class ITK_EXPORT BinaryImageDensityFunction :
public itk::ImageFunction< TInputImage, typename itk::NumericTraits<typename TInputImage::PixelType>::RealType,TCoordRep >
public itk::ImageFunction< TInputImage, typename itk::NumericTraits<typename TInputImage::PixelType>::RealType,TCoordRep >
{
public:
/** Standard class typedefs. */
typedef BinaryImageDensityFunction Self;
typedef itk::ImageFunction<TInputImage,typename itk::NumericTraits<typename TInputImage::PixelType>::RealType,
TCoordRep > Superclass;
TCoordRep > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(BinaryImageDensityFunction, itk::ImageFunction);
......@@ -67,7 +67,7 @@ public:
/** Index typedef support. */
typedef typename Superclass::IndexType IndexType;
/** ContinuousIndex typedef support. */
typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
......@@ -75,40 +75,40 @@ public:
typedef typename Superclass::PointType PointType;
/** Dimension of the underlying image. */
itkStaticConstMacro(ImageDimension, unsigned int,
InputImageType::ImageDimension);
itkStaticConstMacro(ImageDimension, unsigned int,
InputImageType::ImageDimension);
/** Datatype used for the density */
typedef typename itk::NumericTraits<typename InputImageType::PixelType>::RealType
RealType;
RealType;
/** Evalulate the function at specified index */
virtual RealType EvaluateAtIndex( const IndexType& index ) const;
/** Evaluate the function at non-integer positions */
virtual RealType Evaluate( const PointType& point ) const
{
IndexType index;
this->ConvertPointToNearestIndex( point, index );
return this->EvaluateAtIndex( index );
}
virtual RealType EvaluateAtContinuousIndex(
{
IndexType index;
this->ConvertPointToNearestIndex( point, index );
return this->EvaluateAtIndex( index );
}
virtual RealType EvaluateAtContinuousIndex(
const ContinuousIndexType& cindex ) const
{
IndexType index;
this->ConvertContinuousIndexToNearestIndex( cindex, index );
return this->EvaluateAtIndex( index ) ;
}
{
IndexType index;
this->ConvertContinuousIndexToNearestIndex( cindex, index );
return this->EvaluateAtIndex( index ) ;
}
/** Get/Set the radius of the neighborhood over which the
statistics are evaluated */
itkSetMacro( NeighborhoodRadius, unsigned int );
itkGetConstReferenceMacro( NeighborhoodRadius, unsigned int );
protected:
BinaryImageDensityFunction();
~BinaryImageDensityFunction() {};
~BinaryImageDensityFunction(){};
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
......
......@@ -61,43 +61,43 @@ typename BinaryImageDensityFunction<TInputImage,TCoordRep>
BinaryImageDensityFunction<TInputImage,TCoordRep>
::EvaluateAtIndex(const IndexType& index) const
{
RealType sum;
RealType var;
sum = itk::NumericTraits<RealType>::Zero;
if ( !this->GetInputImage() )
{
return ( itk::NumericTraits<RealType>::max() );
}
if ( !this->IsInsideBuffer( index ) )
{
return ( itk::NumericTraits<RealType>::max() );
}
RealType sum;
RealType var;
sum = itk::NumericTraits<RealType>::Zero;
if( !this->GetInputImage() )
{
return ( itk::NumericTraits<RealType>::max() );
}
if ( !this->IsInsideBuffer( index ) )
{
return ( itk::NumericTraits<RealType>::max() );
}
// Create an N-d neighborhood kernel, using a zeroflux boundary condition
typename InputImageType::SizeType kernelSize;
kernelSize.Fill( m_NeighborhoodRadius );
itk::ConstNeighborhoodIterator<InputImageType>
it(kernelSize, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion());
// Set the iterator at the desired location
it.SetLocation(index);
// Walk the neighborhood
const unsigned int size = it.Size();
for (unsigned int i = 0; i < size; ++i)
{
const RealType value = static_cast<RealType>( it.GetPixel(i) );
sum += value;
}
const RealType num = static_cast<RealType>( size );
var = sum/num ;
return var ;
typename InputImageType::SizeType kernelSize;
kernelSize.Fill( m_NeighborhoodRadius );
itk::ConstNeighborhoodIterator<InputImageType>
it(kernelSize, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion());
// Set the iterator at the desired location
it.SetLocation(index);
// Walk the neighborhood
const unsigned int size = it.Size();
for (unsigned int i = 0; i < size; ++i)
{
const RealType value = static_cast<RealType>( it.GetPixel(i) );
sum += value;
}
const RealType num = static_cast<RealType>( size );
var = sum/num ;
return var ;
}
......
......@@ -48,7 +48,7 @@ void
BinaryImageToDensityImageFilter<TInputImage, TOutputImage, TCountFunction>
::ThreadedGenerateData( const InputImageRegionType &outputRegionForThread, int threadId )
{
InputImagePointerType input = const_cast<InputImageType * > (this->GetInput());
OutputImagePointerType output = this->GetOutput();
......@@ -56,23 +56,23 @@ BinaryImageToDensityImageFilter<TInputImage, TOutputImage, TCountFunction>
itk::ImageRegionConstIterator<InputImageType> it(input,outputRegionForThread );
itk::ImageRegionIterator<OutputImageType> itOut(output,outputRegionForThread );
it.GoToBegin();
itOut.GoToBegin();
while (!it.IsAtEnd())
{
m_CountFunction->SetNeighborhoodRadius(m_NeighborhoodRadius);
typename InputImageType::IndexType index = it.GetIndex();
if (outputRegionForThread.IsInside(index))
while(!it.IsAtEnd())
{
itOut.Set(m_CountFunction->EvaluateAtIndex(index));
m_CountFunction->SetNeighborhoodRadius(m_NeighborhoodRadius);
typename InputImageType::IndexType index = it.GetIndex();
if(outputRegionForThread.IsInside(index))
{
itOut.Set(m_CountFunction->EvaluateAtIndex(index));
}
++itOut;
++it;
}
++itOut;
++it;
}
}
/** PrintSelf method */
......
......@@ -29,10 +29,10 @@ PURPOSE. See the above copyright notices for more information.
/** \class EdgeDensityImageFilter
* \brief This composite filter computes the density of the edges around a pixel.
*
*
*/
* \brief This composite filter computes the density of the edges around a pixel.
*
*
*/
namespace otb
{
......@@ -71,15 +71,15 @@ public:
/** Count Density Function typedef support*/
typedef TDensityCount DensityCountFunctionType;
/** PointSetToDensityImageFilter support*/
typedef otb::BinaryImageToDensityImageFilter<InputImageType,
OutputImageType,
DensityCountFunctionType> DensityImageType;
typedef otb::BinaryImageToDensityImageFilter<InputImageType,
OutputImageType,
DensityCountFunctionType> DensityImageType;
typedef typename DensityImageType::Pointer DensityImagePointerType;
/** Get/Set the radius of the neighborhood over which the
statistics are evaluated */
itkSetMacro( NeighborhoodRadius, unsigned int );
......
......@@ -31,7 +31,7 @@ EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
::EdgeDensityImageFilter()
{
this->SetNumberOfRequiredInputs( 1 );
m_NeighborhoodRadius = 1;
m_Detector = DetectorType::New();
m_DensityImageFilter = DensityImageType::New();
......@@ -66,7 +66,7 @@ EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
/** Apply Canny Detector*/
m_Detector->SetInput(ptr);
/** Compute density on the binaruzed Image */
m_DensityImageFilter->SetInput(m_Detector->GetOutput());
......@@ -95,9 +95,9 @@ EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
* Get Detector
*/
template <class TInputImage , class TOutputImage, class TEdgeDetector, class TDensityCount>
typename EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
typename EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
::DetectorType *
EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
::GetDetector()
{
return m_Detector;
......@@ -110,7 +110,7 @@ EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
-----------------------------------------------------------------*/
template <class TInputImage , class TOutputImage, class TEdgeDetector, class TDensityCount>
void
EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
EdgeDensityImageFilter<TInputImage, TOutputImage, TEdgeDetector, TDensityCount>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
......
......@@ -92,7 +92,7 @@ private:
// The number of output Pricipal Components
unsigned int m_NumberOfPrincipalComponentsRequired;
/** Inner Product Matrix pre computed */
/** Inner Product Matrix pre computed */
MatrixType m_InnerProduct;
/** Contains Eigen Vectors Of Inner Product Matrix computed */
......
......@@ -54,7 +54,7 @@ template<class TInputImage, class TOutputImage>
void
EstimateInnerProductPCAImageFilter<TInputImage,TOutputImage>
::GenerateOutputInformation(void)
{
{
Superclass::GenerateOutputInformation();
this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfPrincipalComponentsRequired);
}
......@@ -112,10 +112,10 @@ EstimateInnerProductPCAImageFilter<TInputImage,TOutputImage>
outputPixel.SetSize(m_NumberOfPrincipalComponentsRequired);
outputPixel.Fill(0);
for (unsigned int img_number = 0; img_number < numberOfTrainingImages; img_number++ )
for(unsigned int img_number = 0; img_number < numberOfTrainingImages; img_number++ )
{
unsigned int indexNumberOfTrainingImages = numberOfTrainingImages-1;
for ( unsigned int vec_number = 0 ; vec_number < m_NumberOfPrincipalComponentsRequired; vec_number++, indexNumberOfTrainingImages-- )
for( unsigned int vec_number = 0 ; vec_number < m_NumberOfPrincipalComponentsRequired; vec_number++, indexNumberOfTrainingImages-- )
{
outputPixel[vec_number] += static_cast<OutputInternalPixelType>( static_cast<double>(inputPixel[img_number]) * static_cast<double>(m_EigenVectorsOfInnerProductMatrix[img_number][indexNumberOfTrainingImages]));
}
......
......@@ -51,7 +51,7 @@ namespace otb
template <class TInputImage, class TOutputImage,class TFunction>
class ITK_EXPORT FunctionWithNeighborhoodToImageFilter :
public itk::InPlaceImageFilter<TInputImage,TOutputImage>
public itk::InPlaceImageFilter<TInputImage,TOutputImage>
{
public:
/** Standard class typedefs. */
......@@ -96,22 +96,22 @@ public:
/** Accessors */
itkGetMacro(Radius, InputImageSizeType);
void SetRadius( InputImageSizeType & rad )
{
m_Radius = rad;
m_Function->SetRadius( rad );
this->Modified();
}
{
m_Radius = rad;
m_Function->SetRadius( rad );
this->Modified();
}
itkGetMacro(Offset, InputImageOffsetType);
void SetOffset( InputImageOffsetType & offset )
{
m_Offset = offset;
m_Function->SetOffset( offset );
this->Modified();
}
{
m_Offset = offset;
m_Function->SetOffset( offset );
this->Modified();
}
protected:
FunctionWithNeighborhoodToImageFilter();
virtual ~FunctionWithNeighborhoodToImageFilter() {};
virtual ~FunctionWithNeighborhoodToImageFilter(){};
void BeforeThreadedGenerateData();
......
......@@ -48,7 +48,7 @@ template <class TInputImage, class TOutputImage, class TFunction >
void
FunctionWithNeighborhoodToImageFilter<TInputImage,TOutputImage,TFunction>
::BeforeThreadedGenerateData()
{
{
Superclass::BeforeThreadedGenerateData();
InputImageConstPointer inputPtr = dynamic_cast<const TInputImage*>((itk::ProcessObject::GetInput(0)));
......@@ -59,11 +59,11 @@ FunctionWithNeighborhoodToImageFilter<TInputImage,TOutputImage,TFunction>
}
m_Function->SetInputImage(inputPtr);
for (unsigned int i = 0 ; i<static_cast<unsigned int>(this->GetNumberOfThreads()); i++)
{
FunctionPointerType func = m_Function;
m_FunctionList.push_back( func );
}
for(unsigned int i = 0 ; i<static_cast<unsigned int>(this->GetNumberOfThreads()); i++)
{
FunctionPointerType func = m_Function;
m_FunctionList.push_back( func );
}
}
template <class TInputImage, class TOutputImage, class TFunction >
......@@ -142,13 +142,13 @@ FunctionWithNeighborhoodToImageFilter<TInputImage,TOutputImage,TFunction>
outputIt.GoToBegin();
while ( !inputIt.IsAtEnd() )
{
outputIt.Set( static_cast<OutputImagePixelType>(m_FunctionList[threadId]->EvaluateAtIndex(inputIt.GetIndex())) );
++inputIt;
++outputIt;
progress.CompletedPixel(); // potential exception thrown here
}
{
outputIt.Set( static_cast<OutputImagePixelType>(m_FunctionList[threadId]->EvaluateAtIndex(inputIt.GetIndex())) );
++inputIt;
++outputIt;
progress.CompletedPixel(); // potential exception thrown here
}
}
} // end namespace otb
......
......@@ -31,23 +31,23 @@ namespace otb
* itk::ImagePCAShapeModelEstimator) (PCA) on a vector image in streaming capabilities.
* Alls channels of the input vector image are used for training images
* and also the number of desired largest principal components needed.
* The number of channels of the output image are the user specified number of desired
* The number of channels of the output image are the user specified number of desired
* largest principal components.
*
* The algorithm uses the VNL library to perform the eigen analysis. To speed
* the computation of the instead of performing the eigen analysis of the
* the computation of the instead of performing the eigen analysis of the
* covariance vector A*A' where A is a matrix with p x t, p = number of
* pixels or voxels in each images and t = number of training images, we
* calculate the eigen vectors of the inner product matrix A'*A. The resulting
* eigen vectors (E) are then multiplied with the the matrix A to get the
* principal compoenets. The covariance matrix has a dimension of p x p. Since
* number of pixels in any image being typically very high the eigen
* decomposition becomes computationally expensive. The inner product on the
* other hand has the dimension of t x t, where t is typically much smaller
* eigen vectors (E) are then multiplied with the the matrix A to get the
* principal compoenets. The covariance matrix has a dimension of p x p. Since
* number of pixels in any image being typically very high the eigen
* decomposition becomes computationally expensive. The inner product on the
* other hand has the dimension of t x t, where t is typically much smaller
* that p. Hence the eigen decomposition (most compute intensive part) is an
* orders of magnitude faster.
*
* The Update() function enables the calculation of the various models, creates
*
* The Update() function enables the calculation of the various models, creates
* the membership function objects and populates them.
*
* \sa itk::ImagePCAShapeModelEstimator
......
......@@ -41,7 +41,7 @@ template<class TInputImage, class TOutputImage>
void
InnerProductPCAImageFilter<TInputImage,TOutputImage>
::GenerateOutputInformation(void)
{
{
Superclass::GenerateOutputInformation();
this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfPrincipalComponentsRequired);
}
......
......@@ -13,8 +13,8 @@
for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
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.
=========================================================================*/
......@@ -28,8 +28,7 @@
#include "itkDenseFrequencyContainer.h"
#include "itkNumericTraits.h"
namespace otb
{
namespace otb{
/** \class ListSampleToVariableDimensionHistogramGenerator
* \brief Generates a VariableDimensionHistogram from a ListSample
......@@ -37,20 +36,20 @@ namespace otb
* This class is a fork from itk::ListSampleToHistogramGenerator
* adapted to produce VariableDimensionHistogram, whose dimension can
* be chosen at runtime.
*
*
* Since the MeasurementVectorSize template parameter is no longer
* needed, it has been removed.
*
*
* For more information, please refer to the
* ListSampleToHistogramGenerator class documentation.
*
* \sa VariableDimensionHistogram, ListSample, ListSampleToHistogramGenerator
*/
template< class TListSample,
class THistogramMeasurement,
class TFrequencyContainer = itk::Statistics::DenseFrequencyContainer>
template< class TListSample,
class THistogramMeasurement,
class TFrequencyContainer = itk::Statistics::DenseFrequencyContainer>
class ITK_EXPORT ListSampleToVariableDimensionHistogramGenerator :
public itk::Object
public itk::Object
{
public:
/** Standard typedefs */
......@@ -58,63 +57,55 @@ public:
typedef itk::Object Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(ListSampleToVariableDimensionHistogramGenerator, Object) ;
/** Method for creation through the object factory. */
itkNewMacro(Self) ;
/** Type needed for defining the limits of the histogram bins */
typedef typename itk::NumericTraits< THistogramMeasurement >::RealType
HistogramMeasurementRealType;
/** Type needed for defining the limits of the histogram bins */
typedef typename itk::NumericTraits< THistogramMeasurement >::RealType
HistogramMeasurementRealType;
typedef itk::Statistics::VariableDimensionHistogram< HistogramMeasurementRealType,
TFrequencyContainer > HistogramType ;
TFrequencyContainer > HistogramType ;
typedef typename HistogramType::SizeType HistogramSizeType ;
typedef typename HistogramType::MeasurementVectorType MeasurementVectorType;
/** plug in the ListSample object */
void SetListSample(const TListSample* list)
{
m_List = list ;
}
{
m_List = list ;
}
void SetMarginalScale(float scale)
{
m_MarginalScale = scale ;
}
{ m_MarginalScale = scale ; }
void SetNumberOfBins(HistogramSizeType sizes)
{
m_Sizes = sizes ;
}
{ m_Sizes = sizes ; }
HistogramType* GetOutput() const
{
return m_Histogram ;
}
{ return m_Histogram ; }
void Update()
{
this->GenerateData() ;
}
void Update()
{ this->GenerateData() ; }
itkSetMacro(AutoMinMax,bool);
itkGetConstReferenceMacro(AutoMinMax,bool);
void SetHistogramMin(const MeasurementVectorType & histogramMin)
{
{
m_HistogramMin = histogramMin;
m_AutoMinMax = false;
}
}
void SetHistogramMax(const MeasurementVectorType & histogramMax)
{
{
m_HistogramMax = histogramMax;
m_AutoMinMax = false;
}
}
protected:
......@@ -134,7 +125,7 @@ private: