Optimizing distance calculation between rows and matrices with numpy

时间:2016-02-03 03:08:57

标签: python algorithm numpy vector

I have an image processing problem where I am trying to create something known as a histogram of activated patches.

I have a codebook (a numpy array, 200X36) and an image (another numpy array, 128X128). For each pixel, I have to see which codebook vector is nearest.

The distance between a codebook vector and a pixel is defined as the Euclidean distance between the vector and a 6X6 patch left cornered at the pixel, which is reshaped to form a 1X36 vector.

For each pixel, I am extracting the patch and computing the nearest codebook vector using the code d,i=spatial.KDTree(cData).query(patch.reshape((1,6*6))). But this is O(N) for number of pixels. Is there any way to improve the running time? A reasonable approximation is fine.

0 个答案:

没有答案