sobel

OpenCV-Python 图像梯度 | 十八

落爺英雄遲暮 提交于 2019-12-22 02:56:25
目标 在本章中,我们将学习: 查找图像梯度,边缘等 我们将看到以下函数: cv.Sobel (), cv.Scharr (), cv.Laplacian ()等 理论 OpenCV提供三种类型的梯度滤波器或高通滤波器,即Sobel,Scharr和Laplacian。我们将看到他们每一种。 1. Sobel 和 Scharr 算子 Sobel算子是高斯平滑加微分运算的联合运算,因此它更抗噪声。逆可以指定要采用的导数方向,垂直或水平(分别通过参数yorder和xorder)。逆还可以通过参数ksize指定内核的大小。如果 ksize = -1 ,则使用3x3 Scharr滤波器,比3x3 Sobel滤波器具有更好的结果。请参阅文档以了解所使用的内核。 2. Laplacian 算子 它计算了由关系$Delta src = frac{partial ^2{src}}{partial x^2} frac{partial ^2{src}}{partial y^2}$给出的图像的拉普拉斯图,它是每一阶导数通过Sobel算子计算。如果 ksize = 1 ,然后使用以下内核用于过滤: $$kernel = begin{bmatrix} 0 & 1 & 0 \ 1 & -4 & 1 \ 0 & 1 & 0 end{bmatrix}$$ 代码 下面的代码显示了单个图表中的所有算子。所有内核都是

Matlab: First derivative edge detection, about gradients

折月煮酒 提交于 2019-12-20 04:20:58
问题 I'm writing a program that asks the user to choose between Prewitt and Sobel image filters to detect edges of objects of an image. I must use their filter templates, not the edge function. The user also tells if he wants to detect 'horizontal', 'vertical' or 'diagonal' edges. My problem is theoretical rather than about programming. In my notes i've got that to compute the magnitude of the gradient at each pixel, it is often approximated as sqrt(Gx^2 + Gy^2) where Gx would be the vertical

图像边缘检测的Sobel和Laplace算子的Python实现(附完整代码)

北城以北 提交于 2019-12-19 03:10:31
1.概述 计算机视觉课程要求实现一下图像边缘检测算法,但并没有明确要求实现哪种具体的算法,在网上看了相关图像边缘检测算子,都有非常具体的介绍,也有实现代码或者Python集成库里的代码,有的算子比较简单,很容易理解,例如Sobel、Laplace等,Sobel还有一系列延伸的算子,很相似,这些都还是比较简单的,还有一些稍微复杂点的算子,例如Canny,具体关于这些算法原理的介绍推荐去看 深入学习OpenCV中几种图像边缘检测算子 这篇文章,写的非常棒。看了一些博主写的代码,写的非常好,但是跟我想象中所要求的还是有一些出入,所以我在这个代码的基础上进行了一些修改。本次作业我选择了实现Sobel和Laplace两个比较简单的算法,这里作个记录。 2.Sobel和Laplace简单介绍和实现 2.1 Sobel算子 Sobel算子包括横向和纵向两种模板,把横向模板记为 G x Gx G x ,把纵向模板记为 G y Gy G y ,其中: 在计算时,首先需要将图像转成灰度图,直接用下面的方法即可,参数 0 0 0 代表读取灰度图。 gray_saber = c v2 . imread ( "C:/Users/ALIENWARE/Pictures/Camera Roll/mcqueen.jpg" , 0 ) 然后只需要将上述模板看成一个“元素矩阵”或者“基本矩阵”

Sobel filter implementation in scipy

家住魔仙堡 提交于 2019-12-14 03:58:31
问题 I tried to implement the Sobel_X filter in scipy with convolve2d function. I compared with the results from this function: from scipy.signal import convolve2d from scipy import misc from skimage.exposure import rescale_intensity import cv2 import numpy as np #https://www.pyimagesearch.com/2016/07/25/convolutions-with-opencv-and-python/ def convolve(image, kernel): # grab the spatial dimensions of the image, along with # the spatial dimensions of the kernel (iH, iW) = image.shape[:2] (kH, kW)

信用卡数字识别

一世执手 提交于 2019-12-14 01:51:17
转载:python我的最爱 原文地址:https://www.cnblogs.com/my-love-is-python/p/10409913.html 感谢作者! 机器学习进阶-项目实战-信用卡数字识别 1.cv2.findContour(找出轮廓) 2.cv2.boudingRect(轮廓外接矩阵位置) 3.cv2.threshold(图片二值化操作) 4.cv2.MORPH_TOPHAT(礼帽运算突出线条) 5.cv2.MORPH_CLOSE(闭运算图片内部膨胀) 6. cv2.resize(改变图像大小) 7.cv2.putText(在图片上放上文本) 7. cv2.putText(img, text, loc, text_font, font_scale, color, linestick) # 参数说明:img表示输入图片,text表示需要填写的文本str格式,loc表示文本在图中的位置,font_size可以使用cv2.FONT_HERSHEY_SIMPLEX, font_scale表示文本的规格,color表示文本颜色,linestick表示线条大小 信用卡数字识别: 信用卡 数字模板 涉及到的内容:主要是采用模板匹配的思想 思路: 第一部分:数字模板提取数字 第一步:读入图片 第二步:进行灰度化和二值化处理,这里的二值化使用的cv2.THRESH_BINARY

