OpenCV:如何使用convertScaleAbs()函数 [英] OpenCV: How to use the convertScaleAbs() function
本文介绍了OpenCV:如何使用convertScaleAbs()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在将Sobel滤镜应用于图像后,我试图将图像转换回灰度.我有以下代码:
I am trying to convert an image back to greyscale after applying Sobel filtering on it. I have the following code:
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
转换回灰度.我知道该函数将源(要转换为灰度的图像)和目标数组作为参数,但是我不确定创建目标数组的最佳方法是什么.任何见解都会受到赞赏.
I want to convert the image sobely
back to greyscale using the convertScaleAbs() function. I know that the function takes a source (the image to be converted to greyscale) and destination array as arguments, but I am not sure what is the best way to go about creating the destination array. Any insights are appreciated.
推荐答案
您可以尝试:
gray = cv2.convertScaleAbs(sobely, alpha=255/sobely.max())
plt.imshow(gray, cmap='gray')
这篇关于OpenCV:如何使用convertScaleAbs()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文