How to get the outermost pixels of the image

How can I get the outermost pixels of an image? I want to also be able to loop through the array. What do I mean by looping through the array? Well I have a circle image. The position of the white outline pixels of the circle is what I want to store in an array. And when looping through it this is what I would want How can I achieve this with any image? So far I have made a transparency map, which is a 2 dimensional array that contains 0 if the pixel is transparent and 1 if the pixel is opaque.

How to get the outermost pixels of the image

How can I get the outermost pixels of an image? I want to also be able to loop through the array.

What do I mean by looping through the array? Well I have a circle image. circle

The position of the white outline pixels of the circle is what I want to store in an array.

And when looping through it this is what I would want

looping

How can I achieve this with any image?

So far I have made a transparency map, which is a 2 dimensional array that contains 0 if the pixel is transparent and 1 if the pixel is opaque.