However it is easy to implement using three for loops (two to go through the pixels, one for the sum of the products).