ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkHistogramToProbabilityImageFilter_h 00019 #define __itkHistogramToProbabilityImageFilter_h 00020 00021 #include "itkHistogramToImageFilter.h" 00022 00023 namespace itk 00024 { 00047 namespace Function 00048 { 00049 template< class TInput, class TOutput = float > 00050 class HistogramProbabilityFunction 00051 { 00052 public: 00053 00054 //Probability function = Number of occurances in each bin / 00055 // Total Number of occurances. 00056 // 00057 // Returns pixels of float.. 00058 typedef TOutput OutputPixelType; 00059 00060 HistogramProbabilityFunction(): 00061 m_TotalFrequency(1) {} 00062 00063 ~HistogramProbabilityFunction() {} 00064 00065 inline OutputPixelType operator()(const TInput & A) const 00066 { 00067 return static_cast< OutputPixelType >( static_cast< OutputPixelType >( A ) 00068 / static_cast< OutputPixelType >( m_TotalFrequency ) ); 00069 } 00070 00071 void SetTotalFrequency(SizeValueType n) 00072 { 00073 m_TotalFrequency = n; 00074 } 00075 00076 SizeValueType GetTotalFrequency() const 00077 { 00078 return m_TotalFrequency; 00079 } 00080 00081 private: 00082 SizeValueType m_TotalFrequency; 00083 }; 00084 } 00085 00086 template< class THistogram, class TImage=Image< float, 3> > 00087 class ITK_EXPORT HistogramToProbabilityImageFilter: 00088 public HistogramToImageFilter< THistogram, TImage, 00089 Function::HistogramProbabilityFunction< SizeValueType, typename TImage::PixelType > > 00090 { 00091 public: 00092 00094 typedef HistogramToProbabilityImageFilter Self; 00095 00097 typedef HistogramToImageFilter< THistogram, TImage, 00098 Function::HistogramProbabilityFunction< SizeValueType, typename TImage::PixelType > > 00099 Superclass; 00100 00101 typedef SmartPointer< Self > Pointer; 00102 typedef SmartPointer< const Self > ConstPointer; 00103 00105 itkTypeMacro(HistogramToProbabilityImageFilter, HistogramToImageFilter); 00106 00108 itkNewMacro(Self); 00109 protected: 00110 HistogramToProbabilityImageFilter() {} 00111 virtual ~HistogramToProbabilityImageFilter() {} 00112 private: 00113 HistogramToProbabilityImageFilter(const Self &); //purposely not implemented 00114 void operator=(const Self &); //purposely not implemented 00115 }; 00116 } // end namespace itk 00118 00119 #endif 00120