# Confusion in the position of image coordinates

I am struggling to work out how image coordinates are calculated and how to be consistent when finding particular points in an image using these coordinates for further analysis. I don't think it is necessarily a bug, but it makes it tricky to work with and modify images.

This is best shown by the following example.

We make a test image:

We then replace one of the pixels (at position 20,3) with the value 2 (so it is easy to find.)

testIm2=ReplacePixelValue[testIm, {20, 3} -> 2]

We now try to find the coordinates of this pixel with the value 2.

coords=Position[ImageData[testIm2], 2 | 2.]

which gives the result {13,20}? What is going on here ? How can we be sure of choosing the right pixel values ?

$$(x_i,y_i)$$ which gives coordinates $$(y_i,1+x_{dim}-x_i)$$ where $$x_{dim}$$ is the dimension of the image in the x-direction in the first coordinate system. I hope this helps other people dealing with this problem