opencv canny:如果要处理黑白图像,minVal和maxVal是否重要? [英] opencv canny: Do minVal and maxVal matter if you're working with a black and white image?
问题描述
前言:这是此问题的延续.
请考虑以下代码,该代码取自此处:
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)
图像,您可以获得的dx
和dy
可能值为:
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
可能的幅度值为:
- L1 (默认):
0, 510, 1020, 1530
. - L2 :
0, 360.63, 510, 721.25, 806.38, 1020, 1081.87, 1140.40
- L1 (default) :
0, 510, 1020, 1530
. - 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屋!