NumPy / SciPy:将遮罩移到Image上并检查是否相等 [英] NumPy/SciPy: Move mask over Image and check for equality

查看:256
本文介绍了NumPy / SciPy:将遮罩移到Image上并检查是否相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 NumPy scipy 。我有一个对应于背景的模板图像,我想找出它在输入图像中出现的所有位置,并将输出中相应的数组位置设置为1,否则将它们设置为0.我该怎么做?

I am trying to do image processing using NumPy and scipy. I have a template image corresponding to a background, and I want to find out all the places where it occurs in the input image and set the corresponding array positions in the output to 1, else set them to 0. How can I do this?

推荐答案

您可以使用scipy.ndimage.correlate将模板与图像相关联。然后寻找能给你比赛的亮点。示例:

You can use scipy.ndimage.correlate to correlate your template against the image. Then look for bright spots which will give you your matches. Example:

import scipy.ndimage
from numpy import mean, std

# a, b contain image and template in numpy arrays
correlation = scipy.ndimage.correlate(a, b)
matches = (correlation-mean(correlation)) > 5*std(correlation) # tune depending on level of noise

这篇关于NumPy / SciPy:将遮罩移到Image上并检查是否相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