Here is the code to find image edge and record the morphological connected pixels positions. How to translate the row/col positions to x/y coordinates?

i = ExampleData[{"TestImage", "Lena"}];
im = EdgeDetect[i, 5];
imm = MorphologicalComponents[im];
a = Position[imm,200];

"a" gives a list of positions, how to translate them to x/y coordinates?


1 Answer 1


The image coordinate x is the second element of the position; the image coordinate y is the first position subtracted from the number of rows plus 1.

rows = First@ImageDimensions[i];
xy1 = AffineTransform[{{{0, 1}, {-1, 0}}, {0, rows + 1}}][a]

Another way is to use PixelValuePositions on the morphological components, converted to an Image:

xy2 = PixelValuePositions[Image[imm], 200]


xy1 == xy2
(* True *)

(They happen to be in the same order.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.