Previous | Next --- Slide 15 of 63
Back to Lecture Thumbnails
tennis_player

To improve this code (and all the slides using this format), I would suggest getting rid of the weights vector. We do not need to multiply each input pixel by 1/9 before adding to tmp. Instead, to possibly improve precision and also improve the readability of the code, we could sum all 9 input pixels into tmp and then set the output pixel to be tmp / 9. In the optimized code from the previous slide, it seems that they are computing a sum variable first and then dividing by one third to produce the avg variable.

gklimias

@tennis_player (go Roger) we need to multiply by weights (which don't necessarily need to be 1/9) as it says in the code to avoid overflaws. The intensity of each color in RGB is usually stored as value between 0 and 1 or 0 to 255. Therefore, if we don't multiply by weights when doing the addition, we would overflow and get incorrect results.

Please log in to leave a comment.