[英]Laplacian opencv fails with cv2.error: OpenCV(4.1.2)
I am trying to apply laplacian to a median filter output to get a sharper image, by later processing.我正在尝试将 laplacian 应用于中值滤波器输出以获得更清晰的图像,通过后期处理。 The code snippet is as below :
代码片段如下:
img = plt.imread('example.png')
img_res = cv.resize(img,(256,256))
gray_image = cv.cvtColor(img_res, cv.COLOR_BGR2GRAY)
median_img = median_filter(gray_image, 5)
# Calculate the Laplacian
lap_img = cv.Laplacian(median_img,cv.CV_64F)
The input image is a RGB medical image.输入图像是 RGB 医学图像。 I am faced with the following error, when running this code:
运行此代码时,我遇到以下错误:
cv2.error: OpenCV(4.1.2) C:/projects/opencv-python/opencv/modules/imgproc/src/filter.simd.hpp:3175: error: (-213:The function/feature is not implemented) Unsupported combination of source format (=5), and destination format (=6) in function 'cv::opt_AVX2::getLinearFilter'
This error occurs for any image from the dataset.数据集中的任何图像都会发生此错误。 Could you please point out what could be the issue?
你能指出可能是什么问题吗? The example is followed from this link for grayscale images.
该示例来自此链接,用于灰度图像。
Instead of using two different libraries ( matplotlib
and opencv
), stick to using one library at a time while performing image-processing.不要使用两个不同的库(
matplotlib
和opencv
),而是在执行图像处理时一次使用一个库。 The reason is because these two libraries use different formats to store images.原因是因为这两个库使用不同的格式来存储图像。
matplotlib
uses RGB
convention while opencv
uses BGR
. matplotlib
使用RGB
约定,而opencv
使用BGR
。 My guess is that you're encountering this error due to using matplotlib
to load the image, and then performing operations with opencv
.我的猜测是您遇到此错误是由于使用
matplotlib
加载图像,然后使用opencv
执行操作。 Simply, loading the image using cv2.imread()
instead of plt.imread()
seems to fix the problem简单地说,使用
cv2.imread()
而不是plt.imread()
加载图像似乎可以解决问题
Input ->
Output输入
->
输出
import cv2
from scipy.ndimage.filters import median_filter
import numpy as np
img = cv2.imread('1.png')
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
median_img = median_filter(gray_image, 5)
# Calculate the Laplacian
lap_img = cv2.Laplacian(median_img,cv2.CV_64F).astype(np.uint8)
cv2.imshow('lap_img', lap_img)
cv2.imwrite('lap_img.png', lap_img)
cv2.waitKey()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.