diff --git a/.clang-format b/.clang-format index 399e250..92c5002 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,7 @@ ## See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html for details of each option ## ## The clang-format binaries can be downloaded as part of the clang binary distributions -## from http://releases.llvm.org/download.html +## from https://releases.llvm.org/download.html ## ## Use the script Utilities/Maintenance/clang-format.bash to faciliate ## maintaining a consistent code style. @@ -21,7 +21,7 @@ AccessModifierOffset: -2 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: true -AlignEscapedNewlines: Right +AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true # clang 9.0 AllowAllArgumentsOnNextLine: true diff --git a/.editorconfig b/.editorconfig index 7b95893..648b969 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -# http://EditorConfig.org +# https://EditorConfig.org # top-most EditorConfig file root = true diff --git a/.github/workflows/build-test-package.yml b/.github/workflows/build-test-package.yml new file mode 100644 index 0000000..40189fb --- /dev/null +++ b/.github/workflows/build-test-package.yml @@ -0,0 +1,12 @@ +name: Build, test, package + +on: [push,pull_request] + +jobs: + cxx-build-workflow: + uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-cxx.yml@v5.3.0 + + python-build-workflow: + uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-package-python.yml@v5.3.0 + secrets: + pypi_password: ${{ secrets.pypi_password }} diff --git a/.github/workflows/clang-format-linter.yml b/.github/workflows/clang-format-linter.yml index c59dd58..69166d9 100644 --- a/.github/workflows/clang-format-linter.yml +++ b/.github/workflows/clang-format-linter.yml @@ -8,5 +8,6 @@ jobs: steps: - uses: actions/checkout@v1 - + with: + fetch-depth: 1 - uses: InsightSoftwareConsortium/ITKClangFormatLinterAction@master diff --git a/include/itkFastBilateralImageFilter.h b/include/itkFastBilateralImageFilter.h index 5938596..ba11520 100644 --- a/include/itkFastBilateralImageFilter.h +++ b/include/itkFastBilateralImageFilter.h @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * https://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,57 +28,56 @@ namespace itk { /** -* \class FastBilateralImageFilter -* \brief A fast approximation to the bilateral filter -* \ingroup FastBilateral -* -* This filter is a fast approximation to the bilateral filter. -* Blurring is performed on an image based on the distance of pixels in -* both space and intensity. -* -* The algorithm used was originally proposed by Paris and -* Durand [1]. -* -* Instead of calculating a kernel for every pixel in -* an image, this filter places the values of each pixel into a higher -* dimensional image determined by the position and intensity of a pixel. -* How many bins are used is determined by the sigma values provided -* to the filter. Larger sigmas will result in more aggresive downsampling -* and less running time overall. After the data of an image -* has been organized into bins, a DiscreteGaussianImageFilter is applied. -* Finally, the output image is constructed by interpolating the -* values of the output pixels from the blurred higher -* dimensional image. -* -* [1] Sylvain Paris and Frédo Durand, -* A Fast Approximation of the Bilateral Filter using a Signal Processing -* Approach, -* European Conference on Computer Vision (ECCV'06) -* -* \sa BilateralImageFilter -* \sa GaussianOperator -* \sa AnisotropicDiffusionImageFilter -* \sa Image -* \sa Neighborhood -* \sa NeighborhoodOperator -* -* \ingroup ImageEnhancement -* \ingroup ImageFeatureExtraction -* -* \todo Support for color images -* \todo Support for vector images -*/ - -template -class ITK_EXPORT FastBilateralImageFilter : - public ImageToImageFilter< TInputImage, TOutputImage > + * \class FastBilateralImageFilter + * \brief A fast approximation to the bilateral filter + * \ingroup FastBilateral + * + * This filter is a fast approximation to the bilateral filter. + * Blurring is performed on an image based on the distance of pixels in + * both space and intensity. + * + * The algorithm used was originally proposed by Paris and + * Durand [1]. + * + * Instead of calculating a kernel for every pixel in + * an image, this filter places the values of each pixel into a higher + * dimensional image determined by the position and intensity of a pixel. + * How many bins are used is determined by the sigma values provided + * to the filter. Larger sigmas will result in more aggresive downsampling + * and less running time overall. After the data of an image + * has been organized into bins, a DiscreteGaussianImageFilter is applied. + * Finally, the output image is constructed by interpolating the + * values of the output pixels from the blurred higher + * dimensional image. + * + * [1] Sylvain Paris and Frédo Durand, + * A Fast Approximation of the Bilateral Filter using a Signal Processing + * Approach, + * European Conference on Computer Vision (ECCV'06) + * + * \sa BilateralImageFilter + * \sa GaussianOperator + * \sa AnisotropicDiffusionImageFilter + * \sa Image + * \sa Neighborhood + * \sa NeighborhoodOperator + * + * \ingroup ImageEnhancement + * \ingroup ImageFeatureExtraction + * + * \todo Support for color images + * \todo Support for vector images + */ + +template +class ITK_EXPORT FastBilateralImageFilter : public ImageToImageFilter { public: ITK_DISALLOW_COPY_AND_MOVE(FastBilateralImageFilter); /** Standard class typedefs. */ using Self = FastBilateralImageFilter; - using Superclass = ImageToImageFilter< TInputImage, TOutputImage >; + using Superclass = ImageToImageFilter; using Pointer = SmartPointer; using ConstPointer = SmartPointer; @@ -128,21 +127,21 @@ class ITK_EXPORT FastBilateralImageFilter : /** Convenience set method for setting all domain standard deviations to the * same value. */ - void SetDomainSigma(const double v) - { + void + SetDomainSigma(const double v) + { m_DomainSigma.Fill(v); - } + } protected: - /** Default Constructor. Default value for DomainSigma is 4. Default * value for RangeSigma is 50. These values were chosen match those of the * BilateralImageFilter */ FastBilateralImageFilter() - { + { m_DomainSigma.Fill(4.0); m_RangeSigma = 50.0; - } + } virtual ~FastBilateralImageFilter() {} @@ -152,23 +151,26 @@ class ITK_EXPORT FastBilateralImageFilter : * the BilateralImageFilter, the FastBilateralImageFilter needs * an amount of padding in each dimension based on the domain sigma. */ - virtual void GenerateInputRequestedRegion(); + void + GenerateInputRequestedRegion() override; /** Standard pipline method */ - void GenerateData(); + void + GenerateData() override; /** Method to print member variables to an output stream */ - void PrintSelf(std::ostream& os, Indent indent) const; + void + PrintSelf(std::ostream & os, Indent indent) const override; /** The type of image to use as the higher dimensional grid. * The blurring is performed on this image type. */ - using GridType = typename itk::Image; + using GridType = typename itk::Image; /** Grid types */ using GridPixelType = typename GridType::PixelType; using GridIndexType = typename GridType::IndexType; using GridSizeType = typename GridType::SizeType; - using GridSizeValueType = typename Size::SizeValueType; + using GridSizeValueType = typename Size::SizeValueType; using GridRegionType = typename GridType::RegionType; /** Grid image iterator type. */ @@ -176,20 +178,20 @@ class ITK_EXPORT FastBilateralImageFilter : using GridImageConstIteratorType = ImageRegionConstIterator; /** The type of blurring to use on the grid. */ - using BlurType = DiscreteGaussianImageFilter< GridType, GridType >; + using BlurType = DiscreteGaussianImageFilter; /** The type of interpolation done to calculate output pixels. */ using InterpolatorType = LinearInterpolateImageFunction; using InterpolatedIndexType = typename InterpolatorType::ContinuousIndexType; - double m_RangeSigma; - DomainSigmaArrayType m_DomainSigma; + double m_RangeSigma; + DomainSigmaArrayType m_DomainSigma; }; } // namespace itk #ifndef ITK_MANUAL_INSTANTIATION -#include "itkFastBilateralImageFilter.hxx" +# include "itkFastBilateralImageFilter.hxx" #endif #endif // itkFastBilateralImageFilter diff --git a/include/itkFastBilateralImageFilter.hxx b/include/itkFastBilateralImageFilter.hxx index 54db96e..bc2778a 100644 --- a/include/itkFastBilateralImageFilter.hxx +++ b/include/itkFastBilateralImageFilter.hxx @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * https://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,21 +27,19 @@ namespace itk template void -FastBilateralImageFilter -::GenerateInputRequestedRegion() +FastBilateralImageFilter::GenerateInputRequestedRegion() { // call the superclass' implementation of this method. this should // copy the output requested region to the input requested region Superclass::GenerateInputRequestedRegion(); // get pointers to the input and output - typename Superclass::InputImagePointer inputPtr = - const_cast< TInputImage *>( this->GetInput() ); + typename Superclass::InputImagePointer inputPtr = const_cast(this->GetInput()); - if ( !inputPtr ) - { + if (!inputPtr) + { return; - } + } // Pad the image by 2*sigma (pixel units) // this is done to ensure that nearby pixels are still @@ -53,10 +51,9 @@ FastBilateralImageFilter // Each bin can contain at most ceil(sigma) pixels InputImageSizeType radius; for (size_t i = 0; i < ImageDimension; ++i) - { - radius[i] = - 2*std::ceil(m_DomainSigma[i] / (this->GetInput()->GetSpacing()[i])); - } + { + radius[i] = 2 * std::ceil(m_DomainSigma[i] / (this->GetInput()->GetSpacing()[i])); + } // get a copy of the input requested region (should equal the output // requested region) @@ -64,47 +61,45 @@ FastBilateralImageFilter inputRequestedRegion = inputPtr->GetRequestedRegion(); // pad the input requested region by the operator radius - inputRequestedRegion.PadByRadius( radius ); + inputRequestedRegion.PadByRadius(radius); // crop the input requested region at the input's largest possible region - if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) ) - { - inputPtr->SetRequestedRegion( inputRequestedRegion ); + if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion())) + { + inputPtr->SetRequestedRegion(inputRequestedRegion); return; - } + } else - { + { // Couldn't crop the region (requested region is outside the largest // possible region). Throw an exception. // store what we tried to request (prior to trying to crop) - inputPtr->SetRequestedRegion( inputRequestedRegion ); + inputPtr->SetRequestedRegion(inputRequestedRegion); // build an exception InvalidRequestedRegionError e(__FILE__, __LINE__); e.SetLocation(ITK_LOCATION); - e.SetDescription - ("Requested region is outside the largest possible region."); + e.SetDescription("Requested region is outside the largest possible region."); e.SetDataObject(inputPtr); throw e; - } + } } -template< class TInputImage, class TOutputImage > +template void -FastBilateralImageFilter -::GenerateData() +FastBilateralImageFilter::GenerateData() { this->AllocateOutputs(); InputImageConstPointer input = this->GetInput(); - OutputImagePointer output = this->GetOutput(); + OutputImagePointer output = this->GetOutput(); // Array to store domain sigmas, used during down-sampling and reconstruction - DomainSigmaArrayType domainSigmaInPixels; + DomainSigmaArrayType domainSigmaInPixels; // Minimum intensity of the input image, - //used during down-sampling and reconstruction - InputPixelType intensityMin; + // used during down-sampling and reconstruction + InputPixelType intensityMin; // Define the GridType // These are pointers to the source and destination of the blurring filter @@ -123,51 +118,46 @@ FastBilateralImageFilter // Setup the higher dimensional grids (gridImage and gridWeight). { - GridIndexType gridStartPos; - GridSizeType gridSize; - - // Convert domain sigmas from spacing units to pixel units - // for the blurring in the grid. - // The set method for m_DomainSigma uses spacing units to be - // consistent with the itkBilateralImageFilter implementation. - // When the data is placed into bins in the grid the - // itkDiscreteGaussianImageFilter will be run on the grid using - // imageSpacingOff. - InputImageSizeType inputSize = input->GetRequestedRegion().GetSize(); -// InputImageSizeType fullSize = input->GetLargestPossibleRegion().GetSize(); - - const InputImageSpacingType& spacing = input->GetSpacing(); - for (size_t i = 0; i < ImageDimension; ++i) + GridIndexType gridStartPos; + GridSizeType gridSize; + + // Convert domain sigmas from spacing units to pixel units + // for the blurring in the grid. + // The set method for m_DomainSigma uses spacing units to be + // consistent with the itkBilateralImageFilter implementation. + // When the data is placed into bins in the grid the + // itkDiscreteGaussianImageFilter will be run on the grid using + // imageSpacingOff. + InputImageSizeType inputSize = input->GetRequestedRegion().GetSize(); + // InputImageSizeType fullSize = input->GetLargestPossibleRegion().GetSize(); + + const InputImageSpacingType & spacing = input->GetSpacing(); + for (size_t i = 0; i < ImageDimension; ++i) { - domainSigmaInPixels[i] = m_DomainSigma[i] / spacing[i]; - gridSize[i] = std::floor( (inputSize[i] - 1) / domainSigmaInPixels[i] ) - + 1 + 2*padding; + domainSigmaInPixels[i] = m_DomainSigma[i] / spacing[i]; + gridSize[i] = std::floor((inputSize[i] - 1) / domainSigmaInPixels[i]) + 1 + 2 * padding; } - // Determine min/max intensities to calculate grid size in the intensity axis - using MinMaxCalculatorType = MinimumMaximumImageCalculator< InputImageType >; - typename MinMaxCalculatorType::Pointer calculator = - MinMaxCalculatorType::New(); - - calculator->SetImage(input); - calculator->Compute(); - intensityMin = calculator->GetMinimum(); - InputPixelType intensityMax = calculator->GetMaximum(); - InputPixelType intensityDelta = - static_cast(intensityMax - intensityMin); - gridSize[ImageDimension] = - static_cast((intensityDelta/m_RangeSigma)+1+2*padding); - - for(size_t i = 0; i < ImageDimension+1; ++i) + // Determine min/max intensities to calculate grid size in the intensity axis + using MinMaxCalculatorType = MinimumMaximumImageCalculator; + typename MinMaxCalculatorType::Pointer calculator = MinMaxCalculatorType::New(); + + calculator->SetImage(input); + calculator->Compute(); + intensityMin = calculator->GetMinimum(); + InputPixelType intensityMax = calculator->GetMaximum(); + InputPixelType intensityDelta = static_cast(intensityMax - intensityMin); + gridSize[ImageDimension] = static_cast((intensityDelta / m_RangeSigma) + 1 + 2 * padding); + + for (size_t i = 0; i < ImageDimension + 1; ++i) { - gridStartPos[i] = 0; + gridStartPos[i] = 0; } - GridRegionType region; - region.SetSize(gridSize); - region.SetIndex(gridStartPos); - gridImage->SetRegions(region); - + GridRegionType region; + region.SetSize(gridSize); + region.SetIndex(gridStartPos); + gridImage->SetRegions(region); } // Allocate the memory for pixel data @@ -180,44 +170,40 @@ FastBilateralImageFilter // Duplicate our grid image for the weight image { - using DuplicatorType = ImageDuplicator; - typename DuplicatorType::Pointer duplicator = DuplicatorType::New(); - duplicator->SetInputImage(gridImage); - duplicator->Update(); - gridWeight = duplicator->GetOutput(); + using DuplicatorType = ImageDuplicator; + typename DuplicatorType::Pointer duplicator = DuplicatorType::New(); + duplicator->SetInputImage(gridImage); + duplicator->Update(); + gridWeight = duplicator->GetOutput(); } // Sort the input image in gridImage and keep track of weights in gridWeight { - InputImageConstIteratorType iterInputImage - (input, input->GetRequestedRegion()); - GridIndexType gridIndices; - size_t i; - InputPixelType current; - InputPixelType intensityDelta; - InputImageIndexType index; - - // For every pixel in the input image, place it into a bin in the grid - // This is a scatter type operation and will be inefficient, as far as I - // know, there is no way to place the pixels into the grid using iterators - for ( iterInputImage.GoToBegin(); !iterInputImage.IsAtEnd(); - ++iterInputImage) + InputImageConstIteratorType iterInputImage(input, input->GetRequestedRegion()); + GridIndexType gridIndices; + size_t i; + InputPixelType current; + InputPixelType intensityDelta; + InputImageIndexType index; + + // For every pixel in the input image, place it into a bin in the grid + // This is a scatter type operation and will be inefficient, as far as I + // know, there is no way to place the pixels into the grid using iterators + for (iterInputImage.GoToBegin(); !iterInputImage.IsAtEnd(); ++iterInputImage) { - index = iterInputImage.GetIndex(); - current = iterInputImage.Get(); - // Determine the position in the grid to place the pixel - for ( i = 0; i < ImageDimension; ++i) + index = iterInputImage.GetIndex(); + current = iterInputImage.Get(); + // Determine the position in the grid to place the pixel + for (i = 0; i < ImageDimension; ++i) { - gridIndices[i] = static_cast - (index[i]/domainSigmaInPixels[i]+0.5+padding); + gridIndices[i] = static_cast(index[i] / domainSigmaInPixels[i] + 0.5 + padding); } - intensityDelta = current - intensityMin; - gridIndices[ImageDimension] = - static_cast(intensityDelta/m_RangeSigma+0.5+padding); + intensityDelta = current - intensityMin; + gridIndices[ImageDimension] = static_cast(intensityDelta / m_RangeSigma + 0.5 + padding); - // Update the bin and the weight - (gridImage->GetPixel(gridIndices)) += current; - (gridWeight->GetPixel(gridIndices)) += 1.0; + // Update the bin and the weight + (gridImage->GetPixel(gridIndices)) += current; + (gridWeight->GetPixel(gridIndices)) += 1.0; } } @@ -225,33 +211,33 @@ FastBilateralImageFilter // outputs are pointed to by gridImageOut and gridWeightOut { - // This variance approximately corresponds to a 1D filter of [1 2 1] which is - // used in Paris and Durands C++ implementation to blur their down-sampled - // data. With this variance a kernel width larger than 5 is not necessary. - double variance = 1.59577; - int maxWidth = 5; + // This variance approximately corresponds to a 1D filter of [1 2 1] which is + // used in Paris and Durands C++ implementation to blur their down-sampled + // data. With this variance a kernel width larger than 5 is not necessary. + double variance = 1.59577; + int maxWidth = 5; - // Setup the Gaussian filter - typename BlurType::Pointer gridImageBlurFilter = BlurType::New(); - typename BlurType::Pointer gridWeightBlurFilter = BlurType::New(); + // Setup the Gaussian filter + typename BlurType::Pointer gridImageBlurFilter = BlurType::New(); + typename BlurType::Pointer gridWeightBlurFilter = BlurType::New(); - gridImageBlurFilter ->SetVariance(variance); - gridWeightBlurFilter->SetVariance(variance); + gridImageBlurFilter->SetVariance(variance); + gridWeightBlurFilter->SetVariance(variance); - gridImageBlurFilter ->SetUseImageSpacingOff(); - gridWeightBlurFilter->SetUseImageSpacingOff(); + gridImageBlurFilter->SetUseImageSpacingOff(); + gridWeightBlurFilter->SetUseImageSpacingOff(); - gridImageBlurFilter ->SetMaximumKernelWidth(maxWidth); - gridWeightBlurFilter->SetMaximumKernelWidth(maxWidth); + gridImageBlurFilter->SetMaximumKernelWidth(maxWidth); + gridWeightBlurFilter->SetMaximumKernelWidth(maxWidth); - gridImageBlurFilter ->SetInput(gridImage); - gridWeightBlurFilter->SetInput(gridWeight); + gridImageBlurFilter->SetInput(gridImage); + gridWeightBlurFilter->SetInput(gridWeight); - gridImageOut = gridImageBlurFilter ->GetOutput(); - gridWeightOut = gridWeightBlurFilter->GetOutput(); + gridImageOut = gridImageBlurFilter->GetOutput(); + gridWeightOut = gridWeightBlurFilter->GetOutput(); - gridImageBlurFilter ->Update(); - gridWeightBlurFilter->Update(); + gridImageBlurFilter->Update(); + gridWeightBlurFilter->Update(); } // Early division; in Paris and Durand's implementation early division can @@ -259,19 +245,17 @@ FastBilateralImageFilter // weights can be done then the division. Interpolation is an expensive // operation so I've opted for the early division approach. { - GridImageIteratorType iterGridImage - (gridImageOut, gridImageOut->GetLargestPossibleRegion()); - GridImageConstIteratorType iterGridWeight - (gridWeightOut, gridWeightOut->GetLargestPossibleRegion()); + GridImageIteratorType iterGridImage(gridImageOut, gridImageOut->GetLargestPossibleRegion()); + GridImageConstIteratorType iterGridWeight(gridWeightOut, gridWeightOut->GetLargestPossibleRegion()); - GridPixelType weight; + GridPixelType weight; - for ( iterGridImage.GoToBegin(), iterGridWeight.GoToBegin(); - !iterGridImage.IsAtEnd(); ++iterGridImage, ++iterGridWeight) + for (iterGridImage.GoToBegin(), iterGridWeight.GoToBegin(); !iterGridImage.IsAtEnd(); + ++iterGridImage, ++iterGridWeight) { - if ( (weight = iterGridWeight.Get() ) != 0.0 ) + if ((weight = iterGridWeight.Get()) != 0.0) { - iterGridImage.Value() /= weight; + iterGridImage.Value() /= weight; } } } @@ -281,53 +265,45 @@ FastBilateralImageFilter // was placed and interpolate for the output pixel's value. { - OutputImageIteratorType iterOutputImage - (output, output->GetRequestedRegion()); - InputImageConstIteratorType iterInputImage - (input, output->GetRequestedRegion()); - - InterpolatedIndexType gridIndices; - size_t i; - InputPixelType current; - InputPixelType intensityDelta; - InputImageIndexType index; - typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); - interpolator->SetInputImage(gridImageOut); - - for ( iterOutputImage.GoToBegin(), iterInputImage.GoToBegin(); - !iterOutputImage.IsAtEnd(); ++iterOutputImage, ++iterInputImage) + OutputImageIteratorType iterOutputImage(output, output->GetRequestedRegion()); + InputImageConstIteratorType iterInputImage(input, output->GetRequestedRegion()); + + InterpolatedIndexType gridIndices; + size_t i; + InputPixelType current; + InputPixelType intensityDelta; + InputImageIndexType index; + typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); + interpolator->SetInputImage(gridImageOut); + + for (iterOutputImage.GoToBegin(), iterInputImage.GoToBegin(); !iterOutputImage.IsAtEnd(); + ++iterOutputImage, ++iterInputImage) { - index = iterInputImage.GetIndex(); - current = iterInputImage.Get(); - // Determine the position in the grid to get the data from - for ( i = 0; i < ImageDimension; ++i) + index = iterInputImage.GetIndex(); + current = iterInputImage.Get(); + // Determine the position in the grid to get the data from + for (i = 0; i < ImageDimension; ++i) { - gridIndices[i] = index[i] / domainSigmaInPixels[i] + padding; + gridIndices[i] = index[i] / domainSigmaInPixels[i] + padding; } - intensityDelta = current - intensityMin; + intensityDelta = current - intensityMin; - gridIndices[ImageDimension] = - intensityDelta / m_RangeSigma + padding; - - iterOutputImage.Set( static_cast - (interpolator->EvaluateAtContinuousIndex(gridIndices)) - ); + gridIndices[ImageDimension] = intensityDelta / m_RangeSigma + padding; + iterOutputImage.Set(static_cast(interpolator->EvaluateAtContinuousIndex(gridIndices))); } } } -template< class TInputImage, class TOutputImage > +template void -FastBilateralImageFilter -::PrintSelf(std::ostream& os, Indent indent) const +FastBilateralImageFilter::PrintSelf(std::ostream & os, Indent indent) const { - Superclass::PrintSelf(os,indent); + Superclass::PrintSelf(os, indent); os << indent << "DomainSigma: " << m_DomainSigma << std::endl; os << indent << "RangeSigma: " << m_RangeSigma << std::endl; - } } // namespace itk diff --git a/test/itkFastBilateralImageFilterTest.cxx b/test/itkFastBilateralImageFilterTest.cxx index b894a31..7303fe6 100644 --- a/test/itkFastBilateralImageFilterTest.cxx +++ b/test/itkFastBilateralImageFilterTest.cxx @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * https://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/test/itkFastBilateralImageFilterTest2.cxx b/test/itkFastBilateralImageFilterTest2.cxx index 94f97d6..5d4241c 100755 --- a/test/itkFastBilateralImageFilterTest2.cxx +++ b/test/itkFastBilateralImageFilterTest2.cxx @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * https://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,13 +26,14 @@ * This test was originally taken from the tests for the itkBilateralImageFilter * and modified for the itkFastBilateralImageFilter. */ -int itkFastBilateralImageFilterTest2(int ac, char* av[] ) +int +itkFastBilateralImageFilterTest2(int ac, char * av[]) { - if(ac < 3) - { + if (ac < 3) + { std::cerr << "Usage: " << av[0] << " InputImage OutputImage\n"; return EXIT_FAILURE; - } + } using PixelType = unsigned char; const unsigned int dimension = 2; @@ -41,7 +42,7 @@ int itkFastBilateralImageFilterTest2(int ac, char* av[] ) input->SetFileName(av[1]); // Create a filter - using FilterType = itk::FastBilateralImageFilter; + using FilterType = itk::FastBilateralImageFilter; auto filter = FilterType::New(); @@ -49,16 +50,16 @@ int itkFastBilateralImageFilterTest2(int ac, char* av[] ) // these settings reduce the amount of noise by a factor of 10 // when the original signal to noise level is 5 - filter->SetDomainSigma( 4.0 ); - filter->SetRangeSigma( 50.0 ); + filter->SetDomainSigma(4.0); + filter->SetRangeSigma(50.0); // Test itkSetVectorMacro double domainSigma[dimension]; for (unsigned int i = 0; i < dimension; i++) - { - domainSigma[i] = 4.0; - } + { + domainSigma[i] = 4.0; + } filter->SetDomainSigma(domainSigma); // Test itkGetMacro @@ -66,27 +67,27 @@ int itkFastBilateralImageFilterTest2(int ac, char* av[] ) std::cout << "filter->GetRangeSigma(): " << filter->GetRangeSigma() << std::endl; try - { + { input->Update(); filter->Update(); - } - catch (itk::ExceptionObject& e) - { - std::cerr << "Exception detected: " << e.GetDescription(); + } + catch (itk::ExceptionObject & e) + { + std::cerr << "Exception detected: " << e.GetDescription(); return -1; - } + } catch (...) - { + { std::cerr << "Some other exception occurred" << std::endl; return -2; - } + } // Generate test image itk::ImageFileWriter::Pointer writer; - writer = itk::ImageFileWriter::New(); - writer->SetInput( filter->GetOutput() ); - writer->SetFileName( av[2] ); - writer->Update(); + writer = itk::ImageFileWriter::New(); + writer->SetInput(filter->GetOutput()); + writer->SetFileName(av[2]); + writer->Update(); return EXIT_SUCCESS; } diff --git a/test/itkFastBilateralImageFilterTest3.cxx b/test/itkFastBilateralImageFilterTest3.cxx index 240cced..fc1c48e 100755 --- a/test/itkFastBilateralImageFilterTest3.cxx +++ b/test/itkFastBilateralImageFilterTest3.cxx @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * https://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,13 +28,14 @@ * This test was originally taken from the tests for the itkBilateralImageFilter * and modified for the itkFastBilateralImageFilter. */ -int itkFastBilateralImageFilterTest3(int ac, char* av[] ) +int +itkFastBilateralImageFilterTest3(int ac, char * av[]) { - if(ac < 3) - { + if (ac < 3) + { std::cerr << "Usage: " << av[0] << " InputImage BaselineImage\n"; return -1; - } + } using PixelType = unsigned char; using ImageType = itk::Image; @@ -42,49 +43,49 @@ int itkFastBilateralImageFilterTest3(int ac, char* av[] ) input->SetFileName(av[1]); // Create a filter - using FilterType = itk::FastBilateralImageFilter; + using FilterType = itk::FastBilateralImageFilter; FilterType::Pointer filter1 = FilterType::New(); - filter1->SetInput(input->GetOutput()); + filter1->SetInput(input->GetOutput()); FilterType::Pointer filter2 = FilterType::New(); - filter2->SetInput(filter1->GetOutput()); + filter2->SetInput(filter1->GetOutput()); FilterType::Pointer filter3 = FilterType::New(); - filter3->SetInput(filter2->GetOutput()); + filter3->SetInput(filter2->GetOutput()); - // Instead of using a single agressive smoothing filter, use 3 - // less aggressive filters. - // - // These settings match the "wedding" cake image (cake_easy.png) where - // the signal to noise ratio is 5 (step heights near 100 units, - // noise sigma near 20 units). A single filter stage with these - // settings cuts the noise level in half. These three stages should - // reduce the amount of noise by a factor of 8. This is comparable to - // the noise reduction in using a single stage with parameters - // (4.0, 50.0). The difference is that with 3 less aggressive stages - // the edges are preserved better. - filter1->SetDomainSigma( 4.0 ); - filter1->SetRangeSigma( 20.0 ); - filter2->SetDomainSigma( 4.0 ); - filter2->SetRangeSigma( 20.0 ); - filter3->SetDomainSigma( 4.0 ); - filter3->SetRangeSigma( 20.0 ); + // Instead of using a single agressive smoothing filter, use 3 + // less aggressive filters. + // + // These settings match the "wedding" cake image (cake_easy.png) where + // the signal to noise ratio is 5 (step heights near 100 units, + // noise sigma near 20 units). A single filter stage with these + // settings cuts the noise level in half. These three stages should + // reduce the amount of noise by a factor of 8. This is comparable to + // the noise reduction in using a single stage with parameters + // (4.0, 50.0). The difference is that with 3 less aggressive stages + // the edges are preserved better. + filter1->SetDomainSigma(4.0); + filter1->SetRangeSigma(20.0); + filter2->SetDomainSigma(4.0); + filter2->SetRangeSigma(20.0); + filter3->SetDomainSigma(4.0); + filter3->SetRangeSigma(20.0); try - { + { input->Update(); filter3->Update(); - } - catch (itk::ExceptionObject& e) - { - std::cerr << "Exception detected: " << e.GetDescription(); + } + catch (itk::ExceptionObject & e) + { + std::cerr << "Exception detected: " << e.GetDescription(); return -1; - } + } // Generate test image itk::ImageFileWriter::Pointer writer; writer = itk::ImageFileWriter::New(); - writer->SetInput( filter3->GetOutput() ); - writer->SetFileName( av[2] ); + writer->SetInput(filter3->GetOutput()); + writer->SetFileName(av[2]); writer->Update(); return EXIT_SUCCESS;