Conditional mask considering neighborhood in Python

225 views Asked by At

I want to binarize an 2D numpy array by using a gray level condition, but considering a 4 connectivity neighborhood. Guess the mask could be something like

0 1 0
1 1 1
0 1 0 

In other words, I don't want isolated pixels to be extracted from the image, since I can do this simply by using numpy.where or new_array[array == 20] = 1. The condition I want to use is actually a interval, and all the pixels from this interval that have a 4 neighbors whose values are also within this range, could be printed as 1.

0

There are 0 answers