[Numpy-discussion] Neighbour-frequency matrix

David Warde-Farley dwf@cs.toronto....
Wed Jul 15 16:51:01 CDT 2009


Here's an interesting problem, and it might've already been solved by  
some of you folks that do image processing:

Suppose I have an 8-bit integer 2-d array, X, and I want a 256x256  
matrix that tells me how many times a pixel value v was horizontally  
(along second dimension) adjacent to a pixel value b.

So,  in an array [[1, 2, 1],[1,1,2],[1,0,0]] the upper left 3x3 square  
would be [[1, 1, 0], [1, 1, 3], [0, 3, 0]] with the rest of the matrix  
0.

Is there an efficient way to do such a thing with numpy operations? I  
can't think of a way.

David


More information about the NumPy-Discussion mailing list