我有两个大小相等的图像,我想计算一个函数,假设f在图像的补丁上,在每个图像位置计算一个数
补丁提取很容易
patches1 = image.extract_patches_2d(img1,(5,5))
patches2 = image.extract_patches_2d(img2,(5,5))
现在应用这个函数可以如下所示
result = numpy.zeros((image1.shape[0], img1.shape[1]))
for i in range(len(image1.shape[0])):
for j in range(len(image1.shape[1])):
result[i,j] = f(patches1[i], patches1[j])
但是这太慢了!!!你知道吗
我想知道什么可能是最好的方法来快速计算它和摆脱循环。你知道吗
谢谢
编辑1:
f的实现是
def f (patch1, patch2):
return np.sqrt(patch1^2 + patch2^2)
我试过这个-任何想要测试他们的代码的人都可以复制我的初始化。基本上,它创建一个单一的标准化图像,并将图像的黑色部分作为补丁a与白色部分作为补丁B进行比较
您可以使用多处理使其快速:
有一种更聪明的方法可以做到这一点:优化f,使其在整个
image
而不是patches1
上工作。这里我只展示一种工程方法。你知道吗相关问题 更多 >
编程相关推荐