chain code algorithm

T

The_Sheriff

hi,
need help.....how do I implement the chain code algorithm on a binary
image in C++???

Joe
 
A

andrew queisser

The_Sheriff said:
hi,
need help.....how do I implement the chain code algorithm on a binary
image in C++???

Joe
Are you talking about encoding the contour of binary blob as a chain code?
If so, I've done this:


1) Assume you're on edge pixel 'x'

123
4x5
678

2) Arrange the neighboring pixels into a byte

12345678

3) Go into a 256-element lookup table LUT1 which you've precalculated. LUT1
maps the byte into one of 8 directions.

4) Go into another 8-element LUT2 that maps your direction into an offset
(if you have a flat framebuffer) or a pair of x,y movements to calculate the
next position

4) Store the movement and update your pixel position.

5) Repeat


For example (assuming counter-clockwise movement) and starting point x0,y0

111
1x0
110

gives you 11110110 = 0xF6. LUT1[0xF6] needs to return 3. LUT2[3] needs to
return { 1, -1 } assuming traditional fb with 0,0 in the upper left corner.
Store 3 in the array and continue at x0+1,y0-1.

You can collapse the two LUTs into one.

Hope that helps,
Andrew
 
T

The_Sheriff

i think my question is easier than this....i want to perform the chain
code algorithm on the image "F.img." "0" would represent the
background and "255" represents the object.
The starting point is the first object pixel in the raster scan and i
have to trace the object contour in the counter-clockwise direction
using 8-connectedness
i want to also print out the resulting chain codes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top