implement a tracing algorithm in jitter

Nov 11, 2011 at 6:20pm

implement a tracing algorithm in jitter

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?


Nov 12, 2011 at 11:32am


checkout cv.jit library, especially cv.jit.snake.

cv.jit is at:

have fun!

Nov 13, 2011 at 6:41pm

thanks for your reply nesa. Actually I had already checked out cv.jit.snake, and since you suggested it, I looked deeper into it.

But I still can

i’ve been trying to extract the contours fist with cv.jit.binedge, then taking the coordinates of those lines to build the snake matrix, but I’m unsure of how to fill a matrix with their coordinates without iterating the matrix (jit.iter) and selecting the coordinates of only the ‘on” pixels.

it seems to me that if I iterate the matrix or spilling it into lists i’m using up precious processor cycles.

is there a way to fill a matrix with the coordinates of the “on” pixels without iterating or spilling the list? I’m sure there must be.

I’m thinking that ideally, after finding the contours with cv.jit.binedge, what I should be doing is filling a one dimensional two plane matrix with the x coordinates of the “on” cells on the first plane and the y coordinates on the second plane, then reorganizing the cells into a consecutive sequence so that the coordinates spit out in order of proximity to the previous “on” cell. (perhaps tap.jit.proximity would be a good way to do that, but i’d rather not pay for it.)

But I basically keep running up against the same problem all the time. I’m unaware of a method for filling a matrix with the coordinates of specific cells (the “on” ones) in another matrix without iterating or spilling this initial matrix.

can you or anyone help?


Feb 22, 2013 at 8:36am

hello urmatter,

Did you ever make any progress on this? I have been attempting to build something similar to what you describe, and have plenty of ideas, but more questions than answers.



You must be logged in to reply to this topic.