24 m_IplDistanceImage(nullptr), m_IplOutputImage(nullptr), m_ItkInputImage(nullptr), m_ApplyTemporalMedianFilter(false), m_ApplyAverageFilter(false),
25 m_ApplyMedianFilter(false), m_ApplyThresholdFilter(false), m_ApplyMaskSegmentation(false), m_ApplyBilateralFilter(false), m_DataBuffer(nullptr),
26 m_DataBufferCurrentIndex(0), m_DataBufferMaxSize(0), m_TemporalMedianFilterNumOfFrames(10), m_ThresholdFilterMin(1),
27 m_ThresholdFilterMax(7000), m_BilateralFilterDomainSigma(2), m_BilateralFilterRangeSigma(60), m_BilateralFilterKernelRadius(0)
33 cvReleaseImage(&(this->m_IplDistanceImage));
34 cvReleaseImage(&(this->m_IplOutputImage));
35 if (m_DataBuffer!=
nullptr)
37 delete [] m_DataBuffer;
43 this->SetInput(0, distanceImage);
48 if ((distanceImage ==
nullptr) && (idx == this->GetNumberOfInputs() - 1))
50 this->SetNumberOfInputs(this->GetNumberOfInputs() - 1);
60 this->m_ImageSize = this->m_ImageWidth * this->m_ImageHeight *
sizeof(float);
62 if (this->m_IplDistanceImage !=
nullptr)
64 cvReleaseImage(&(this->m_IplDistanceImage));
67 float* distanceFloatData = (
float*) distImgAcc.
GetData();
68 this->m_IplDistanceImage = cvCreateImage(cvSize(this->m_ImageWidth, this->m_ImageHeight), IPL_DEPTH_32F, 1);
69 memcpy(this->m_IplDistanceImage->imageData, (
void*)distanceFloatData, this->m_ImageSize);
71 if (this->m_IplOutputImage !=
nullptr)
73 cvReleaseImage(&(this->m_IplOutputImage));
75 this->m_IplOutputImage = cvCreateImage(cvSize(this->m_ImageWidth, this->m_ImageHeight), IPL_DEPTH_32F, 1);
77 CreateItkImage(this->m_ItkInputImage);
80 this->ProcessObject::SetNthInput(idx, distanceImage);
83 this->CreateOutputsForAllInputs();
88 return this->GetInput(0);
93 if (this->GetNumberOfInputs() < 1)
95 return static_cast< mitk::Image*
>(this->ProcessObject::GetInput(idx));
101 for (
unsigned int idx=0; idx<this->GetNumberOfOutputs(); idx++)
105 if (outputImage.IsNotNull()&&inputImage.IsNotNull())
108 outputImage->CopyInformation(inputImage);
109 outputImage->Initialize(inputImage->GetPixelType(),inputImage->GetDimension(),inputImage->GetDimensions());
110 outputImage->SetSlice(inputAcc.GetData());
114 ImageReadAccessor outputAcc(this->GetOutput(), this->GetOutput()->GetSliceData(0, 0, 0) );
115 float* outputDistanceFloatData = (
float*) outputAcc.
GetData();
118 ImageReadAccessor inputAcc(this->GetInput(), this->GetInput()->GetSliceData(0, 0, 0) );
121 float* distanceFloatData = (
float*)inputAcc.
GetData();
122 memcpy(this->m_IplDistanceImage->imageData, (
void*)distanceFloatData, this->m_ImageSize);
123 if (m_ApplyThresholdFilter||m_ApplyMaskSegmentation)
125 ProcessSegmentation(this->m_IplDistanceImage);
127 if (this->m_ApplyTemporalMedianFilter||this->m_ApplyAverageFilter)
129 ProcessStreamedQuickSelectMedianImageFilter(this->m_IplDistanceImage);
131 if (this->m_ApplyMedianFilter)
133 ProcessCVMedianFilter(this->m_IplDistanceImage, this->m_IplOutputImage);
134 memcpy( this->m_IplDistanceImage->imageData, this->m_IplOutputImage->imageData, this->m_ImageSize );
136 if (this->m_ApplyBilateralFilter)
138 float* itkFloatData = this->m_ItkInputImage->GetBufferPointer();
139 memcpy(itkFloatData, this->m_IplDistanceImage->imageData, this->m_ImageSize );
141 memcpy( this->m_IplDistanceImage->imageData, itkOutputImage->GetBufferPointer(), this->m_ImageSize );
146 memcpy( outputDistanceFloatData, this->m_IplDistanceImage->imageData, this->m_ImageSize );
151 this->SetNumberOfOutputs(this->GetNumberOfInputs());
152 for (
unsigned int idx = 0; idx < this->GetNumberOfIndexedInputs(); ++idx)
153 if (this->GetOutput(idx) ==
nullptr)
155 DataObjectPointer newOutput = this->MakeOutput(idx);
156 this->SetNthOutput(idx, newOutput);
166 if (output->IsInitialized())
169 itkDebugMacro(<<
"GenerateOutputInformation()");
171 output->Initialize(input->GetPixelType(), *input->GetTimeGeometry());
172 output->SetPropertyList(input->GetPropertyList()->Clone());
177 char* segmentationMask;
178 if (m_SegmentationMask.IsNotNull())
180 ImageReadAccessor segMaskAcc(m_SegmentationMask, m_SegmentationMask->GetSliceData(0,0,0));
181 segmentationMask = (
char*)segMaskAcc.
GetData();
185 segmentationMask =
nullptr;
187 float *f = (
float*)inputIplImage->imageData;
188 for(
int i=0; i<this->m_ImageWidth*this->m_ImageHeight; i++)
190 if (this->m_ApplyThresholdFilter)
192 if (f[i]<=m_ThresholdFilterMin)
196 else if (f[i]>=m_ThresholdFilterMax)
201 if (this->m_ApplyMaskSegmentation)
203 if (segmentationMask)
205 if (segmentationMask[i]==0)
218 bilateralFilter->SetInput(inputItkImage);
219 bilateralFilter->SetDomainSigma(m_BilateralFilterDomainSigma);
220 bilateralFilter->SetRangeSigma(m_BilateralFilterRangeSigma);
222 outputItkImage = bilateralFilter->GetOutput();
223 outputItkImage->Update();
224 return outputItkImage;
229 int diameter = m_BilateralFilterKernelRadius;
230 double sigmaColor = m_BilateralFilterRangeSigma;
231 double sigmaSpace = m_BilateralFilterDomainSigma;
232 cvSmooth(inputIplImage, outputIplImage, CV_BILATERAL, diameter, 0, sigmaColor, sigmaSpace);
237 cvSmooth(inputIplImage, outputIplImage, CV_MEDIAN, radius, 0, 0, 0);
242 float* data = (
float*)inputIplImage->imageData;
244 int imageSize = inputIplImage->width * inputIplImage->height;
247 if (this->m_TemporalMedianFilterNumOfFrames == 0)
252 if (m_TemporalMedianFilterNumOfFrames != this->m_DataBufferMaxSize)
255 for(
int i=0; i<this->m_DataBufferMaxSize; i++ ) {
256 delete[] this->m_DataBuffer[i];
258 if (this->m_DataBuffer !=
nullptr)
260 delete[] this->m_DataBuffer;
263 this->m_DataBufferMaxSize = m_TemporalMedianFilterNumOfFrames;
266 this->m_DataBuffer =
new float*[this->m_DataBufferMaxSize];
267 for(
int i=0; i<this->m_DataBufferMaxSize; i++)
269 this->m_DataBuffer[i] =
nullptr;
271 this->m_DataBufferCurrentIndex = 0;
274 int currentBufferSize = this->m_DataBufferMaxSize;
275 tmpArray =
new float[this->m_DataBufferMaxSize];
278 if (this->m_DataBuffer[this->m_DataBufferCurrentIndex] ==
nullptr)
280 this->m_DataBuffer[this->m_DataBufferCurrentIndex] =
new float[imageSize];
281 currentBufferSize = this->m_DataBufferCurrentIndex + 1;
284 for(
int j=0; j<imageSize; j++)
286 this->m_DataBuffer[this->m_DataBufferCurrentIndex][j] = data[j];
289 float tmpValue = 0.0f;
290 for(
int i=0; i<imageSize; i++)
292 if (m_ApplyAverageFilter)
295 for(
int j=0; j<currentBufferSize; j++)
297 tmpValue+=this->m_DataBuffer[j][i];
299 data[i] = tmpValue/currentBufferSize;
301 else if (m_ApplyTemporalMedianFilter)
303 for(
int j=0; j<currentBufferSize; j++)
305 tmpArray[j] = this->m_DataBuffer[j][i];
307 data[i] = quick_select(tmpArray, currentBufferSize);
311 this->m_DataBufferCurrentIndex = (this->m_DataBufferCurrentIndex + 1) % this->m_DataBufferMaxSize;
316 #define ELEM_SWAP(a,b) { register float t=(a);(a)=(b);(b)=t; }
321 int median = (low + high)/2;
328 if (high == low + 1) {
329 if (arr[low] > arr[high])
334 middle = (low + high) / 2;
335 if (arr[middle] > arr[high])
ELEM_SWAP(arr[middle], arr[high]) ;
336 if (arr[low] > arr[high])
ELEM_SWAP(arr[low], arr[high]) ;
337 if (arr[middle] > arr[low])
ELEM_SWAP(arr[middle], arr[low]) ;
344 do ll++;
while (arr[low] > arr[ll]) ;
345 do hh--;
while (arr[hh] > arr[low]) ;
363 this->m_TemporalMedianFilterNumOfFrames = tmporalMedianFilterNumOfFrames;
372 this->m_ThresholdFilterMin =
min;
373 this->m_ThresholdFilterMax =
max;
378 this->m_BilateralFilterDomainSigma = domainSigma;
379 this->m_BilateralFilterRangeSigma = rangeSigma;
380 this->m_BilateralFilterKernelRadius = kernelRadius;
386 ItkImageType2D::IndexType startIndex;
389 ItkImageType2D::SizeType size;
390 size[0] = this->m_ImageWidth;
391 size[1] = this->m_ImageHeight;
392 ItkImageType2D::RegionType region;
393 region.SetSize( size );
394 region.SetIndex( startIndex );
395 itkInputImage->SetRegions( region );
396 itkInputImage->Allocate();
itk::SmartPointer< Self > Pointer
virtual void GenerateOutputInformation() override
void CreateOutputsForAllInputs()
Create an output for each input.
const void * GetData() const
Gives const access to the data.
void ProcessCVMedianFilter(IplImage *inputIplImage, IplImage *outputIplImage, int radius=3)
Applies the OpenCV median filter to the input image. See http://opencv.willowgarage.com/documentation/c/image_filtering.html#smooth for more details.
virtual ImageDataItemPointer GetSliceData(int s=0, int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
~ToFCompositeFilter()
standard destructor
void ProcessCVBilateralFilter(IplImage *inputIplImage, IplImage *outputIplImage)
Applies the OpenCV bilateral filter to the input image. See http://opencv.willowgarage.com/documentation/c/image_filtering.html#smooth for more details.
void CreateItkImage(ItkImageType2D::Pointer &itkInputImage)
Initialize and allocate a 2D ITK image of dimension m_ImageWidth*m_ImageHeight.
ToFCompositeFilter()
standard constructor
virtual void GenerateData() override
method generating the output of this filter. Called in the updated process of the pipeline...
Image class for storing images.
virtual void SetInput(Image *distanceImage)
sets the input of this filter
void SetThresholdFilterParameter(int min, int max)
Sets the parameters (lower, upper threshold) of the threshold filter.
void SetTemporalMedianFilterParameter(int tmporalMedianFilterNumOfFrames)
Sets the parameter of the temporal median filter.
void ProcessStreamedQuickSelectMedianImageFilter(IplImage *inputIplImage)
Performs temporal median filter on an image given the number of frames to be considered.
void SetBilateralFilterParameter(double domainSigma, double rangeSigma, int kernelRadius)
Sets the parameters (domain sigma, range sigma, kernel radius) of the bilateral filter.
float quick_select(float arr[], int n)
Quickselect algorithm This Quickselect routine is based on the algorithm described in "Numerical reci...
virtual bool IsEmpty() const
Check whether object contains data (at least at one point in time), e.g., a set of points may be empt...
ItkImageType2D::Pointer ProcessItkBilateralFilter(ItkImageType2D::Pointer inputItkImage)
Applies the ITK bilateral filter to the input image See http://www.itk.org/Doxygen320/html/classitk_1...
void ProcessSegmentation(IplImage *inputIplImage)
Applies a mask and/or threshold segmentation to the input image. All pixels with values outside the m...
Image * GetInput()
returns the input of this filter
unsigned int GetDimension() const
Get dimension of the image.
ImageReadAccessor class to get locked read access for a particular image part.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.