Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用opencv中的“GaussianBlur()”指令演示opencv中使用的高斯核GaussianBlur? 我想演示openCV中使用的高斯核cv2.GaussianBlur(img,内核大小,西格玛)用于解释目的 我知道如何演示应用模糊后产生的图像,这不是我的目标 我的目标是为任何使用的sigma和任何使用的内核大小自动演示内核 我看过一段代码(如下所述),但我更喜欢使用与OpenCV中使用的指令相关的,而不仅仅是一般的数学依赖方法 预期的输出内核如下所示:_Python_Opencv_Image Processing_Gaussianblur - Fatal编程技术网

Python 如何使用opencv中的“GaussianBlur()”指令演示opencv中使用的高斯核GaussianBlur? 我想演示openCV中使用的高斯核cv2.GaussianBlur(img,内核大小,西格玛)用于解释目的 我知道如何演示应用模糊后产生的图像,这不是我的目标 我的目标是为任何使用的sigma和任何使用的内核大小自动演示内核 我看过一段代码(如下所述),但我更喜欢使用与OpenCV中使用的指令相关的,而不仅仅是一般的数学依赖方法 预期的输出内核如下所示:

Python 如何使用opencv中的“GaussianBlur()”指令演示opencv中使用的高斯核GaussianBlur? 我想演示openCV中使用的高斯核cv2.GaussianBlur(img,内核大小,西格玛)用于解释目的 我知道如何演示应用模糊后产生的图像,这不是我的目标 我的目标是为任何使用的sigma和任何使用的内核大小自动演示内核 我看过一段代码(如下所述),但我更喜欢使用与OpenCV中使用的指令相关的,而不仅仅是一般的数学依赖方法 预期的输出内核如下所示:,python,opencv,image-processing,gaussianblur,Python,Opencv,Image Processing,Gaussianblur,导入cv2 将numpy作为np导入 #读取图像 img_path='image.jpg' img=cv2.imread(img\u路径) img=cv2.cvt颜色(img,cv2.COLOR\u BGR2RGB) #高斯模糊器 内核=np.one((15,15)) 西格玛=2 模糊图像=cv2.GaussianBlur(img,(Kernel.shape[0],Kernel.shape[1]),sigma) 高斯内核手册代码: def dnorm(x,mu,sd): 返回1/(np.sqr

导入cv2
将numpy作为np导入
#读取图像
img_path='image.jpg'
img=cv2.imread(img\u路径)
img=cv2.cvt颜色(img,cv2.COLOR\u BGR2RGB)
#高斯模糊器
内核=np.one((15,15))
西格玛=2
模糊图像=cv2.GaussianBlur(img,(Kernel.shape[0],Kernel.shape[1]),sigma)
高斯内核手册代码:
def dnorm(x,mu,sd):
返回1/(np.sqrt(2*np.pi)*sd)*np.e**(-np.power((x-mu)/sd,2)/2)
def gaussian_内核(大小,sigma=1,verbose=False):
kernel_1D=np.linspace(-(大小//2),大小//2,大小)
对于范围内的i(尺寸):
kernel_1D[i]=dnorm(kernel_1D[i],0,sigma)
kernel_2D=np.outer(kernel_1D.T,kernel_1D.T)
kernel_2D*=1.0/kernel_2D.max()
如果冗长:
plt.imshow(kernel_2D,interpolation='none',cmap='gray')
plt.标题(“图像”)
plt.show()
返回内核

在Python/OpenCV中有一种方法

 - Read the input
 - Create a delta image (one white pixel in the center of a black background)
 - Blur the image
 - List item
 - Resize the image to enlarge it
 - Stretch the image to full dynamic range
 - Save the result


三角洲图像:

结果:


你似乎知道你要做的一切。还有什么?@YvesDaoust我不喜欢用这个手动过程来演示内核,我更喜欢直接从模糊的OpenCV定义中派生内核。你称之为手动吗?@YvesDaoust我用“手动”一词来描述数学方法,而没有任何与OpenCV库的连接,以及指令
cv2.GaussianBlur()
中的结果图像。这是否回答了你的问题?
import cv2
import numpy as np
import skimage.exposure as exposure

# create delta image
dims = 30
dims2 = 30 // 2
delta = np.zeros((dims,dims,3), dtype=np.float32)
delta[dims2:dims2+1, dims2:dims2+1] = (255,255,255)

# blur image
blur = cv2.GaussianBlur(delta, (0,0), sigmaX=5, sigmaY=5)

# resize 16x
dims4x = dims * 16
resized = cv2.resize(blur, (dims4x,dims4x), interpolation = cv2.INTER_AREA)

# stretch to full dynamic range
result = exposure.rescale_intensity(resized, in_range='image', out_range=(0,255)).astype(np.uint8)

# save image
cv2.imwrite('delta.png',delta)
cv2.imwrite('gaussian_blur_view.png',result)

# show the images
cv2.imshow("delta", delta)
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()