opencv canny: Do minVal and maxVal matter if you're working with a black and white image?

流过昼夜 提交于 2020-01-25 02:52:43

问题


Preface: This is a continuation of this question.

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()

My Question:

  • When using open cv's canny function, do your choices for minVal and maxVal matter if you're working with a black and white image?

Reason I ask:

  • I've experimented with many values and they don't seem to matter.

回答1:


The threshold values do matter.


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

And the possible magnitude values are:

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

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.



来源:https://stackoverflow.com/questions/35102372/opencv-canny-do-minval-and-maxval-matter-if-youre-working-with-a-black-and-whi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!