如何用cv2正确实现高斯模糊



我得到以下错误

error                                     Traceback (most recent call last)
<ipython-input-10-2d3a348b0b9b> in <module>()
25 
26 #gaussian blur (sigma = 1)
---> 27 gaus_blur1 = cv2.GaussianBlur(img,(0,0), 1, 1)
28 cv2_imshow(gaus_blur1[2000])
29 
error: OpenCV(4.1.2) /io/opencv/modules/core/src/matrix.cpp:757: error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in function 'locateROI'

当我尝试做时

for k in range (7165):
img[k] = cv2.imread('/content/FIGURE/figure' + str(k) +'.png', 1) 
#storing images into array of integers
img_neg = 255 - img    #taking the negative
#cv2_imshow(img_neg[2000])
#voxel form
#gaussian blur (sigma = 1)
gaus_blur1 = cv2.GaussianBlur(img_neg,(0,0), 1, 1)

网上的大多数解决方案都提到,无法正确读取文件夹中的图像,但事实并非如此,我试图绘制一些图像,而数据集正是这样。你知道它可能是什么吗?

虽然你的问题中缺乏上下文仍然不太清楚,但你似乎试图模糊图像的阵列,而不是一个2D图像

模糊每个图像本身:

# could be some other structure than dicts, but it's not clear from the question
img = {}  
gaus_blur = {}
for k in range(7165):
image = cv2.imread("/content/FIGURE/figure" + str(k) + ".png", 1)
img[k] = image  # store original image
gaus_blur[k] = cv2.GaussianBlur(255 - image, (0, 0), 1, 1)  # store inverse blurred image

最新更新