Created
April 18, 2017 21:17
-
-
Save Darker/d971d184970f041d53bb131343de1fc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Image::convolute(const int matrix[3][3], Image& target) | |
{ | |
target.setSize(getWidth(), getHeight()); | |
for(size_t y=0, yl=getHeight(); y<yl; ++y) { | |
for(size_t x=0, xl=getWidth(); x<xl; ++x) { | |
if(x==0 || y==0 || x+1==xl || y+1==yl) { | |
target.pixels[y][x] = pixels[y][x]; | |
} | |
else { | |
target.pixels[y][x] = ((pixels[y-1][x-1]*matrix[0][0]) | |
+ (pixels[y-1][x ]*matrix[0][1]) | |
+ (pixels[y-1][x+1]*matrix[0][2]) | |
+ (pixels[y ][x-1]*matrix[1][0]) | |
+ (pixels[y ][x ]*matrix[1][1]) | |
+ (pixels[y ][x+1]*matrix[1][2]) | |
+ (pixels[y+1][x-1]*matrix[2][0]) | |
+ (pixels[y+1][x ]*matrix[2][1]) | |
+ (pixels[y+1][x+1]*matrix[2][2])); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment