20 #include <itkRecursiveMultiResolutionPyramidImageFilter.h> 21 #include <itkLaplacianRecursiveGaussianImageFilter.h> 24 #include <itkWaveletFrequencyForward.h> 25 #include <itkWaveletFrequencyFilterBankGenerator.h> 26 #include <itkHeldIsotropicWavelet.h> 27 #include <itkVowIsotropicWavelet.h> 28 #include <itkSimoncelliIsotropicWavelet.h> 29 #include <itkShannonIsotropicWavelet.h> 30 #include <itkForwardFFTImageFilter.h> 31 #include <itkInverseFFTImageFilter.h> 32 #include <itkFFTPadPositiveIndexImageFilter.h> 33 #include "itkZeroFluxNeumannBoundaryCondition.h" 34 #include "itkPeriodicBoundaryCondition.h" 35 #include "itkConstantBoundaryCondition.h" 37 #include "itkCastImageFilter.h" 39 #include "itkUnaryFunctorImageFilter.h" 42 #include <itkImageDuplicator.h> 48 template<
class TInput>
58 bool operator==(
const ThresholdValue & other)
const 60 return !(*
this != other);
62 inline unsigned short operator()(
const TInput & A)
const 72 template<
class TInput,
class TOutput>
82 bool operator==(
const RoundValue & other)
const 84 return !(*
this != other);
86 inline TOutput operator()(
const TInput & A)
const 94 template<
typename TPixel,
unsigned int VImageDimension>
95 static void ExecuteMultiResolution(itk::Image<TPixel, VImageDimension>*
image,
unsigned int numberOfLevels,
bool outputAsDouble, std::vector<mitk::Image::Pointer> &resultImages)
97 typedef itk::Image<TPixel, VImageDimension>
ImageType;
98 typedef itk::Image<double, VImageDimension> DoubleOutputType;
99 typedef itk::RecursiveMultiResolutionPyramidImageFilter<ImageType, ImageType> ImageTypeFilterType;
100 typedef itk::RecursiveMultiResolutionPyramidImageFilter<ImageType, DoubleOutputType> DoubleTypeFilterType;
104 typename DoubleTypeFilterType::Pointer recursiveMultiResolutionPyramidImageFilter = DoubleTypeFilterType::New();
105 recursiveMultiResolutionPyramidImageFilter->SetInput(image);
106 recursiveMultiResolutionPyramidImageFilter->SetNumberOfLevels(numberOfLevels);
107 recursiveMultiResolutionPyramidImageFilter->Update();
110 for (
unsigned int i = 0; i < numberOfLevels; ++i)
113 CastToMitkImage(recursiveMultiResolutionPyramidImageFilter->GetOutput(i), outputImage);
114 resultImages.push_back(outputImage);
118 typename ImageTypeFilterType::Pointer recursiveMultiResolutionPyramidImageFilter = ImageTypeFilterType::New();
119 recursiveMultiResolutionPyramidImageFilter->SetInput(image);
120 recursiveMultiResolutionPyramidImageFilter->SetNumberOfLevels(numberOfLevels);
121 recursiveMultiResolutionPyramidImageFilter->Update();
124 for (
unsigned int i = 0; i < numberOfLevels; ++i)
127 CastToMitkImage(recursiveMultiResolutionPyramidImageFilter->GetOutput(i), outputImage);
128 resultImages.push_back(outputImage);
135 std::vector<Image::Pointer> resultImages;
143 template<
typename TPixel,
unsigned int VImageDimension>
146 typedef itk::Image<TPixel, VImageDimension>
ImageType;
147 typedef itk::Image<double, VImageDimension> DoubleOutputType;
148 typedef itk::LaplacianRecursiveGaussianImageFilter<ImageType, ImageType> ImageTypeFilterType;
149 typedef itk::LaplacianRecursiveGaussianImageFilter<ImageType, DoubleOutputType> DoubleTypeFilterType;
153 typename DoubleTypeFilterType::Pointer filter = DoubleTypeFilterType::New();
154 filter->SetInput(image);
155 filter->SetSigma(sigma);
161 typename ImageTypeFilterType::Pointer filter = ImageTypeFilterType::New();
162 filter->SetInput(image);
163 filter->SetSigma(sigma);
179 template<
typename TInputPixel,
typename TOutputPixel,
unsigned int VImageDimension,
typename TWaveletFunction >
182 const unsigned int Dimension = VImageDimension;
183 typedef TInputPixel PixelType;
184 typedef TOutputPixel OutputPixelType;
185 typedef itk::Image< PixelType, Dimension >
ImageType;
186 typedef itk::Image< double, Dimension > DoubleImageType;
187 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
189 typedef itk::CastImageFilter< ImageType, DoubleImageType > CastFilterType;
190 typedef itk::FFTPadPositiveIndexImageFilter< DoubleImageType > FFTPadType;
191 typedef itk::ForwardFFTImageFilter< DoubleImageType, itk::Image< std::complex<double>, Dimension> > FFTFilterType;
192 typedef typename FFTFilterType::OutputImageType ComplexImageType;
194 typedef TWaveletFunction WaveletFunctionType;
195 typedef itk::WaveletFrequencyFilterBankGenerator< ComplexImageType, WaveletFunctionType > WaveletFilterBankType;
196 typedef itk::WaveletFrequencyForward< ComplexImageType, ComplexImageType, WaveletFilterBankType > ForwardWaveletType;
198 typedef itk::InverseFFTImageFilter< ComplexImageType, OutputImageType > InverseFFTFilterType;
201 unsigned int highSubBands = numberOfBands;
202 unsigned int levels = numberOfLevels;
206 typename CastFilterType::Pointer castFilter = CastFilterType::New();
207 castFilter->SetInput(image);
210 typename FFTPadType::Pointer fftpad = FFTPadType::New();
211 fftpad->SetSizeGreatestPrimeFactor(4);
212 itk::ConstantBoundaryCondition< DoubleImageType > constantBoundaryCondition;
213 itk::PeriodicBoundaryCondition< DoubleImageType > periodicBoundaryCondition;
214 itk::ZeroFluxNeumannBoundaryCondition< DoubleImageType > zeroFluxNeumannBoundaryCondition;
218 fftpad->SetBoundaryCondition(&constantBoundaryCondition);
221 fftpad->SetBoundaryCondition(&periodicBoundaryCondition);
224 fftpad->SetBoundaryCondition(&zeroFluxNeumannBoundaryCondition);
229 fftpad->SetInput(castFilter->GetOutput());
231 typename FFTFilterType::Pointer fftFilter = FFTFilterType::New();
232 fftFilter->SetInput(fftpad->GetOutput());
235 typename ForwardWaveletType::Pointer forwardWavelet = ForwardWaveletType::New();
237 forwardWavelet->SetHighPassSubBands(highSubBands);
238 forwardWavelet->SetLevels(levels);
239 forwardWavelet->SetInput(fftFilter->GetOutput());
240 forwardWavelet->Update();
243 typename ComplexImageType::SpacingType inputSpacing;
244 for (
unsigned int i = 0; i < Dimension; ++i)
246 inputSpacing[i] = image->GetLargestPossibleRegion().GetSize()[i];
248 typename ComplexImageType::SpacingType expectedSpacing = inputSpacing;
249 typename ComplexImageType::PointType inputOrigin = image->GetOrigin();
250 typename ComplexImageType::PointType expectedOrigin = inputOrigin;
251 typename ComplexImageType::SizeType inputSize = fftFilter->GetOutput()->GetLargestPossibleRegion().GetSize();
252 typename ComplexImageType::SizeType expectedSize = inputSize;
255 typename InverseFFTFilterType::Pointer inverseFFT = InverseFFTFilterType::New();
256 for (
unsigned int level = 0; level < numberOfLevels + 1; ++level)
258 double scaleFactorPerLevel = std::pow(static_cast< double >(forwardWavelet->GetScaleFactor()),static_cast< double >(level));
259 for (
unsigned int i = 0; i < Dimension; ++i)
261 expectedSize[i] = inputSize[i] / scaleFactorPerLevel;
262 expectedOrigin[i] = inputOrigin[i];
263 expectedSpacing[i] = inputSpacing[i] * scaleFactorPerLevel;
265 for (
unsigned int band = 0; band < highSubBands; ++band)
267 unsigned int nOutput = level * forwardWavelet->GetHighPassSubBands() + band;
269 if (level == numberOfLevels && band == 0)
271 nOutput = forwardWavelet->GetTotalOutputs() - 1;
273 else if (level == numberOfLevels && band != 0)
278 inverseFFT->SetInput(forwardWavelet->GetOutput(nOutput));
279 inverseFFT->Update();
281 auto itkOutputImage = inverseFFT->GetOutput();
282 itkOutputImage->SetSpacing(expectedSpacing);
285 resultImages.push_back(outputImage);
290 template<
typename TPixel,
unsigned int VImageDimension>
293 typedef itk::Point< double, VImageDimension > PointType;
294 typedef itk::HeldIsotropicWavelet< double, VImageDimension, PointType > HeldIsotropicWaveletType;
295 typedef itk::VowIsotropicWavelet< double, VImageDimension, PointType > VowIsotropicWaveletType;
296 typedef itk::SimoncelliIsotropicWavelet< double, VImageDimension, PointType > SimoncelliIsotropicWaveletType;
297 typedef itk::ShannonIsotropicWavelet< double, VImageDimension, PointType > ShannonIsotropicWaveletType;
302 ExecuteSpecificWaveletTransformation<TPixel, double, VImageDimension, HeldIsotropicWaveletType >(
image, numberOfLevels, numberOfBands, condition, resultImages);
305 ExecuteSpecificWaveletTransformation<TPixel, double, VImageDimension, ShannonIsotropicWaveletType >(
image, numberOfLevels, numberOfBands, condition, resultImages);
308 ExecuteSpecificWaveletTransformation<TPixel, double, VImageDimension, SimoncelliIsotropicWaveletType >(
image, numberOfLevels, numberOfBands, condition, resultImages);
311 ExecuteSpecificWaveletTransformation<TPixel, double, VImageDimension, VowIsotropicWaveletType >(
image, numberOfLevels, numberOfBands, condition, resultImages);
314 ExecuteSpecificWaveletTransformation<TPixel, double, VImageDimension, ShannonIsotropicWaveletType >(
image, numberOfLevels, numberOfBands, condition, resultImages);
321 std::vector<Image::Pointer> resultImages;
327 template<
typename TPixel,
unsigned int VImageDimension>
330 typedef itk::Image< TPixel, VImageDimension >
ImageType;
331 typedef itk::Image< double, VImageDimension > DoubleImageType;
332 typedef itk::CastImageFilter< ImageType, DoubleImageType > CastFilterType;
333 typedef itk::ImageDuplicator< DoubleImageType > DuplicatorType;
336 typename CastFilterType::Pointer castFilter = CastFilterType::New();
337 castFilter->SetInput(image);
338 castFilter->Update();
339 typename DuplicatorType::Pointer duplicator = DuplicatorType::New();
340 duplicator->SetInputImage(castFilter->GetOutput());
341 duplicator->Update();
345 template<
typename TPixel,
unsigned int VImageDimension>
348 typedef itk::Image< TPixel, VImageDimension >
ImageType;
349 typedef itk::Image< double, VImageDimension > DoubleImageType;
350 typedef itk::UnaryFunctorImageFilter< DoubleImageType, ImageType, mitk::Functor::RoundValue<double, TPixel> > DefaultFilterType;
352 typename DoubleImageType::Pointer itkImage = DoubleImageType::New();
355 typename DefaultFilterType::Pointer filter = DefaultFilterType::New();
356 filter->SetInput(itkImage);
371 auto newGeometry = image->GetGeometry()->Clone();
374 for (
int i = 0; i < 3; ++i)
376 spacing[i] = newGeometry->GetSpacing()[i];
378 if (spacingVector[i] > 0)
380 spacing[i] = spacingVector[i];
383 unsigned int samples = image->GetDimensions()[i];
384 double currentSpacing = newGeometry->GetSpacing()[i];
385 double newFactor = std::floor(samples*currentSpacing / spacingVector[i]);
386 spacing[i] = samples * currentSpacing / newFactor;
390 bounds[i*2+1] = std::ceil(bounds[i*2+1] * newGeometry->GetSpacing()[i] *1.0 / spacing[i]);
395 for (
int i = 0; i < 3; ++i)
397 double oldLength = newGeometry->GetSpacing()[i] * newGeometry->GetBounds()[i*2+1];
398 double newLength = spacing[i] * bounds[i*2+1];
399 origin[i] = origin[i] - (newLength - oldLength) / 2;
403 newGeometry->SetSpacing(spacing);
404 newGeometry->SetOrigin(origin);
405 newGeometry->SetBounds(bounds);
412 newGeometry.GetPointer(),
433 template<
typename TPixel,
unsigned int VImageDimension>
436 typedef itk::Image<TPixel, VImageDimension>
ImageType;
437 typedef itk::Image<TPixel, VImageDimension> MaskType;
438 typedef itk::UnaryFunctorImageFilter< ImageType, MaskType, mitk::Functor::ThresholdValue<TPixel> > DefaultFilterType;
440 typename DefaultFilterType::Pointer filter = DefaultFilterType::New();
441 filter->SetInput(image);
442 filter->GetFunctor().value = 0.5;
470 unsigned int levels,
unsigned int bands)
472 unsigned int totalOutputs = 1 + levels * bands;
473 if (linearIndex > totalOutputs - 1)
475 itkGenericExceptionMacro(<<
"Failed converting linearIndex " << linearIndex
476 <<
" with levels: " << levels <<
" bands: " << bands <<
477 " to Level,Band pair : out of bounds");
481 if (linearIndex == totalOutputs - 1)
483 return std::make_pair(levels - 1, 0);
486 unsigned int band = (linearIndex) % bands + 1;
488 unsigned int level = (linearIndex) / bands;
489 itkAssertInDebugAndIgnoreInReleaseMacro(level < levels);
490 return std::make_pair(level, band);
MITKCORE_EXPORT bool operator!=(const InteractionEvent &a, const InteractionEvent &b)
BoundingBoxType::BoundsArrayType BoundsArrayType
GridInterpolationPositionType
itk::Image< unsigned char, 3 > ImageType
DataCollection - Class to facilitate loading/accessing structured data.
template unsigned int ComputeMaxNumberOfLevels< 3 >(const Size< 3 > &inputSize, const unsigned int &scaleFactor)
#define AccessByItk_n(mitkImage, itkImageTypeFunction, va_tuple)
Access a MITK image by an ITK image with one or more parameters.
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
mitk::Image::Pointer image
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=nullptr, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
IndexPairType IndexToLevelBandSteerablePyramid(unsigned int linearIndex, unsigned int levels, unsigned int bands)
mitk::MAPRegistrationWrapper::Pointer GenerateIdentityRegistration3D()
template unsigned int ComputeMaxNumberOfLevels< 2 >(const Size< 2 > &inputSize, const unsigned int &scaleFactor)