1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 #ifndef itkMedianImageFilter_h 19 #define itkMedianImageFilter_h 20 21 #include "itkBoxImageFilter.h" 22 #include "itkImage.h" 23 24 namespace itk 25 { 26 /** \class MedianImageFilter 27 * \brief Applies a median filter to an image 28 * 29 * Computes an image where a given pixel is the median value of the 30 * the pixels in a neighborhood about the corresponding input pixel. 31 * 32 * A median filter is one of the family of nonlinear filters. It is 33 * used to smooth an image without being biased by outliers or shot noise. 34 * 35 * This filter requires that the input pixel type provides an operator<() 36 * (LessThan Comparable). 37 * 38 * \sa Image 39 * \sa Neighborhood 40 * \sa NeighborhoodOperator 41 * \sa NeighborhoodIterator 42 * 43 * \ingroup IntensityImageFilters 44 * \ingroup ITKSmoothing 45 * 46 * \wiki 47 * \wikiexample{Smoothing/MedianImageFilter,Median filter an image} 48 * \wikiexample{Smoothing/RGBMedianImageFilter,Median filter an RGB image} 49 * \endwiki 50 */ 51 template< typename TInputImage, typename TOutputImage > 52 class ITK_TEMPLATE_EXPORT MedianImageFilter: 53 public BoxImageFilter< TInputImage, TOutputImage > 54 { 55 public: 56 ITK_DISALLOW_COPY_AND_ASSIGN(MedianImageFilter); 57 58 /** Extract dimension from input and output image. */ 59 static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension; 60 static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension; 61 62 /** Convenient type alias for simplifying declarations. */ 63 using InputImageType = TInputImage; 64 using OutputImageType = TOutputImage; 65 66 /** Standard class type aliases. */ 67 using Self = MedianImageFilter; 68 using Superclass = ImageToImageFilter< InputImageType, OutputImageType >; 69 using Pointer = SmartPointer< Self >; 70 using ConstPointer = SmartPointer< const Self >; 71 72 /** Method for creation through the object factory. */ 73 itkNewMacro(Self); 74 75 /** Run-time type information (and related methods). */ 76 itkTypeMacro(MedianImageFilter, BoxImageFilter); 77 78 /** Image type alias support */ 79 using InputPixelType = typename InputImageType::PixelType; 80 using OutputPixelType = typename OutputImageType::PixelType; 81 82 using InputImageRegionType = typename InputImageType::RegionType; 83 using OutputImageRegionType = typename OutputImageType::RegionType; 84 85 using InputSizeType = typename InputImageType::SizeType; 86 87 #ifdef ITK_USE_CONCEPT_CHECKING 88 // Begin concept checking 89 itkConceptMacro( SameDimensionCheck, 90 ( Concept::SameDimension< InputImageDimension, OutputImageDimension > ) ); 91 itkConceptMacro( InputConvertibleToOutputCheck, 92 ( Concept::Convertible< InputPixelType, OutputPixelType > ) ); 93 itkConceptMacro( InputLessThanComparableCheck, 94 ( Concept::LessThanComparable< InputPixelType > ) ); 95 // End concept checking 96 #endif 97 98 protected: 99 MedianImageFilter(); 100 ~MedianImageFilter() override = default; 101 102 /** MedianImageFilter can be implemented as a multithreaded filter. 103 * Therefore, this implementation provides a ThreadedGenerateData() 104 * routine which is called for each processing thread. The output 105 * image data is allocated automatically by the superclass prior to 106 * calling ThreadedGenerateData(). ThreadedGenerateData can only 107 * write to the portion of the output image specified by the 108 * parameter "outputRegionForThread" 109 * 110 * \sa ImageToImageFilter::ThreadedGenerateData(), 111 * ImageToImageFilter::GenerateData() */ 112 void DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override; 113 114 }; 115 } // end namespace itk 116 117 #ifndef ITK_MANUAL_INSTANTIATION 118 #include "itkMedianImageFilter.hxx" 119 #endif 120 121 #endif 122