Homework 5
a) implement these kernel filters for an image programmatically:
(multiply all 9 pixels by these values, add them up. divide by weight. set value of [me] pixel)
also important: make sure the value you’re setting [me] pixel to is between 0 and 255, if it isn’t adjust it. one easy way to do this is value = ofClamp(value, 0, 255);
sharpen: -1,-1,-1, -1,9,-1, -1,-1,-1 weight 1
gaussian: 1,2,1, 2,4,2, 1,2,1 weight: 16
prewitt (edge): 1,1,1 0,0,0 -1,-1,-1 weight 0
b) median filtering
Given the pixel + neighbors routine do the following:
for every pixel in an image, put it and it’s 8 neighbors in a temporary array of 9 elements, that you sort with qsort. then take the middle most element (the median) and use that as the new value
try doing both gaussian blur (1,2,1 / 2,4,2 / 1,2,1 kernel) and median filtering on a noisy image, at least once but perhaps multiple times. Which is better at fixing or removing points of noise?
c) (advanced, optional, this is for the hardcore folks!). Try doing this both with squares and circles. First threshold an image. Then, find the largest square (or circle in the image). It can be white or black. Record it, then turn invert just those pixels and try to find the next larget box. here’s an input and result (via squares). when you draw the outcome, you can draw it just a bit smaller then the actual found square so it’s possible to see them.
input image: