【问题标题】:OpenCV: How to use the convertScaleAbs() functionOpenCV:如何使用 convertScaleAbs() 函数
【发布时间】:2019-12-05 12:03:34
【问题描述】:

在对图像应用 Sobel 过滤后,我正在尝试将图像转换回灰度。我有以下代码:

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

image = cv2.imread("train.jpg")
img = np.array(image, dtype=np.uint8)

#convert to greyscale
img_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#remove noise
img_smooth = cv2.GaussianBlur(img_grey, (13,13), 0)

sobely = cv2.Sobel(img_smooth,cv2.CV_64F,0,1,ksize=9)

我想使用 convertScaleAbs() 函数将图像 sobely 转换回灰度。我知道该函数将源(要转换为灰度的图像)和目标数组作为参数,但我不确定创建目标数组的最佳方法是什么。任何见解都值得赞赏。

【问题讨论】:

    标签: python numpy opencv computer-vision


    【解决方案1】:

    你可以试试:

    gray = cv2.convertScaleAbs(sobely, alpha=255/sobely.max())
    plt.imshow(gray, cmap='gray')
    
    

    【讨论】:

      【解决方案2】:

      您可以接受 alphabeta 参数的默认参数,因此调用很简单:

      graySobel = cv.convertScaleAbs(sobely)
      

      那么就可以调用adaptiveThreshold

      thres = cv2.adaptiveThreshold(graySobel, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                cv2.THRESH_BINARY, 73, 2)
      

      【讨论】:

        猜你喜欢
        • 2017-03-20
        • 2018-12-29
        • 2010-11-01
        • 1970-01-01
        • 2016-07-10
        • 2012-04-17
        • 1970-01-01
        • 2011-07-04
        • 1970-01-01
        相关资源
        最近更新 更多