22m_IplDistanceImage(nullptr), m_IplOutputImage(nullptr), m_ItkInputImage(nullptr), m_ApplyTemporalMedianFilter(false), m_ApplyAverageFilter(false),
23 m_ApplyMedianFilter(false), m_ApplyThresholdFilter(false), m_ApplyMaskSegmentation(false), m_ApplyBilateralFilter(false), m_DataBuffer(nullptr),
24m_DataBufferCurrentIndex(0), m_DataBufferMaxSize(0), m_TemporalMedianFilterNumOfFrames(10), m_ThresholdFilterMin(1),
25m_ThresholdFilterMax(7000), m_BilateralFilterDomainSigma(2), m_BilateralFilterRangeSigma(60), m_BilateralFilterKernelRadius(0)
46 if ((distanceImage ==
nullptr) && (idx == this->GetNumberOfInputs() - 1))
48 this->SetNumberOfIndexedInputs(this->GetNumberOfInputs() - 1);
54 if (!distanceImage->IsEmpty())
56 this->m_ImageWidth = distanceImage->GetDimension(0);
57 this->m_ImageHeight = distanceImage->GetDimension(1);
58 this->m_ImageSize = this->m_ImageWidth * this->m_ImageHeight *
sizeof(float);
60 if (this->m_IplDistanceImage !=
nullptr)
62 cvReleaseImage(&(this->m_IplDistanceImage));
64 ImageReadAccessor distImgAcc(distanceImage, distanceImage->GetSliceData(0,0,0));
65 float* distanceFloatData = (
float*) distImgAcc.GetData();
66 this->m_IplDistanceImage = cvCreateImage(cvSize(this->m_ImageWidth, this->m_ImageHeight), IPL_DEPTH_32F, 1);
67 memcpy(this->m_IplDistanceImage->imageData, (
void*)distanceFloatData, this->m_ImageSize);
69 if (this->m_IplOutputImage !=
nullptr)
71 cvReleaseImage(&(this->m_IplOutputImage));
73 this->m_IplOutputImage = cvCreateImage(cvSize(this->m_ImageWidth, this->m_ImageHeight), IPL_DEPTH_32F, 1);
75 CreateItkImage(this->m_ItkInputImage);
78 this->ProcessObject::SetNthInput(idx,
const_cast<InputImageType*
>(distanceImage));
81 this->CreateOutputsForAllInputs();
99 for (
unsigned int idx=0; idx<this->GetNumberOfOutputs(); idx++)
101 mitk::Image::Pointer outputImage = this->GetOutput(idx);
102 mitk::Image::Pointer inputImage = this->GetInput(idx);
103 if (outputImage.IsNotNull()&&inputImage.IsNotNull())
105 ImageReadAccessor inputAcc(inputImage, inputImage->GetSliceData());
106 outputImage->CopyInformation(inputImage);
107 outputImage->Initialize(inputImage->GetPixelType(),inputImage->GetDimension(),inputImage->GetDimensions());
108 outputImage->SetSlice(inputAcc.GetData());
112 ImageReadAccessor outputAcc(this->GetOutput(), this->GetOutput()->GetSliceData(0, 0, 0) );
113 float* outputDistanceFloatData = (
float*) outputAcc.GetData();
116 ImageReadAccessor inputAcc(this->GetInput(), this->GetInput()->GetSliceData(0, 0, 0) );
119 float* distanceFloatData = (
float*)inputAcc.GetData();
120 memcpy(this->m_IplDistanceImage->imageData, (
void*)distanceFloatData, this->m_ImageSize);
121 if (m_ApplyThresholdFilter||m_ApplyMaskSegmentation)
123 ProcessSegmentation(this->m_IplDistanceImage);
125 if (this->m_ApplyTemporalMedianFilter||this->m_ApplyAverageFilter)
127 ProcessStreamedQuickSelectMedianImageFilter(this->m_IplDistanceImage);
129 if (this->m_ApplyMedianFilter)
131 ProcessCVMedianFilter(this->m_IplDistanceImage, this->m_IplOutputImage);
132 memcpy( this->m_IplDistanceImage->imageData, this->m_IplOutputImage->imageData, this->m_ImageSize );
134 if (this->m_ApplyBilateralFilter)
136 float* itkFloatData = this->m_ItkInputImage->GetBufferPointer();
137 memcpy(itkFloatData, this->m_IplDistanceImage->imageData, this->m_ImageSize );
138 ItkImageType2D::Pointer itkOutputImage = ProcessItkBilateralFilter(this->m_ItkInputImage);
139 memcpy( this->m_IplDistanceImage->imageData, itkOutputImage->GetBufferPointer(), this->m_ImageSize );
144 memcpy( outputDistanceFloatData, this->m_IplDistanceImage->imageData, this->m_ImageSize );
163 mitk::Image::ConstPointer input = this->GetInput();
164 mitk::Image::Pointer output = this->GetOutput();
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)
216 ItkImageType2D::Pointer outputItkImage;
217 BilateralFilterType::Pointer bilateralFilter = BilateralFilterType::New();
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);
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;
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]) ;
385 itkInputImage = ItkImageType2D::New();
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();
void SetBilateralFilterParameter(double domainSigma, double rangeSigma, int kernelRadius)
Sets the parameters (domain sigma, range sigma, kernel radius) of the bilateral filter.