# help on 2D Median filter slow performance

## help on 2D Median filter slow performance

Hi,

I am working on 2D median filter with IPP. But the 2D median filter function I wrote is too slow.

First of all, the outcome 2D image is correct verified with Matlab. But I compare the processing time between Matlab 2D median filter (medfilt2) and ippiFilterMedian_32f_C1R (which is the function I used). For a image with size 273 by 101, Matlab only needs about 0.32 second. But my code will need 38 seconds.

Can someone help me solve this problem?

Here is my code. In the main function, first, I assign random numbers to a 2D image. Then I apply the 2D median filter. The date type of my 2D input and output image is Ipp32f. The filter mask size is 31 by 31.

////////////////////////////////////////////////////////////////////////////////////////
#include
#include
#include
#include "ippi.h"

typedef int BOOL;

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

//generate random numbers
float RangedRandDemo( int range_min, int range_max)
{
double u = ( double)rand() / (RAND_MAX + 1) * (range_max - range_min) + range_min;
double v = u * 1.f / (range_max - range_min);
float returnValue = ( int)((v + 0.5) * 10000) / 10000.f;
return returnValue;
}

int main(int argc, char *argv[])
{
//initialization
int imgWidth = 273;
int imgHeight = 101;
IppiSize roi;
IppiPoint anchor;

IppiSize imgSize = {imgWidth, imgHeight};
int step;
Ipp32f* inputImage = ippiMalloc_32f_C1(imgWidth, imgHeight, &step);
Ipp32f* outputImage = ippiMalloc_32f_C1(imgWidth, imgHeight, &step);

int srcStep = (imgWidth) * sizeof(Ipp32f);
int dstStep = srcStep;

//set the original image to be zeros
ippiSet_32f_C1R(0, (Ipp32f*)inputImage, imgWidth * sizeof(Ipp32f), imgSize);
ippiSet_32f_C1R(0, (Ipp32f*)outputImage, imgWidth * sizeof(Ipp32f), imgSize);

//Randomly generate input signal
int i = 0, j = 0;
for(i = 0; i < imgWidth; i++)
for(j = 0; j < imgHeight; j++)
inputImage[j*imgWidth+i] = RangedRandDemo(0, 100);

clock_t tStart = clock();

//Apply the median filter to the randomly generated input image
IppStatus status;
status = ippiFilterMedian_32f_C1R(

double perfTime = ( double)((clock() - tStart)/CLOCKS_PER_SEC);

ippiFree(inputImage);
ippiFree(outputImage);

if(status ==ippStsNoErr) //successfully
return TRUE;
else
return FALSE; //error
}

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.