OpenCV binary filter which sets a pixel to background if ALL neighbors are background
I'm looking for an OpenCV image filter that works on binary images. Basically what I want is the filter to set a foreground pixel to background, if and only if all 8 of its neighbors are background. It should not touch any pixels that are background. Those should always stay backgroun开发者_如何学编程d.
Thanks in advance!
Two possible ways of going about this:
You'll have to use Get2D() and put the image pixels into a 2-D array. Then manually check with a 3x3 mask for pixels neighbors that are background. This would be the lengthy but failsafe method OR
Read up on morphological opening using
cvMorphologyEx()
function: it basically removes small bright regions in image. The default morphology kernel is a 3x3 anchored at center so that will correspond to your requirement of 8 neighbors.Late response to the question but do see if these work. :)
精彩评论