Image 8-connectivity without excessive branching?

Posted by shoosh on Stack Overflow See other posts from Stack Overflow or by shoosh
Published on 2010-04-13T09:06:06Z Indexed on 2010/04/13 9:12 UTC
Read the original article Hit count: 401

I'm writing a low level image processing algorithm which needs to do alot of 8-connectivity checks for pixels. For every pixel I often need to check the pixels above it, below it and on its sides and diagonals.

On the edges of the image there are special cases where there are only 5 or 3 neighbors instead of 8 neighbors for a pixels. The naive way to do it is for every access to check if the coordinates are in the right range and if not, return some default value.

I'm looking for a way to avoid all these checks since they introduce a large overhead to the algorithm. Are there any tricks to avoid it altogether?

© Stack Overflow or respective owner

Related posts about image-processing

Related posts about Performance