Export to GitHub

simple-iphone-image-processing - issue #5

Gaussian blur bug


Posted on Jul 13, 2010 by Happy Camel

What steps will reproduce the problem? 1. Improve gaussianBlur() or take my improved code 2. 3.

What is the expected output? What do you see instead? gaussianBlur() reduces image by 5 pixels in the upper left corner.

What version of the product are you using? On what operating system? xCode and the newest version (13th july 2010)

Please provide any additional information below. Fixed gaussianBlur() function:

ImageWrapper *Image::gaussianBlur() { Image *result=new Image(m_width, m_height); for(int y = 0; y < m_height; y++) { for(int x = 0; x < m_width; x++) {

        int val = (*this)[y][x]*41; //Declare currents pixels value
        int middle = 41; //Declare average

        if (x &gt; 0)                           { val += (*this)[y][x-1]    *26;middle += 26;}
        if (x &gt; 1)                           { val += (*this)[y][x-2]    *7; middle += 7;}
        if (x &lt; m_width-1)                   { val += (*this)[y][x+1]    *26;middle += 26;}
        if (x &lt; m_width-2)                   { val += (*this)[y][x+2]    *7; middle += 7;}

        if (y &gt; 0)                           { val += (*this)[y-1][x]    *26;middle += 26;}
        if (y &gt; 0 &amp;&amp; x &gt; 0)                   { val += (*this)[y-1][x-1]  *16;middle += 16;}
        if (y &gt; 0 &amp;&amp; x &gt; 1)                   { val += (*this)[y-1][x-2]  *4; middle += 4;}
        if (y &gt; 0 &amp;&amp; x &lt; m_width-1)           { val += (*this)[y-1][x+1]  *16;middle += 16;}
        if (y &gt; 0 &amp;&amp; x &lt; m_width-2)           { val += (*this)[y-1][x+2]  *4; middle += 4;}

        if (y &gt; 1)                           { val += (*this)[y-2][x]    *7; middle += 7;}
        if (y &gt; 1 &amp;&amp; x &gt; 0)                   { val += (*this)[y-2][x-1]  *4; middle += 4;}
        if (y &gt; 1 &amp;&amp; x &gt; 1)                   { val += (*this)[y-2][x-2]  *1; middle += 1;}
        if (y &gt; 1 &amp;&amp; x &lt; m_width-1)           { val += (*this)[y-2][x+1]  *4; middle += 4;}
        if (y &gt; 1 &amp;&amp; x &lt; m_width-2)           { val += (*this)[y-2][x+2]  *1; middle += 1;}

        if (y &lt; m_height-1)                  { val += (*this)[y+1][x]    *26;middle += 26;}
        if (y &lt; m_height-1 &amp;&amp; x &gt; 0)      { val += (*this)[y+1][x-1]  *16;middle += 16;}
        if (y &lt; m_height-1 &amp;&amp; x &gt; 1)      { val += (*this)[y+1][x-2]  *4; middle += 4;}
        if (y &lt; m_height-1 &amp;&amp; x &lt; m_width-1){ val += (*this)[y+1][x+1]    *16;middle += 16;}
        if (y &lt; m_height-1 &amp;&amp; x &lt; m_width-2){ val += (*this)[y+1][x+2]    *4; middle += 4;}

        if (y &lt; m_height-2)                  { val += (*this)[y+2][x]    *7; middle += 7;}
        if (y &lt; m_height-2 &amp;&amp; x &gt; 0)      { val += (*this)[y+2][x-1]  *4; middle += 4;}
        if (y &lt; m_height-2 &amp;&amp; x &gt; 1)      { val += (*this)[y+2][x-2]  *1; middle += 1;}
        if (y &lt; m_height-2 &amp;&amp; x &lt; m_width-1){ val += (*this)[y+2][x+1]    *4; middle += 4;}
        if (y &lt; m_height-2 &amp;&amp; x &lt; m_width-2){ val += (*this)[y+2][x+2]    *1; middle += 1;}

        (*result)[y][x] = (int)val/middle; //Calculating average value for given pixel
    }
}

return [ImageWrapper imageWithCPPImage:result]; //Return the image

}

Comment #1

Posted on Mar 28, 2011 by Helpful Giraffe

+1 to this issue too, just ran into it myself and was surprised that the blur function would reduce the size of the image.

Status: New

Labels:
Type-Defect Priority-Medium