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 __itkHistogramToEntropyImageFilter_h 00019 #define __itkHistogramToEntropyImageFilter_h 00020 00021 #include "itkHistogramToImageFilter.h" 00022 00023 namespace itk 00024 { 00052 namespace Function 00053 { 00054 template< class TInput, class TOutput = double > 00055 class HistogramEntropyFunction 00056 { 00057 public: 00058 00059 //Probability function = Number of occurances in each bin / 00060 // Total Number of occurances. 00061 // 00062 // Returns pixels of float.. 00063 typedef TOutput OutputPixelType; 00064 00065 HistogramEntropyFunction(): 00066 m_TotalFrequency(1) {} 00067 00068 ~HistogramEntropyFunction() {} 00069 00070 inline OutputPixelType operator()(const TInput & A) const 00071 { 00072 if ( A ) 00073 { 00074 const double p = static_cast< OutputPixelType >( A ) 00075 / static_cast< OutputPixelType >( m_TotalFrequency ); 00076 return static_cast< OutputPixelType >( ( -1 ) * p * vcl_log(p) / vcl_log(2.0) ); 00077 } 00078 else 00079 { 00080 const double p = static_cast< OutputPixelType >( A + 1 ) 00081 / static_cast< OutputPixelType >( m_TotalFrequency ); 00082 return static_cast< OutputPixelType >( ( -1 ) * p * vcl_log(p) / vcl_log(2.0) ); 00083 } 00084 } 00085 00086 void SetTotalFrequency(const SizeValueType n) 00087 { 00088 m_TotalFrequency = n; 00089 } 00090 00091 SizeValueType GetTotalFrequency() const 00092 { 00093 return m_TotalFrequency; 00094 } 00095 00096 private: 00097 SizeValueType m_TotalFrequency; 00098 }; 00099 } 00100 00101 template< class THistogram, class TImage=Image< double, 3> > 00102 class ITK_EXPORT HistogramToEntropyImageFilter: 00103 public HistogramToImageFilter< THistogram, TImage, 00104 Function::HistogramEntropyFunction< SizeValueType, typename TImage::PixelType > > 00105 { 00106 public: 00107 00109 typedef HistogramToEntropyImageFilter Self; 00110 00112 typedef HistogramToImageFilter< THistogram, TImage, 00113 Function::HistogramEntropyFunction< SizeValueType, typename TImage::PixelType > > 00114 Superclass; 00115 00116 typedef SmartPointer< Self > Pointer; 00117 typedef SmartPointer< const Self > ConstPointer; 00118 00120 itkTypeMacro(HistogramToEntropyImageFilter, HistogramToImageFilter); 00121 00123 itkNewMacro(Self); 00124 protected: 00125 HistogramToEntropyImageFilter() {} 00126 virtual ~HistogramToEntropyImageFilter() {} 00127 private: 00128 HistogramToEntropyImageFilter(const Self &); //purposely not implemented 00129 void operator=(const Self &); //purposely not implemented 00130 }; 00131 } // end namespace itk 00133 00134 #endif 00135