首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么correlate2d会返回noise?

为什么correlate2d会返回noise?
EN

Stack Overflow用户
提问于 2019-12-06 05:31:05
回答 1查看 265关注 0票数 0

我目前正在尝试为扫雷机器人创建一个计算机视觉。然而,使用scipy.signal.correlate2d只会产生噪声。下面是我的测试代码,为什么输出只是噪声,而不是我期望的热图?

代码语言:javascript
复制
from scipy import signal
import numpy as np
from cv2 import cv2
from PIL import Image

image = cv2.imread('MinesweeperTest.png',0)
template = cv2.imread('Mine2.png',0)

corr = signal.correlate2d(image,template,mode="same")

Image.fromarray(corr).save("correlation.png")

所有涉及到的图片都可以在这里找到:

MinesweeperTest.png:https://imgur.com/PpLLOW7

Min2.png:https://imgur.com/ApIIs1Z

Correlation.png:https://imgur.com/hkskY00

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-06 05:55:21

在调用correlate2d之前对图像进行预处理,使其平均值为0,这将有助于获得更有意义的2D互相关:

代码语言:javascript
复制
image = image - image.mean()
template = template - template.mean()

一个可重现的例子是:

代码语言:javascript
复制
from imageio import imread
from matplotlib import pyplot as plt
from scipy import signal
import numpy as np

image = imread('https://i.imgur.com/PpLLOW7.png', pilmode='L')
template = imread('https://i.imgur.com/ApIIs1Z.png', pilmode='L')

# fixed these
image = image - image.mean()
template = template - template.mean()

corr = signal.correlate2d(image, template, mode="same")
plt.imshow(corr, cmap='hot')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59203554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档