我正在尝试使用 skimage 和 scipy 提高灰度图像的图像质量,然后在 cv2 中使用它们。不幸的是,当我尝试使用 cv2 转换 skimage 图像时出现错误。
图像:
import skimage
import scipy
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('Image.png')
scale = 5
img_rs = skimage.transform.rescale(image = img,
scale = scale,
order = 3,
mode = 'wrap',
cval = 0,
multichannel = True,
anti_aliasing = 'none')
img_int = scipy.misc.imresize(img_rs, 0.99999, interp = 'cubic')
img_int_gray = skimage.color.rgb2gray(img_int)
blurred_img = scipy.ndimage.gaussian_filter(img_int_gray, 3)
filter_blurred_img = scipy.ndimage.gaussian_filter(blurred_img, 1)
alpha = 30
sharp_img = blurred_img + alpha * (blurred_img - filter_blurred_img)
#error
img_gs = cv2.cvtColor(sharp_img, cv2.COLOR_BGR2GRAY)
plt.imsave('sharp_img.png', img_gs, cmap = 'gray')
输出:
Traceback (most recent call last):
File "/home/artur/Desktop/test.py", line 25, in <module>
img_gs = cv2.cvtColor(sharp_img, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/color.hpp:255: error: (-2:Unspecified error) in function 'cv::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<3, 4>; VDcn = cv::Set<1>; VDepth = cv::Set<0, 2, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Invalid number of channels in input image:
> 'VScn::contains(scn)'
> where
> 'scn' is 1
现在我读到 skimage 和 cv2 使用不同的格式,所以我尝试在转换为 cv2 之前添加这一行,这应该使它与 cv2 兼容:
sharp_img = skimage.img_as_ubyte(sharp_img)
我究竟做错了什么?
宝慕林4294392
相关分类