Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble with Box Blur Edges
    text
    copied!<p>I am a newbie hobbyist trying to program a box blur and I am having trouble with respect to edges. I am hoping that someone can spot the error.</p> <p>The edges are black and I am assuming that it's because the borders are not being reflected properly. I am sure this has been discussed with a fix size kernel however I am using a variable sized kernel.</p> <p>I am using the code found on another post --</p> <p><a href="https://stackoverflow.com/questions/7860575/optimized-float-blur-variations">Optimized float Blur variations</a></p> <p>However I just do not understand the reflected borders portion.</p> <p>I do not really care if optimized or not nor do I care about other kernel shapes, box shape will be just fine.</p> <p>The code is</p> <pre><code> {// code from https://stackoverflow.com/questions/7860575/optimized-float-blur-variations //-------------------------------------- int image_width ; int image_height ; int scale = 0; int weight = (radius * 2) + 1; int kernel_X = 0; int kernel_Y = 0; //-------------------------------------- float sum = 0.0; int kernel_width = radius;//set both to the same to make the kernel square int kernel_height = radius;//set both to the same to make the kernel square // HORIZONTAL for(iy = 0; iy &lt; image_height ;iy++) { sum = 0.0; // Process entire window for first pixel (including wrap-around edge) for (kernel_X = 0; kernel_X &lt;= kernel_width; kernel_X++) { if (kernel_X &gt;= 0 &amp;&amp; kernel_X &lt; image_width) //sum += src[iy * image_width ]; sum += src[iy * image_width + kernel_X]; } //&gt;-------------- border code does not reflect edges HELP!! // Wrap watch for left side of image &amp; resulting black bar for (kernel_X = (image_width - kernel_width); kernel_X &lt; image_width; kernel_X++) { // if (kernel_X &gt;= 0 &amp;&amp; kernel_X &lt; image_width)// HORIZONTAL width = horizontal = X // sum += src[iy * kernel_width + image_width ];//&lt;-------------------enter tester formula here // sum += src[iy + ix * image_width + kernel_X];//&lt;-------------------FAIL // sum += src[iy * kernel_width + image_width ];//&lt;-------------------streaky } // Store first window tmp[iy * image_width] = (sum / weight ); for(ix = 1; ix &lt; image_width; ix++) { // Subtract pixel leaving window if (ix - kernel_width - 1 &gt;= 0) sum -= src[iy * image_width + ix - kernel_width - 1]; // Add pixel entering window if (ix + kernel_width &lt; image_width) sum += src[iy * image_width + ix + kernel_width]; else sum += src[iy * image_width + ix + kernel_width - image_width]; tmp[iy * image_width + ix] = (sum / weight);//just for testing } } // VERTICAL for(ix = 0; ix &lt; image_width; ix++) { sum = 0.0; // Process entire window for first pixel for (kernel_Y = 0; kernel_Y &lt;= kernel_height; kernel_Y++) { if (kernel_Y &gt;= 0 &amp;&amp; kernel_Y &lt; image_height) sum += tmp[kernel_Y * image_width + ix]; } //&gt;-------------- border code does not reflect edges HELP!! // Wrap watch for top side of image &amp; resulting black bar for (kernel_Y = image_height-kernel_height; kernel_Y &lt; kernel_height; kernel_Y++) { //if (kernel_Y &gt;= 0 &amp;&amp; kernel_Y &lt; image_height) // sum += tmp[(iy + kernel_height - image_height) * image_width + ix]; } for(iy=1;iy&lt; image_height ;iy++) { // Subtract pixel leaving window if (iy-kernel_height-1 &gt;= 0) sum -= tmp[(iy - kernel_height-1) * image_width + ix]; // Add pixel entering window if (iy + kernel_height &lt; image_height) sum += tmp[(iy + kernel_height) * image_width + ix]; else sum += tmp[(iy + kernel_height - image_height) * image_width + ix]; dst[ (scale * image_width * image_height) + (iy * image_width + ix) ] = (sum / weight); } } } </code></pre> <p>I appreciate any help on this.</p> <p>Thanks John</p> <p>edit here are some links of image examples of the edges.</p> <p>image with proper box blur <a href="http://img687.imageshack.us/img687/931/standardboxblur.jpg" rel="nofollow noreferrer">http://img687.imageshack.us/img687/931/standardboxblur.jpg</a></p> <p>Image with improper edges using the above code (notice dark bar on Top and Left edges, bottom and right are not quite right either) <a href="http://img202.imageshack.us/img202/5137/boxblurbadedges.jpg" rel="nofollow noreferrer">http://img202.imageshack.us/img202/5137/boxblurbadedges.jpg</a></p>
 

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