映射联合直方图值

时间:2014-11-07 02:14:49

标签: python numpy matplotlib

我问了一个类似的问题(Mapping values from a joint histogram back into the image spaces),但我已经意识到JH上任何值大于1的点都不会被映射回图像空间中的像素数量。例如,如果图像A和图像B具有JH值3,例如A的强度3和B的6,那么这意味着有效的3个像素具有该信息。这是我(失败)尝试映射索引。我应该提到图像A和B的值在0到255之间,而JH的形状为256x256,所以分类是一对一的,幸运的是!

import numpy as np 

rows, cols = A.shape[0], B.shape[1]
N = 256 # bins

#### Numpy's method
#H,xedge,yedge = np.histogram2d(A, B, bins=(rows,cols))


#### Manually
H1 = np.zeros((N, N), dtype=float)
inds = np.array([[0, 0, 0, 0, 0]])

for i,j in product(range(rows), range(cols)):
    # Keep in mind H[0,0] will be HUGE
    H1[A[i,j], B[i,j]] = H1[A[i,j], B[i,j]] + 1

    # conditionals for saving indices 
    if H1[A[i,j], B[i,j]]>0:
        # omit the point where the intensities are 0 for both 
        if A[i,j]!=0 and B[i,j]!=0:
            inds = np.append(inds, [[A[i,j], B[i, j], i, j, 
                    H1[A[i,j], B[i,j]]]], axis=0)


# omit the first row and sort by the last column, the JH 
# outputs are A, B, i, j, H values
inds = inds[1:]
inds = inds[np.argsort(inds[:, 0])]

但是如果你使用上面链接的方法在联合直方图中映射1的值,你得到3662个值,但这个方法得到6507,几乎加倍!我有点难过了

0 个答案:

没有答案