- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 maskSize = {31, 31};
IppiSize halfMaskSize;
halfMaskSize.width = (maskSize.width - 1)/2;
halfMaskSize.height = (maskSize.height - 1)/2;
IppiSize roi;
IppiPoint anchor;
anchor.x = halfMaskSize.width;
anchor.y = halfMaskSize.height;
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;
roi.width = imgWidth - maskSize.width+1;
roi.height = imgHeight - maskSize.height+1;
//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(
(Ipp32f*)(inputImage + (halfMaskSize.height * imgWidth + halfMaskSize.width)), srcStep,
(Ipp32f*)(outputImage + (halfMaskSize.height * imgWidth + halfMaskSize.width)), dstStep,
roi, maskSize, anchor);
double perfTime = ( double)((clock() - tStart)/CLOCKS_PER_SEC);
ippiFree(inputImage);
ippiFree(outputImage);
if(status ==ippStsNoErr) //successfully
return TRUE;
else
return FALSE; //error
}
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 maskSize = {31, 31};
IppiSize halfMaskSize;
halfMaskSize.width = (maskSize.width - 1)/2;
halfMaskSize.height = (maskSize.height - 1)/2;
IppiSize roi;
IppiPoint anchor;
anchor.x = halfMaskSize.width;
anchor.y = halfMaskSize.height;
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;
roi.width = imgWidth - maskSize.width+1;
roi.height = imgHeight - maskSize.height+1;
//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(
(Ipp32f*)(inputImage + (halfMaskSize.height * imgWidth + halfMaskSize.width)), srcStep,
(Ipp32f*)(outputImage + (halfMaskSize.height * imgWidth + halfMaskSize.width)), dstStep,
roi, maskSize, anchor);
double perfTime = ( double)((clock() - tStart)/CLOCKS_PER_SEC);
ippiFree(inputImage);
ippiFree(outputImage);
if(status ==ippStsNoErr) //successfully
return TRUE;
else
return FALSE; //error
}
Link Copied
0 Replies
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page