📄 itkhistogram.h
字号:
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkHistogram.h,v $
Language: C++
Date: $Date: 2005-09-30 17:24:45 $
Version: $Revision: 1.49 $
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 __itkHistogram_h
#define __itkHistogram_h
#include <vector>
#include "itkIndex.h"
#include "itkSize.h"
#include "itkFixedArray.h"
#include "itkSample.h"
#include "itkDenseFrequencyContainer.h"
#include "itkSparseFrequencyContainer.h"
namespace itk{
namespace Statistics{
/**
* Due to a bug in MSVC, an enum value cannot be accessed out of a template
* parameter until the template class opens. In order for templated classes
* to access the dimension of an image template parameter in defining their
* own dimension, this class is needed as a work-around.
*/
template <typename THistogram>
struct GetHistogramDimension
{
itkStaticConstMacro(HistogramDimension, unsigned int, THistogram::MeasurementVectorSize);
};
/** \class Histogram
* \brief This class stores measurement vectors in the context of n-dimensional histogram.
*
* Histogram represents an ND histogram. Histogram bins can be
* regularly or irregularly spaced. The storage for the histogram is
* managed via the FrequencyContainer specified by the template
* argument. The default frequency container is a
* DenseFrequencyContainer. A SparseFrequencyContainer can be used as
* an alternative.
*
* Frequencies of a bin (SetFrequency(), IncreaseFrequency()) can be
* specified by measurement, index, or instance identifier.
*
* Measurements can be queried by bin index or instance
* identifier. In this case, the measurement returned in the centroid
* of the histogram bin.
*
* The Initialize() method is used to specified the number of bins for
* each dimension of the histogram. An overloaded version also allows
* for regularly spaced bins to defined. To define irregularly sized
* bins, use the SetBinMin()/SetBinMax() methods.
*
* If you do not know the length of the measurement vector at compile time, you
* can set the second template parameter to 0. This can conveniently be obtained
* from MeasurementVectorTraits. For instance, instantiate a histogram as
* below:
*
* \code
* typedef Histogram< THistogramMeasurement, typename
* MeasurementVectorTraits< MeasurementVectorType >::MeasurementVectorLength,
* TFrequencyContainer > HistogramType;
* \endcode
*
* \sa Sample, DenseFrequencyContainer, SparseFrequencyContainer
*/
template < class TMeasurement = float, unsigned int VMeasurementVectorSize = 1,
class TFrequencyContainer = DenseFrequencyContainer >
class ITK_EXPORT Histogram
: public Sample < FixedArray< TMeasurement, VMeasurementVectorSize > >
{
public:
/** Standard typedefs */
typedef Histogram Self ;
typedef Sample< FixedArray< TMeasurement, VMeasurementVectorSize > > Superclass ;
typedef SmartPointer<Self> Pointer ;
typedef SmartPointer<const Self> ConstPointer ;
/** Run-time type information (and related methods). */
itkTypeMacro(Histogram, Sample) ;
/** standard New() method support */
itkNewMacro(Self) ;
/** Dimension of a measurement vector */
itkStaticConstMacro(MeasurementVectorSize, unsigned int,
VMeasurementVectorSize);
/** type of an element of a measurement vector */
typedef TMeasurement MeasurementType ;
/** Common sample class typedefs */
typedef typename Superclass::MeasurementVectorType MeasurementVectorType ;
typedef typename Superclass::InstanceIdentifier InstanceIdentifier ;
typedef MeasurementVectorType ValueType ;
typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
/** frequency container typedef */
typedef TFrequencyContainer FrequencyContainerType ;
typedef typename FrequencyContainerType::Pointer FrequencyContainerPointer ;
/** Frequency and TotalFrequency value type from superclass */
typedef typename FrequencyContainerType::FrequencyType FrequencyType ;
typedef typename FrequencyContainerType::TotalFrequencyType TotalFrequencyType ;
/** Index typedef support. An index is used to access pixel values. */
typedef itk::Index< VMeasurementVectorSize > IndexType;
typedef typename IndexType::IndexValueType IndexValueType;
/** size array type */
typedef itk::Size< VMeasurementVectorSize > SizeType ;
typedef typename SizeType::SizeValueType SizeValueType ;
/** bin min max value storage types */
typedef std::vector< MeasurementType > BinMinVectorType ;
typedef std::vector< MeasurementType > BinMaxVectorType ;
typedef std::vector< BinMinVectorType > BinMinContainerType ;
typedef std::vector< BinMaxVectorType > BinMaxContainerType ;
/** Initialize the histogram, generating the offset table and
* preparing the frequency container. Subclasses should call this
* method in their Initialize() method. */
void Initialize(const SizeType &size) ;
/** Initialize the histogram using equal size bins. To assign bin's
* min and max values along each dimension use SetBinMin() and
* SetBinMax() functions. */
void Initialize(const SizeType &size, MeasurementVectorType& lowerBound,
MeasurementVectorType& upperBound) ;
/** Initialize the values of the histogram bins to zero */
void SetToZero() ;
/** Get the index of a measurement value from the histogram.
* \deprecated Use GetIndex(const MeasurementVectorType &
* measurement, IndexType & index ) const instead.*/
const IndexType & GetIndex(const MeasurementVectorType& measurement) const;
/** Get the index of histogram corresponding to the specified
* measurement value. Returns true if index is valid and false if
* the measurement is outside the histogram */
bool GetIndex(const MeasurementVectorType & measurement,
IndexType & index ) const;
/** Get the index that is uniquely labelled by an instance identifier
* The corresponding id is the offset of the index
* This method uses ImageBase::ComputeIndex() method */
const IndexType & GetIndex(const InstanceIdentifier &id) const;
/** Is set to false if the bins at edges of the histogram extend to
* +/- infinity. */
itkGetMacro(ClipBinsAtEnds, bool);
/** Set to false to have the bins at edges of the histogram extend to
* +/- infinity. */
itkSetMacro(ClipBinsAtEnds, bool);
/** Returns true if the given index is out of bound meaning one of index
* is not between [0, last index] */
bool IsIndexOutOfBounds(const IndexType &index) const;
/** Get the instance identifier of the bin that is indexed by the
* index. The corresponding instance identifier is the offset of the index
* This method uses ImageBase::ComputeIndex() method */
InstanceIdentifier GetInstanceIdentifier(const IndexType &index) const ;
/** Returns the number of instances (bins or cells) in this container */
unsigned int Size() const ;
/** Get the size (N-dimensional) of the histogram */
SizeType GetSize() const
{ return m_Size ; }
/** Get the size of histogram along a specified dimension */
SizeValueType GetSize(const unsigned int dimension) const
{
return m_Size[dimension] ;
}
/** Get the minimum value of nth bin of dimension d */
const MeasurementType& GetBinMin(const unsigned int dimension,
const unsigned long nbin) const
{ return m_Min[dimension][nbin] ; }
/** Get the maximum value of nth bin of dimension d */
const MeasurementType& GetBinMax(const unsigned int dimension,
const unsigned long nbin) const
{ return m_Max[dimension][nbin] ; }
/** Set the minimum value of nth bin of dimension d */
void SetBinMin(const unsigned int dimension, const unsigned long nbin,
const MeasurementType min)
{ m_Min[dimension][nbin] = min ; }
/** Set the maximum value of nth bin of dimension d */
void SetBinMax(const unsigned int dimension,
unsigned long nbin, const MeasurementType max)
{ m_Max[dimension][nbin] = max ; }
/** Get the minimum of the bin along dimension d corresponding to a
* particular measurement. */
const MeasurementType& GetBinMinFromValue(const unsigned int dimension,
const float value ) const ;
/** Get the maximum of the bin along dimension d corresponding to a
* particular measurement. */
const MeasurementType& GetBinMaxFromValue(const unsigned int dimension,
const float value ) const ;
/** Get the vector of bin minimums along a dimension */
const BinMinVectorType& GetDimensionMins(const unsigned int dimension) const
{ return m_Min[dimension] ; }
/** Get the vector of maximums along a dimension */
const BinMaxVectorType& GetDimensionMaxs(const unsigned int dimension) const
{ return m_Max[dimension] ; }
/** Get the minimums of the bins */
const BinMinContainerType& GetMins() const
{ return m_Min ; }
/** Method the maximums of the bins */
const BinMaxContainerType& GetMaxs() const
{ return m_Max ; }
// /** Get the minimums of the bin corresponding to a particular measurement */
// MeasurementVectorType& GetHistogramMinFromValue(const MeasurementVectorType
// &measurement) ;
//
// /** Get the maximums of the bin corresponding to a particular measurement */
// MeasurementVectorType& GetHistogramMaxFromValue(const MeasurementVectorType
// &measurement) ;
/** Get the minimums of the bin corresponding to a particular index */
MeasurementVectorType& GetHistogramMinFromIndex(const IndexType &index) ;
/** Get the maximums of the bin corresponding to a particular index */
MeasurementVectorType& GetHistogramMaxFromIndex(const IndexType &index) ;
/** Get the frequency of an instance indentifier */
FrequencyType GetFrequency(const InstanceIdentifier &id) const
{ return m_FrequencyContainer->GetFrequency(id) ; }
/** Get the frequency of an index */
FrequencyType GetFrequency(const IndexType &index) const ;
/** Set all the bins in the histogram to a specified frequency */
void SetFrequency(const FrequencyType value) ;
/** Set the frequency of an instance identifier. Returns false if the bin is
* out of bounds. */
bool SetFrequency(const InstanceIdentifier &id, const FrequencyType value)
{ return m_FrequencyContainer->SetFrequency(id, value) ; }
/** Set the frequency of an index. Returns false if the bin is
* out of bounds. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -