Orfeo Toolbox  3.16
itkNoiseImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkNoiseImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-04-06 00:19:17 $
7  Version: $Revision: 1.7 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkNoiseImageFilter_txx
18 #define __itkNoiseImageFilter_txx
19 
20 
21 // First make sure that the configuration is available.
22 // This line can be removed once the optimized versions
23 // gets integrated into the main directories.
24 #include "itkConfigure.h"
25 
26 #ifdef ITK_USE_CONSOLIDATED_MORPHOLOGY
28 #else
29 
30 
31 #include "itkNoiseImageFilter.h"
32 
35 #include "itkImageRegionIterator.h"
38 #include "itkOffset.h"
39 #include "itkProgressReporter.h"
40 
41 namespace itk
42 {
43 
44 template <class TInputImage, class TOutputImage>
47 {
48  m_Radius.Fill(1);
49 }
50 
51 template <class TInputImage, class TOutputImage>
52 void
55 {
56  // call the superclass' implementation of this method
57  Superclass::GenerateInputRequestedRegion();
58 
59  // get pointers to the input and output
60  typename Superclass::InputImagePointer inputPtr =
61  const_cast< TInputImage * >( this->GetInput() );
62  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
63 
64  if ( !inputPtr || !outputPtr )
65  {
66  return;
67  }
68 
69  // get a copy of the input requested region (should equal the output
70  // requested region)
71  typename TInputImage::RegionType inputRequestedRegion;
72  inputRequestedRegion = inputPtr->GetRequestedRegion();
73 
74  // pad the input requested region by the operator radius
75  inputRequestedRegion.PadByRadius( m_Radius );
76 
77  // crop the input requested region at the input's largest possible region
78  if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
79  {
80  inputPtr->SetRequestedRegion( inputRequestedRegion );
81  return;
82  }
83  else
84  {
85  // Couldn't crop the region (requested region is outside the largest
86  // possible region). Throw an exception.
87 
88  // store what we tried to request (prior to trying to crop)
89  inputPtr->SetRequestedRegion( inputRequestedRegion );
90 
91  // build an exception
92  InvalidRequestedRegionError e(__FILE__, __LINE__);
93  e.SetLocation(ITK_LOCATION);
94  e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
95  e.SetDataObject(inputPtr);
96  throw e;
97  }
98 }
99 
100 
101 template< class TInputImage, class TOutputImage>
102 void
104 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
105  int threadId)
106 {
107  unsigned int i;
109 
112 
113  // Allocate output
114  typename OutputImageType::Pointer output = this->GetOutput();
115  typename InputImageType::ConstPointer input = this->GetInput();
116 
117  // Find the data-set boundary "faces"
120  faceList = bC(input, outputRegionForThread, m_Radius);
121 
123 
124  // support progress methods/callbacks
125  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
126 
127  InputRealType value;
128  InputRealType sum;
129  InputRealType sumOfSquares;
130  InputRealType var;
131  InputRealType num;
132 
133  // Process each of the boundary faces. These are N-d regions which border
134  // the edge of the buffer.
135  for (fit=faceList.begin(); fit != faceList.end(); ++fit)
136  {
138  input, *fit);
139  unsigned int neighborhoodSize = bit.Size();
140  num = static_cast<InputRealType>( bit.Size() );
141 
142  it = ImageRegionIterator<OutputImageType>(output, *fit);
143  bit.OverrideBoundaryCondition(&nbc);
144  bit.GoToBegin();
145 
146  while ( ! bit.IsAtEnd() )
147  {
148  sum = NumericTraits<InputRealType>::Zero;
149  sumOfSquares = NumericTraits<InputRealType>::Zero;
150  for (i = 0; i < neighborhoodSize; ++i)
151  {
152  value = static_cast<InputRealType>( bit.GetPixel(i) );
153  sum += value;
154  sumOfSquares += (value*value);
155  }
156 
157  // calculate the standard deviation value
158  var = (sumOfSquares - (sum*sum/num)) / (num - 1.0);
159  it.Set( static_cast<OutputPixelType>(vcl_sqrt(var)) );
160 
161  ++bit;
162  ++it;
163  progress.CompletedPixel();
164  }
165  }
166 }
167 
171 template <class TInputImage, class TOutput>
172 void
175  std::ostream& os,
176  Indent indent) const
177 {
178  Superclass::PrintSelf( os, indent );
179  os << indent << "Radius: " << m_Radius << std::endl;
180 
181 }
182 
183 } // end namespace itk
184 
185 #endif
186 
187 #endif

Generated at Sat Feb 2 2013 23:56:29 for Orfeo Toolbox with doxygen 1.8.1.1