BRAIN YU: The next filter you'll implement
is a reflection filter, wherein this filter, you'll take an image
and produce the mirror image of that original picture.
How are you going to do that?
Well, recall that each image is really just a two dimensional array where
we have rows, and every row has individual pixels inside of that row.
We could number the rows in this image.
So we have rows 0, 1, 2, 3, 4, and 5, for example.
When we take the mirror image of this picture, what really happens
is that the rows stay in the same order, but the pixels in the row switch
places so that row 0 is still at the top, but it's been reflected.
Row 1 is still the second row, but it's been reflected, so on and so forth.
So what we really need to do in order to take the reflection of an image
is just to take each row and apply the same filter to each row,
taking the individual pixels in that row, which might all be different,
and reflecting them so that the pixel that was originally on the far left
of the row is now in the far right.
The pixel that was originally second from the left in the row
is now second from the right so on and so forth.
If there are an odd number of pixels, as there are in this particular row,
you'll notice that the middle pixel, the pixel at index 5,
doesn't actually change position.
But if there were an even number of pixels,
then every pixel would switch positions with the pixels on the mirror image
side of it on the opposite end of the same row.
So what is the algorithm you're actually going to implement here?
Well, for every row, you're going to want
to swap the pixels on horizontally opposite sides
where the far left pixel becomes the far right and vice versa.
And once you can do this for one row, you
can repeat this using some sort of loop applying it to every row in the image
swapping the first row, then the second row, third row, so on and so forth.
After you've implemented this function, you can test it by running ./filter -r
for the reflect filter then passing in an infile and specifying an outfile.
Once you do that, if the input file looks like this,
then the output file should be the reflection of that original image.
My name is Brian, and this was reflect.