You will have to read the image into a two dimensional structure, maybe a two dimensional array, and then apply the operations to corresponding elements at position x and y.
ResultantImage[x][y] = Image1[x][y] - Image2[x][y]
You could do this even with a single dimensional array, but that is rather unintuitive in my opinion.