I am in the process of implementing an image processing algorithm that requires following rays extending outwards from a starting point and calculating the intensity derivative at each point. The idea is to find the point where the difference in intensity goes beyond a particular threshold.

Specifically I'm examining an image of an eye to find the pupil, and the edge of the pupil is a sharp change in intensity.

How does one iterate along a line in a 2d matrix, and is there a better way to do this? Is this a problem that linear algebra can help with?

Thanks

Stephen Emslie