Ask Your Question

fbr's profile - activity

2014-02-24 02:31:37 -0600 commented question How to create my own filter to detect a pixel is a local maximum?

That sound highly unefficient. A dumb way would be to test explicitely all the neighbor pixels. I'll try that since I don't have a better idea.

2014-02-24 01:53:01 -0600 asked a question How to count the number of neighbor pixels in a mask?
Let's say I have a 0 or 1 mask image.

How can I count, for each pixel, its number of 9-connected
neighbors which are set to 1?

I tried this:

count_neighbors_K = np.array([ [1,1,1],
                               [1,0,1],
                               [1,1,1] ], dtype = np.uint8)


test_array = np.array([ [0,0,0,0],
                        [0,0,0,0],
                        [0,1,0,0],
                        [0,0,0,0] ], dtype = np.uint8)

# neighbors_count = cv2.filter2D(mask, -1, count_neighbors_K)
neighbors_count = cv2.filter2D(test_array, -1, count_neighbors_K)
neighbors_count

But the count on the borders are wrong:

>>> neighbors_count
array([[0, 0, 0, 0],
       [2, 1, 1, 0],
       [2, 0, 1, 0],
       [4, 2, 2, 0]], dtype=uint8)
2014-02-24 01:46:57 -0600 commented question How to create my own filter to detect a pixel is a local maximum?

I am looking for something local, not global.

2014-02-23 23:43:16 -0600 asked a question How to create my own filter to detect a pixel is a local maximum?

Hello,

I am interested into doing this from the Python cv2 wrapper of OpenCV.

I'd like to test each pixel of a gray image to see if it has a value >= to the value of its 9 neighbors.

The output should be a binary mask, preferably of the same size than the input image.

Thanks, F.