Reading an image into an array?

▼魔方 西西 提交于 2019-12-13 20:11:41
问题 I'm attempting to write a program that utilizes the sobel filter to detect edges in images. So first off, I've written down some of the requirements in some basic code, such as the x and y direction filters as arrays and also an attempt to read in a pgm image: program edges implicit none integer, dimension(:,:), allocatable :: inp, outim, GX, GY integer, parameter :: dp = selected_real_kind(15,300) integer :: ky, kx, x, y, out_unit = 10, M, N, sx, sy, i, j real(kind=dp) :: G M = 5 N = 5

My Sobel Edge Detection Operator Output is weird

喜你入骨 提交于 2019-12-11 14:48:24
问题 My output of Sobel edge detection operator is weird. Here's my code : BufferedImage temp = img; float kernelx[][] = {{-1, 0, 1},{-2, 0, 2},{-1, 0, 1}}; float kernely[][] = {{-1, -2, -1},{0, 0, 0},{1, 2, 1}}; float valx = 0; float valy = 0; float val = 0; for(int i=1;i<width-2;i++) { for(int j=1;j<height-2;j++) { valx = (kernelx[0][0]*new Color(img.getRGB(i-1, j-1)).getRed()) + (kernelx[0][2]*new Color(img.getRGB(i+1, j-1)).getRed()) + (kernelx[1][0]*new Color(img.getRGB(i-1, j)).getRed()) +

初识OpenCV-Python - 009: 图像梯度

落爺英雄遲暮 提交于 2019-12-10 12:03:38
本节学习找到图像的梯度和边界。只要用到的函数为: cv2.Sobel(), cv2.Scharr(), cv2.Laplacian() 1. Laplacian 和 Sobel的对比 import cv2from matplotlib import pyplot as pltimg = cv2.imread('dave.png',0)#Laplcatician 导数计算图像的拉普拉斯变换,其中每个导数都使用Sobel导数laplacian = cv2.Laplacian(img,cv2.CV_64F)/**sobel 是高斯平滑加微分的联合运算,对噪声有较强的抵抗能力。可以指定倒数方向(垂直和水平)。如果ksize=-1, 则是3*3的Scharr滤波器,其结果优于3*3的sobel滤波器。**/sobelx = cv2.Sobel(img, cv2.CV_64F, 1,0, ksize=5) #5*5的ksizesobely = cv2.Sobel(img, cv2.CV_64F, 0,1, ksize=5)plt.subplot(2,2,1), plt.imshow(img,cmap='gray')plt.title('Original'), plt.xticks([]), plt.yticks([])plt.subplot(2,2,2), plt.imshow

Python-OpenCV中的filter2D()函数

独自空忆成欢 提交于 2019-12-08 21:28:32
原文转自:https://www.cnblogs.com/lfri/p/10599420.html Python-OpenCV中的filter2D()函数 使用自定义内核对图像进行卷积。该功能将任意线性滤波器应用于图像。支持就地操作。当光圈部分位于图像外部时,该功能会根据指定的边框模式插入异常像素值。 语法 函数原型: dst=cv.filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]) 参数: 参数 描述 src 原图像 dst 目标图像,与原图像尺寸和通过数相同 ddepth 目标图像的所需深度 kernel 卷积核(或相当于相关核),单通道浮点矩阵;如果要将不同的内核应用于不同的通道,请使用拆分将图像拆分为单独的颜色平面,然后单独处理它们。 anchor 内核的锚点,指示内核中过滤点的相对位置;锚应位于内核中;默认值(-1,-1)表示锚位于内核中心。 detal 在将它们存储在dst中之前,将可选值添加到已过滤的像素中。类似于偏置。 borderType 像素外推法,参见BorderTypes 该函数实际计算的是相关性,而不是卷积 dst ( x , y ) = ∑ 0 ≤ y ′ < kernel.rows 0 ≤ x ′ < kernel.cols , kernel ( x ′ , y ′

Squaring introduces a lot of noise when doing Sobel operator using filter2D (OpenCV)

我怕爱的太早我们不能终老 提交于 2019-12-08 07:51:11
问题 I am trying to manually implement a sobel operator. For some reason, the horizontal and vertical components of the operator seem to have good results, but the combined image has a lot of noise. I notice when I do something like (imgv**2)**0.5, that also introduces a ton of noise, even though ideally, I should get approximately the same image back. Does anyone know what's going on here? Am I supposed to combine the images a different way? Here is my code in python: import cv2 import numpy as