我正在尝试使用 skimage 和 scipy 提高灰度图像的图像质量,然后在 cv2 中使用它们。不幸的是,当我尝试使用 cv2 转换 skimage 图像时出现错误。图像:import skimageimport scipyimport cv2import matplotlib.pyplot as pltimg = cv2.imread('Image.png')scale = 5img_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 = 30sharp_img = blurred_img + alpha * (blurred_img - filter_blurred_img)#errorimg_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)我究竟做错了什么?
1 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
您已经在行中将图像转换为灰度
img_int_gray = skimage.color.rgb2gray(img_int)
它在线上失败
img_gs = cv2.cvtColor(sharp_img, cv2.COLOR_BGR2GRAY)
因为它需要一个 3 通道的 BGR 图像。删除了这一行,你可以只保存sharp_img
与plt.imsave('sharp_img.png', sharp_img, cmap = 'gray')
添加回答
举报
0/150
提交
取消