Created
January 19, 2013 19:42
-
-
Save maddenpj/4574663 to your computer and use it in GitHub Desktop.
This file contains 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 ImageProcessingClassApp::reduceIntensity(int n) | |
{ | |
int reduce = 2 << n; | |
// myImage is a object variable that starts as a grayscale copy of the original image | |
Surface::Iter iter = myImage.getIter(); | |
while(iter.line()) { | |
while(iter.pixel()) { | |
int orig = iter.r(); | |
int next = orig/reduce; | |
next *= reduce; | |
iter.r() = next; | |
iter.g() = next; | |
iter.b() = next; | |
} | |
} | |
} | |
void ImageProcessingClassApp::average(int n) | |
{ | |
Surface::Iter iter = myImage.getIter(Area(0+n, 0+n, myImage.getWidth()-n, myImage.getHeight()-n)); | |
while(iter.line()) { | |
while(iter.pixel()) { | |
int sum = 0; | |
int count = 0; | |
for(int x = -n/2; x <= n/2; x++) { | |
for(int y = -n/2; y <= n/2; y++) { | |
count++; | |
sum += iter.r(x,y); | |
} | |
} | |
int average = sum/count; | |
iter.r() = average; | |
iter.g() = average; | |
iter.b() = average; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment