Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gaussian blur bug #5

Open
GoogleCodeExporter opened this issue Oct 3, 2015 · 1 comment
Open

Gaussian blur bug #5

GoogleCodeExporter opened this issue Oct 3, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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 > 0)                          { val += (*this)[y][x-1]    *26;middle += 26;}
            if (x > 1)                          { val += (*this)[y][x-2]    *7; middle += 7;}
            if (x < m_width-1)                  { val += (*this)[y][x+1]    *26;middle += 26;}
            if (x < m_width-2)                  { val += (*this)[y][x+2]    *7; middle += 7;}

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

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

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

            if (y < m_height-2)                 { val += (*this)[y+2][x]    *7; middle += 7;}
            if (y < m_height-2 && x > 0)        { val += (*this)[y+2][x-1]  *4; middle += 4;}
            if (y < m_height-2 && x > 1)        { val += (*this)[y+2][x-2]  *1; middle += 1;}
            if (y < m_height-2 && x < m_width-1){ val += (*this)[y+2][x+1]  *4; middle += 4;}
            if (y < m_height-2 && x < 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
}

Original issue reported on code.google.com by Me.Te...@gmail.com on 13 Jul 2010 at 7:10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant