19 #include "opencv2/imgproc.hpp" 22 m_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),
24 m_DataBufferCurrentIndex(0), m_DataBufferMaxSize(0), m_TemporalMedianFilterNumOfFrames(10), m_ThresholdFilterMin(1),
25 m_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);
65 float* distanceFloatData = (
float*) distImgAcc.
GetData();
67 memcpy(this->
m_IplDistanceImage->imageData, (
void*)distanceFloatData, this->m_ImageSize);
78 this->ProcessObject::SetNthInput(idx, const_cast<InputImageType*>(distanceImage));
91 if (this->GetNumberOfInputs() < 1)
93 return static_cast< mitk::Image*
>(this->ProcessObject::GetInput(idx));
99 for (
unsigned int idx=0; idx<this->GetNumberOfOutputs(); idx++)
103 if (outputImage.IsNotNull()&&inputImage.IsNotNull())
106 outputImage->CopyInformation(inputImage);
107 outputImage->Initialize(inputImage->GetPixelType(),inputImage->GetDimension(),inputImage->GetDimensions());
108 outputImage->SetSlice(inputAcc.GetData());
113 float* outputDistanceFloatData = (
float*) outputAcc.
GetData();
119 float* distanceFloatData = (
float*)inputAcc.
GetData();
120 memcpy(this->
m_IplDistanceImage->imageData, (
void*)distanceFloatData, this->m_ImageSize);
132 memcpy( this->
m_IplDistanceImage->imageData, this->m_IplOutputImage->imageData, this->m_ImageSize );
144 memcpy( outputDistanceFloatData, this->
m_IplDistanceImage->imageData, this->m_ImageSize );
149 this->SetNumberOfIndexedOutputs(this->GetNumberOfInputs());
150 for (
unsigned int idx = 0; idx < this->GetNumberOfIndexedInputs(); ++idx)
154 DataObjectPointer newOutput = this->
MakeOutput(idx);
155 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;
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++)
203 if (segmentationMask)
205 if (segmentationMask[i]==0)
216 ItkImageType2D::Pointer outputItkImage;
217 BilateralFilterType::Pointer bilateralFilter = BilateralFilterType::New();
218 bilateralFilter->SetInput(inputItkImage);
222 outputItkImage = bilateralFilter->GetOutput();
223 outputItkImage->Update();
224 return outputItkImage;
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;
284 for(
int j=0; j<imageSize; j++)
289 float tmpValue = 0.0f;
290 for(
int i=0; i<imageSize; i++)
295 for(
int j=0; j<currentBufferSize; j++)
299 data[i] = tmpValue/currentBufferSize;
303 for(
int j=0; j<currentBufferSize; j++)
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]) ;
385 itkInputImage = ItkImageType2D::New();
386 ItkImageType2D::IndexType startIndex;
389 ItkImageType2D::SizeType size;
392 ItkImageType2D::RegionType region;
393 region.SetSize( size );
394 region.SetIndex( startIndex );
395 itkInputImage->SetRegions( region );
396 itkInputImage->Allocate();
bool m_ApplyMaskSegmentation
Flag indicating if a mask segmentation is performed.
bool m_ApplyBilateralFilter
Flag indicating if the bilateral filter is currently active for processing the distance image...
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...
~ToFCompositeFilter() override
standard destructor
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
Make a DataObject of the correct type to used as the specified output.
virtual ImageDataItemPointer GetSliceData(int s=0, int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
void GenerateOutputInformation() override
bool m_ApplyThresholdFilter
Flag indicating if the threshold filter is currently active for processing the distance image...
double m_BilateralFilterRangeSigma
Parameter of the bilateral filter controlling the edge preserving effect of the filter. Default value: 60.
bool m_ApplyMedianFilter
Flag indicating if the spatial median filter is currently active for processing the distance image...
int m_ImageWidth
x-dimension of the image
void CreateOutputsForAllInputs()
Create an output for each input.
bool m_ApplyAverageFilter
Flag indicating if the average filter is currently active for processing the distance image...
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.
ItkImageType2D::Pointer m_ItkInputImage
ITK representation of the distance image.
int m_TemporalMedianFilterNumOfFrames
Number of frames to be used in the calculation of the temporal median.
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.
IplImage * m_IplOutputImage
OpenCV-representation of the output image.
unsigned int GetDimension() const
Get dimension of the image.
int m_ImageHeight
y-dimension of the image
void CreateItkImage(ItkImageType2D::Pointer &itkInputImage)
Initialize and allocate a 2D ITK image of dimension m_ImageWidth*m_ImageHeight.
ToFCompositeFilter()
standard constructor
int m_ThresholdFilterMin
Lower threshold of the threshold filter. Pixels with values below will be assigned value 0 when apply...
void GenerateData() override
method generating the output of this filter. Called in the updated process of the pipeline...
Image class for storing images.
double m_BilateralFilterDomainSigma
Parameter of the bilateral filter controlling the smoothing effect of the filter. Default value: 2...
int m_ImageSize
size of the image in bytes
float ** m_DataBuffer
Buffer used for calculating the pixel-wise median over the last n (m_TemporalMedianFilterNumOfFrames)...
int m_DataBufferMaxSize
Maximal size for the buffer of the temporal median filter (m_DataBuffer)
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.
int m_BilateralFilterKernelRadius
Kernel radius of the bilateral filter mask.
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.
mitk::Image::Pointer m_SegmentationMask
mask image used for segmenting the image
float quick_select(float arr[], int n)
Quickselect algorithm This Quickselect routine is based on the algorithm described in "Numerical reci...
void SetInput(const InputImageType *distanceImage) override
sets the input of this filter
int m_DataBufferCurrentIndex
Current index in the buffer of the temporal median filter.
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...
OutputType * GetOutput()
Get the output data of this image source object.
Image * GetInput()
returns the input of this filter
bool m_ApplyTemporalMedianFilter
Flag indicating if the temporal median filter is currently active for processing the distance image...
ImageReadAccessor class to get locked read access for a particular image part.
int m_ThresholdFilterMax
Lower threshold of the threshold filter. Pixels with values above will be assigned value 0 when apply...
const void * GetData() const
Gives const access to the data.
IplImage * m_IplDistanceImage
OpenCV-representation of the distance image.