Hello all!
I've trying to figure out a way to implement a simple procedural algorithm in jitter that traces the contours of a one bit matrix.
I'd like to implement something like the moore-neighbor (radial sweep) algorithm for edge detection but for an image forwhich the edges have already been detected and extracted (using cv.jit.binedge).
The goal would be to fill a two plane matrix, where plane0 would be a one-dimensional array of all the x values of the consecutive edges and plane1 would have the corresponding y coordinates. This would be like updating a pens position in an lcd, following the edge from beginning to end in a sequence.
In a way, this is kind of like the opposite of a tracking application: instead of tracking a point and leaving a traced line, I would like to trace the line and output the consecutive coordinates of the point.
The algorithm would be something like this:
1-spiral inward from the outer edge of the reference matrix until the first "on" pixel is discovered.
2-output the coordinates of this pixel to the first empty cell (on two planes) of the "trace" matrix.
3-turn the current pixel on the reference matrix off and check the neighboring pixels in clockwise order (starting from the previous off pixel the pen was at) to see if any of those are also on.
-->If one is found then move "pen" to that pixel and repeat from step 2.
-->If none are found then repeat from step 1.
4- do this until the reference matrix's cell values add up to zero.
any suggestions? is there an object that already does this or do I have to compose this in jit.expr? Is there a simpler way?
Thanks!