opencv canny:如果要处理黑白图像,minVal和maxVal是否重要? [英] opencv canny: Do minVal and maxVal matter if you're working with a black and white image?

查看:117
本文介绍了opencv canny:如果要处理黑白图像,minVal和maxVal是否重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前言:这是此问题的延续.

请考虑以下代码,该代码取自此处:

Consider the following code, taken from here:

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('messi5.jpg',0)
edges = cv2.Canny(img,100,200) # Would 100 and 200 matter if your original image was black and white?

plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Edge Image'), plt.xticks([]), plt.yticks([])

plt.show()

我的问题:

  • 在使用open cv的canny函数时,如果要处理黑白图像,对minVal和maxVal的选择是否重要?

我问的原因:

  • 我尝试了很多值,但它们似乎并不重要.

推荐答案

阈值确实很重要.

假定3x3 Sobel滤波器(如Canny中所示),对于输入的二进制(0, 255)图像,您可以获得的dxdy可能值为:

Assuming a 3x3 Sobel filter (as in Canny), the possible values for dx and dy you can get for an input binary (0, 255) image are:

-1020, -765, -510, -255, 0, 255, 510, 765, 1020

可能的幅度值为:

  1. L1 (默认):0, 510, 1020, 1530.
  2. L2 :0, 360.63, 510, 721.25, 806.38, 1020, 1081.87, 1140.40
  1. L1 (default) : 0, 510, 1020, 1530.
  2. L2 : 0, 360.63, 510, 721.25, 806.38, 1020, 1081.87, 1140.40

因此,如果使用的话,您会从Canny获得不同的输出图像,例如(minVal, maxVal)作为(200,400)(400,600).

So, you'll get different output images from Canny if you use, for example (minVal, maxVal) as (200,400) or (400,600).

如果使用相同间隔的阈值(间隔的边界是上面显示的幅度值),那么您将始终获得相同的结果.

If you use thresholds that are in the same interval (the boundary of the intervals are the magnitude values shown above), then you'll get always the same result.

这篇关于opencv canny:如果要处理黑白图像,minVal和maxVal是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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