Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimized float Blur variations
    primarykey
    data
    text
    <p>I am looking for optimized functions in c++ for calculating areal averages of floats. the function is passed a source float array, a destination float array (same size as source array), array width and height, "blurring" area width and height.</p> <p>The function should "wrap-around" edges for the blurring/averages calculations.</p> <p>Here is example code that blur with a rectangular shape:</p> <pre><code>/***************************************** * Find averages extended variations *****************************************/ void findaverages_ext(float *floatdata, float *dest_data, int fwidth, int fheight, int scale, int aw, int ah, int weight, int xoff, int yoff) { printf("findaverages_ext scale: %d, width: %d, height: %d, weight: %d \n", scale, aw, ah, weight); float total = 0.0; int spos = scale * fwidth * fheight; int apos; int w = aw; int h = ah; float* f_temp = new float[fwidth * fheight]; // Horizontal for(int y=0;y&lt;fheight ;y++) { Sleep(10); // Do not burn your processor total = 0.0; // Process entire window for first pixel (including wrap-around edge) for (int kx = 0; kx &lt;= w; ++kx) if (kx &gt;= 0 &amp;&amp; kx &lt; fwidth) total += floatdata[y*fwidth + kx]; // Wrap for (int kx = (fwidth-w); kx &lt; fwidth; ++kx) if (kx &gt;= 0 &amp;&amp; kx &lt; fwidth) total += floatdata[y*fwidth + kx]; // Store first window f_temp[y*fwidth] = (total / (w*2+1)); for(int x=1;x&lt;fwidth ;x++) // x width changes with y { // Substract pixel leaving window if (x-w-1 &gt;= 0) total -= floatdata[y*fwidth + x-w-1]; // Add pixel entering window if (x+w &lt; fwidth) total += floatdata[y*fwidth + x+w]; else total += floatdata[y*fwidth + x+w-fwidth]; // Store average apos = y * fwidth + x; f_temp[apos] = (total / (w*2+1)); } } // Vertical for(int x=0;x&lt;fwidth ;x++) { Sleep(10); // Do not burn your processor total = 0.0; // Process entire window for first pixel for (int ky = 0; ky &lt;= h; ++ky) if (ky &gt;= 0 &amp;&amp; ky &lt; fheight) total += f_temp[ky*fwidth + x]; // Wrap for (int ky = fheight-h; ky &lt; fheight; ++ky) if (ky &gt;= 0 &amp;&amp; ky &lt; fheight) total += f_temp[ky*fwidth + x]; // Store first if not out of bounds dest_data[spos + x] = (total / (h*2+1)); for(int y=1;y&lt; fheight ;y++) // y width changes with x { // Substract pixel leaving window if (y-h-1 &gt;= 0) total -= f_temp[(y-h-1)*fwidth + x]; // Add pixel entering window if (y+h &lt; fheight) total += f_temp[(y+h)*fwidth + x]; else total += f_temp[(y+h-fheight)*fwidth + x]; // Store average apos = y * fwidth + x; dest_data[spos+apos] = (total / (h*2+1)); } } delete f_temp; } </code></pre> <p>What I need is similar functions that for each pixel finds the average (blur) of pixels from shapes different than rectangular.</p> <p>The specific shapes are: "S" (sharp edges), "O" (rectangular but hollow), "+" and "X", where the average float is stored at the center pixel on destination data array. Size of blur shape should be variable, width and height.</p> <p>The functions does not need to be pixelperfect, only optimized for performance. There could be separate functions for each shape.</p> <p>I am also happy if anyone can tip me of how to optimize the example function above for rectangluar blurring. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload