[Numpy-discussion] Neighbour-frequency matrix

Stéfan van der Walt stefan@sun.ac...
Thu Jul 16 10:51:35 CDT 2009

2009/7/15 David Warde-Farley <dwf@cs.toronto.edu>:
> 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.

You can also have a look at the gray-level co-occurrence matrix code here:



More information about the NumPy-Discussion mailing list