changed to iteration over input image and than over output image