<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic help on 2D Median filter slow performance in Intel® Integrated Performance Primitives</title>
    <link>https://community.intel.com/t5/Intel-Integrated-Performance/help-on-2D-Median-filter-slow-performance/m-p/820900#M4726</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am working on 2D median filter with IPP. But the 2D median filter function I wrote is too slow.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Can someone help me solve this problem?&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;////////////////////////////////////////////////////////////////////////////////////////&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;TIME.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include "ippi.h"&lt;BR /&gt;&lt;BR /&gt;typedef int BOOL;&lt;BR /&gt;&lt;BR /&gt;#ifndef FALSE&lt;BR /&gt;#define FALSE 0&lt;BR /&gt;#endif&lt;BR /&gt;&lt;BR /&gt;#ifndef TRUE&lt;BR /&gt;#define TRUE 1&lt;BR /&gt;#endif&lt;BR /&gt;&lt;BR /&gt;//generate random numbers&lt;BR /&gt;float RangedRandDemo( int range_min, int range_max)&lt;BR /&gt;{&lt;BR /&gt; double u = ( double)rand() / (RAND_MAX + 1) * (range_max - range_min) + range_min;&lt;BR /&gt; double v = u * 1.f / (range_max - range_min);&lt;BR /&gt; float returnValue = ( int)((v + 0.5) * 10000) / 10000.f;&lt;BR /&gt; return returnValue;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt; //initialization&lt;BR /&gt; int imgWidth = 273;&lt;BR /&gt; int imgHeight = 101;&lt;BR /&gt; IppiSize maskSize = {31, 31};&lt;BR /&gt; IppiSize halfMaskSize;&lt;BR /&gt; halfMaskSize.width = (maskSize.width - 1)/2;&lt;BR /&gt; halfMaskSize.height = (maskSize.height - 1)/2;&lt;BR /&gt; IppiSize roi;&lt;BR /&gt; IppiPoint anchor;&lt;BR /&gt; anchor.x = halfMaskSize.width;&lt;BR /&gt; anchor.y = halfMaskSize.height;&lt;BR /&gt;&lt;BR /&gt; IppiSize imgSize = {imgWidth, imgHeight};&lt;BR /&gt; int step;&lt;BR /&gt; Ipp32f* inputImage = ippiMalloc_32f_C1(imgWidth, imgHeight, &amp;amp;step);&lt;BR /&gt; Ipp32f* outputImage = ippiMalloc_32f_C1(imgWidth, imgHeight, &amp;amp;step);&lt;BR /&gt;&lt;BR /&gt; int srcStep = (imgWidth) * sizeof(Ipp32f);&lt;BR /&gt; int dstStep = srcStep;&lt;BR /&gt; roi.width = imgWidth - maskSize.width+1;&lt;BR /&gt; roi.height = imgHeight - maskSize.height+1;&lt;BR /&gt;&lt;BR /&gt; //set the original image to be zeros&lt;BR /&gt; ippiSet_32f_C1R(0, (Ipp32f*)inputImage, imgWidth * sizeof(Ipp32f), imgSize);&lt;BR /&gt; ippiSet_32f_C1R(0, (Ipp32f*)outputImage, imgWidth * sizeof(Ipp32f), imgSize);&lt;BR /&gt;&lt;BR /&gt; //Randomly generate input signal&lt;BR /&gt; int i = 0, j = 0;&lt;BR /&gt; for(i = 0; i &amp;lt; imgWidth; i++)&lt;BR /&gt;  for(j = 0; j &amp;lt; imgHeight; j++)&lt;BR /&gt;   inputImage[j*imgWidth+i] = RangedRandDemo(0, 100);&lt;BR /&gt; &lt;BR /&gt; clock_t tStart = clock();&lt;BR /&gt;&lt;BR /&gt; //Apply the median filter to the randomly generated input image&lt;BR /&gt; IppStatus status;&lt;BR /&gt; status = ippiFilterMedian_32f_C1R(&lt;BR /&gt;  (Ipp32f*)(inputImage + (halfMaskSize.height * imgWidth + halfMaskSize.width)), srcStep,&lt;BR /&gt;  (Ipp32f*)(outputImage + (halfMaskSize.height * imgWidth + halfMaskSize.width)), dstStep,&lt;BR /&gt;  roi, maskSize, anchor);&lt;BR /&gt;&lt;BR /&gt; double perfTime = ( double)((clock() - tStart)/CLOCKS_PER_SEC);&lt;BR /&gt;&lt;BR /&gt; ippiFree(inputImage);&lt;BR /&gt; ippiFree(outputImage);&lt;BR /&gt;&lt;BR /&gt; if(status ==ippStsNoErr) //successfully&lt;BR /&gt;  return TRUE;&lt;BR /&gt; else&lt;BR /&gt;  return FALSE; //error&lt;BR /&gt;}&lt;BR /&gt;&lt;/STDLIB.H&gt;&lt;/TIME.H&gt;&lt;/STDIO.H&gt;</description>
    <pubDate>Wed, 16 May 2012 14:46:48 GMT</pubDate>
    <dc:creator>Hai</dc:creator>
    <dc:date>2012-05-16T14:46:48Z</dc:date>
    <item>
      <title>help on 2D Median filter slow performance</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/help-on-2D-Median-filter-slow-performance/m-p/820900#M4726</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am working on 2D median filter with IPP. But the 2D median filter function I wrote is too slow.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Can someone help me solve this problem?&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;////////////////////////////////////////////////////////////////////////////////////////&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;TIME.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include "ippi.h"&lt;BR /&gt;&lt;BR /&gt;typedef int BOOL;&lt;BR /&gt;&lt;BR /&gt;#ifndef FALSE&lt;BR /&gt;#define FALSE 0&lt;BR /&gt;#endif&lt;BR /&gt;&lt;BR /&gt;#ifndef TRUE&lt;BR /&gt;#define TRUE 1&lt;BR /&gt;#endif&lt;BR /&gt;&lt;BR /&gt;//generate random numbers&lt;BR /&gt;float RangedRandDemo( int range_min, int range_max)&lt;BR /&gt;{&lt;BR /&gt; double u = ( double)rand() / (RAND_MAX + 1) * (range_max - range_min) + range_min;&lt;BR /&gt; double v = u * 1.f / (range_max - range_min);&lt;BR /&gt; float returnValue = ( int)((v + 0.5) * 10000) / 10000.f;&lt;BR /&gt; return returnValue;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt; //initialization&lt;BR /&gt; int imgWidth = 273;&lt;BR /&gt; int imgHeight = 101;&lt;BR /&gt; IppiSize maskSize = {31, 31};&lt;BR /&gt; IppiSize halfMaskSize;&lt;BR /&gt; halfMaskSize.width = (maskSize.width - 1)/2;&lt;BR /&gt; halfMaskSize.height = (maskSize.height - 1)/2;&lt;BR /&gt; IppiSize roi;&lt;BR /&gt; IppiPoint anchor;&lt;BR /&gt; anchor.x = halfMaskSize.width;&lt;BR /&gt; anchor.y = halfMaskSize.height;&lt;BR /&gt;&lt;BR /&gt; IppiSize imgSize = {imgWidth, imgHeight};&lt;BR /&gt; int step;&lt;BR /&gt; Ipp32f* inputImage = ippiMalloc_32f_C1(imgWidth, imgHeight, &amp;amp;step);&lt;BR /&gt; Ipp32f* outputImage = ippiMalloc_32f_C1(imgWidth, imgHeight, &amp;amp;step);&lt;BR /&gt;&lt;BR /&gt; int srcStep = (imgWidth) * sizeof(Ipp32f);&lt;BR /&gt; int dstStep = srcStep;&lt;BR /&gt; roi.width = imgWidth - maskSize.width+1;&lt;BR /&gt; roi.height = imgHeight - maskSize.height+1;&lt;BR /&gt;&lt;BR /&gt; //set the original image to be zeros&lt;BR /&gt; ippiSet_32f_C1R(0, (Ipp32f*)inputImage, imgWidth * sizeof(Ipp32f), imgSize);&lt;BR /&gt; ippiSet_32f_C1R(0, (Ipp32f*)outputImage, imgWidth * sizeof(Ipp32f), imgSize);&lt;BR /&gt;&lt;BR /&gt; //Randomly generate input signal&lt;BR /&gt; int i = 0, j = 0;&lt;BR /&gt; for(i = 0; i &amp;lt; imgWidth; i++)&lt;BR /&gt;  for(j = 0; j &amp;lt; imgHeight; j++)&lt;BR /&gt;   inputImage[j*imgWidth+i] = RangedRandDemo(0, 100);&lt;BR /&gt; &lt;BR /&gt; clock_t tStart = clock();&lt;BR /&gt;&lt;BR /&gt; //Apply the median filter to the randomly generated input image&lt;BR /&gt; IppStatus status;&lt;BR /&gt; status = ippiFilterMedian_32f_C1R(&lt;BR /&gt;  (Ipp32f*)(inputImage + (halfMaskSize.height * imgWidth + halfMaskSize.width)), srcStep,&lt;BR /&gt;  (Ipp32f*)(outputImage + (halfMaskSize.height * imgWidth + halfMaskSize.width)), dstStep,&lt;BR /&gt;  roi, maskSize, anchor);&lt;BR /&gt;&lt;BR /&gt; double perfTime = ( double)((clock() - tStart)/CLOCKS_PER_SEC);&lt;BR /&gt;&lt;BR /&gt; ippiFree(inputImage);&lt;BR /&gt; ippiFree(outputImage);&lt;BR /&gt;&lt;BR /&gt; if(status ==ippStsNoErr) //successfully&lt;BR /&gt;  return TRUE;&lt;BR /&gt; else&lt;BR /&gt;  return FALSE; //error&lt;BR /&gt;}&lt;BR /&gt;&lt;/STDLIB.H&gt;&lt;/TIME.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Wed, 16 May 2012 14:46:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/help-on-2D-Median-filter-slow-performance/m-p/820900#M4726</guid>
      <dc:creator>Hai</dc:creator>
      <dc:date>2012-05-16T14:46:48Z</dc:date>
    </item>
  </channel>
</rss>

