我有两个黑白图像,我需要计算互信息.
Image 1 = X
Image 2 = Y
Run Code Online (Sandbox Code Playgroud)
我知道互信息可以定义为:
MI = entropy(X) + entropy(Y) - JointEntropy(X,Y)
Run Code Online (Sandbox Code Playgroud)
MATLAB已经具有内置函数来计算熵但不计算联合熵.我想真正的问题是:我如何计算两幅图像的联合熵?
这是我想要找到的联合熵的图像示例:
X =
0 0 0 0 0 0
0 0 1 1 0 0
0 0 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Y =
0 0 0 0 0 0
0 0 0.38 0.82 0.38 0.04
0 0 0.32 0.82 0.68 0.17
0 0 0.04 0.14 0.11 0
0 0 0 …Run Code Online (Sandbox Code Playgroud) 假设[]是一个有序向量.如何找到第一个(最小的)索引ix,使得(ix)>阈值?
给定一个向量a = [1,2,3.2,4,5]和一个元素x = 3在向量a中,如何找到大于x的确切条目?
我很难找到在Python列表中查找索引的有效解决方案.到目前为止,我测试过的所有解决方案都比MATLAB中的"find"功能慢.我刚刚开始使用Python(因此,我不是很有经验).
在MATLAB中我会使用以下内容:
a = linspace(0, 1000, 1000); % monotonically increasing vector
b = 1000 * rand(1, 100); % 100 points I want to find in a
for i = 1 : numel(b)
indices(i) = find(b(i) <= a, 1); % find the first index where b(i) <= a
end
Run Code Online (Sandbox Code Playgroud)
如果我使用MATLAB的arrayfun(),我可以加快这个过程.在Python中我尝试了几种可能性.我用了
for i in xrange(0, len(b)):
tmp = numpy.where(b[i] <= a)
indices.append(tmp[0][0])
Run Code Online (Sandbox Code Playgroud)
这花费了很多时间,特别是如果a非常大的话.如果b排序比我可以使用
for i in xrange(0, len(b)):
if(b[curr_idx] <= a[i]):
indices.append(i)
curr_idx += 1
if(curr_idx >= len(b)):
return indices
break
Run Code Online (Sandbox Code Playgroud)
这比numpy.where()解决方案快得多,因为我只需要在列表中搜索一次,但这仍然比MATLAB解决方案慢. …