1 00:00:00,000 --> 00:00:00,120 2 00:00:00,120 --> 00:00:01,870 BRAIN YU: The next filter you'll implement 3 00:00:01,870 --> 00:00:05,160 is a reflection filter, wherein this filter, you'll take an image 4 00:00:05,160 --> 00:00:08,700 and produce the mirror image of that original picture. 5 00:00:08,700 --> 00:00:10,210 How are you going to do that? 6 00:00:10,210 --> 00:00:13,920 Well, recall that each image is really just a two dimensional array where 7 00:00:13,920 --> 00:00:18,475 we have rows, and every row has individual pixels inside of that row. 8 00:00:18,475 --> 00:00:20,100 We could number the rows in this image. 9 00:00:20,100 --> 00:00:23,850 So we have rows 0, 1, 2, 3, 4, and 5, for example. 10 00:00:23,850 --> 00:00:27,240 When we take the mirror image of this picture, what really happens 11 00:00:27,240 --> 00:00:31,560 is that the rows stay in the same order, but the pixels in the row switch 12 00:00:31,560 --> 00:00:35,370 places so that row 0 is still at the top, but it's been reflected. 13 00:00:35,370 --> 00:00:39,970 Row 1 is still the second row, but it's been reflected, so on and so forth. 14 00:00:39,970 --> 00:00:43,500 So what we really need to do in order to take the reflection of an image 15 00:00:43,500 --> 00:00:47,430 is just to take each row and apply the same filter to each row, 16 00:00:47,430 --> 00:00:51,000 taking the individual pixels in that row, which might all be different, 17 00:00:51,000 --> 00:00:54,570 and reflecting them so that the pixel that was originally on the far left 18 00:00:54,570 --> 00:00:56,730 of the row is now in the far right. 19 00:00:56,730 --> 00:00:59,310 The pixel that was originally second from the left in the row 20 00:00:59,310 --> 00:01:02,640 is now second from the right so on and so forth. 21 00:01:02,640 --> 00:01:06,390 If there are an odd number of pixels, as there are in this particular row, 22 00:01:06,390 --> 00:01:09,660 you'll notice that the middle pixel, the pixel at index 5, 23 00:01:09,660 --> 00:01:11,820 doesn't actually change position. 24 00:01:11,820 --> 00:01:13,950 But if there were an even number of pixels, 25 00:01:13,950 --> 00:01:17,940 then every pixel would switch positions with the pixels on the mirror image 26 00:01:17,940 --> 00:01:21,490 side of it on the opposite end of the same row. 27 00:01:21,490 --> 00:01:24,480 So what is the algorithm you're actually going to implement here? 28 00:01:24,480 --> 00:01:26,220 Well, for every row, you're going to want 29 00:01:26,220 --> 00:01:29,550 to swap the pixels on horizontally opposite sides 30 00:01:29,550 --> 00:01:32,940 where the far left pixel becomes the far right and vice versa. 31 00:01:32,940 --> 00:01:34,740 And once you can do this for one row, you 32 00:01:34,740 --> 00:01:38,700 can repeat this using some sort of loop applying it to every row in the image 33 00:01:38,700 --> 00:01:43,530 swapping the first row, then the second row, third row, so on and so forth. 34 00:01:43,530 --> 00:01:48,480 After you've implemented this function, you can test it by running ./filter -r 35 00:01:48,480 --> 00:01:53,500 for the reflect filter then passing in an infile and specifying an outfile. 36 00:01:53,500 --> 00:01:56,250 Once you do that, if the input file looks like this, 37 00:01:56,250 --> 00:02:00,270 then the output file should be the reflection of that original image. 38 00:02:00,270 --> 00:02:03,750 My name is Brian, and this was reflect. 39 00:02:03,750 --> 00:02:04,992