22 #include "itkImageRegionIterator.h"
28 #include <itkLabelStatisticsImageFilter.h>
29 #include <itkMinimumMaximumImageCalculator.h>
35 this->SetNumberOfIndexedInputs(3);
36 this->SetNumberOfRequiredInputs(1);
47 this->SetNthInput(1, nonconstMask );
54 this->SetNthInput(2, nonconstMask );
59 return this->GetInput(1);
64 return this->GetInput(2);
69 Superclass::GenerateInputRequestedRegion();
81 itkDebugMacro(<<
"GenerateOutputInformation()");
83 output->Initialize(input->GetPixelType(), *input->GetTimeGeometry());
84 output->SetPropertyList(input->GetPropertyList()->Clone());
87 template <
typename TPixel,
unsigned int VImageDimension >
91 typedef itk::Image<TPixel, VImageDimension>
ImageType;
92 typedef itk::Image<int, VImageDimension> MaskType;
93 typedef itk::LabelStatisticsImageFilter<ImageType, MaskType> FilterType;
94 typedef itk::MinimumMaximumImageCalculator<ImageType> MinMaxComputerType;
105 minMaxComputer->SetImage(itkImage);
106 minMaxComputer->Compute();
109 labelStatisticsImageFilter->SetUseHistograms(
true);
110 labelStatisticsImageFilter->SetHistogramParameters(256, minMaxComputer->GetMinimum(),minMaxComputer->GetMaximum());
111 labelStatisticsImageFilter->SetInput( itkImage );
113 labelStatisticsImageFilter->SetLabelInput(itkMask0);
114 labelStatisticsImageFilter->Update();
115 double median0 = labelStatisticsImageFilter->GetMedian(1);
116 double mean0 = labelStatisticsImageFilter->GetMean(1);
119 auto histo = labelStatisticsImageFilter->GetHistogram(1);
120 double maxFrequency=0;
121 for (
auto hIter=histo->Begin();hIter!=histo->End();++hIter)
123 if (maxFrequency < hIter.GetFrequency())
125 maxFrequency = hIter.GetFrequency();
126 modulo0 = (histo->GetBinMin(0,hIter.GetInstanceIdentifier()) + histo->GetBinMax(0,hIter.GetInstanceIdentifier())) / 2.0;
130 labelStatisticsImageFilter->SetLabelInput(itkMask1);
131 labelStatisticsImageFilter->Update();
132 double median1 = labelStatisticsImageFilter->GetMedian(1);
133 double mean1 = labelStatisticsImageFilter->GetMean(1);
136 auto histo = labelStatisticsImageFilter->GetHistogram(1);
137 double maxFrequency=0;
138 for (
auto hIter=histo->Begin();hIter!=histo->End();++hIter)
140 if (maxFrequency < hIter.GetFrequency())
142 maxFrequency = hIter.GetFrequency();
143 modulo1 = (histo->GetBinMin(0,hIter.GetInstanceIdentifier()) + histo->GetBinMax(0,hIter.GetInstanceIdentifier())) / 2.0;
155 value0=median0;
break;
157 value0=modulo0;
break;
164 value1=median1;
break;
166 value1=modulo1;
break;
171 if (scaling < 0.0001)
174 itk::ImageRegionIterator<ImageType> inIter(itkImage, itkImage->GetLargestPossibleRegion());
175 itk::ImageRegionIterator<ImageType> outIter(outImage, outImage->GetLargestPossibleRegion());
176 while (! inIter.IsAtEnd())
178 TPixel value = inIter.Value();
179 outIter.Set((value - offset) / scaling);
virtual void SetRequestedRegionToLargestPossibleRegion() override
void InternalComputeMask(itk::Image< TPixel, VImageDimension > *itkImage)
itk::SmartPointer< Self > Pointer
virtual void GenerateInputRequestedRegion() override
const mitk::Image * GetMask1() const
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
map::core::discrete::Elements< 3 >::InternalImageType ImageType
Image class for storing images.
#define AccessByItk(mitkImage, itkImageTypeFunction)
Access a MITK image by an ITK image.
virtual void GenerateOutputInformation() override
void SetMask2(const mitk::Image *mask)
~MRNormTwoRegionsBasedFilter()
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
void SetMask1(const mitk::Image *mask)
const mitk::Image * GetMask2() const
MRNormTwoRegionsBasedFilter()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.