#coding=utf-8
from PIL import Image
import numpy as np
from scipy.ndimage import filters
import matplotlib.pyplot as plt
import scipy.signal def mean_filter2d(arr):
n = 3
# 3*3 滤波器, 每个系数都是 1/9
w = np.ones((n, n)) / n ** 2
# 使用滤波器卷积图像
# mode = same 表示输出尺寸等于输入尺寸
# boundary 表示采用对称边界条件处理图像边缘
s = scipy.signal.convolve2d(arr, w, mode='same', boundary='symm')
return s def harris_response1(im,sigma=1.1):
"""计算图像的harris响应函数"""
#计算导数
imx = np.zeros(im.shape)
imx = scipy.ndimage.sobel(im,axis=0,mode='reflect')
# imx = filters.gaussian_filter(im,(sigma,sigma),(0,1),imx)
imy = np.zeros(im.shape)
imy = scipy.ndimage.sobel(im,axis=1,mode='reflect')
# imy = filters.gaussian_filter(im, (sigma, sigma), (1, 0), imy)
fig, ax = plt.subplots(1,2)
ax[0].imshow(imx, cmap='gray')
ax[1].imshow(imy, cmap='gray')
plt.show()
#计算Harris的各个分量
wxx = filters.gaussian_filter(imx*imx,sigma)
wxy = filters.gaussian_filter(imx*imy,sigma)
wyy = filters.gaussian_filter(imy*imy,sigma)
#计算像素的角点响应函数
# return (wxx*wyy - 2*wxy)/(wxx + wyy)
return wxx*wyy - wxy*wxy - 0.04*((wxx + wyy)**2) def harris_response2(im,sigma=1.1):
"""计算图像的harris响应函数"""
#计算导数
imx = np.zeros(im.shape)
imx = scipy.ndimage.sobel(im,axis=0,mode='reflect')
# imx = filters.gaussian_filter(im,(sigma,sigma),(0,1),imx)
imy = np.zeros(im.shape)
imy = scipy.ndimage.sobel(im,axis=1,mode='reflect')
# imy = filters.gaussian_filter(im, (sigma, sigma), (1, 0), imy)
fig, ax = plt.subplots(1,2)
ax[0].imshow(imx, cmap='gray')
ax[1].imshow(imy, cmap='gray')
plt.show()
#计算Harris的各个分量
wxx = mean_filter2d(imx*imx)
wxy = mean_filter2d(imx*imy)
wyy = mean_filter2d(imy*imy)
#计算像素的角点响应函数
return wxx*wyy - wxy*wxy - 0.04*((wxx + wyy)**2) def get_harris_points(harrism,min_dist = 10,thresold = 0.1):
"""从一幅Harrisim响应中返回角点,min_dist为分割角点和图像边界的最少像素数目"""
corner_thsold = harrism.max()*thresold
harrism_t = (harrism > corner_thsold) * 1
#得到候选点的坐标
coords = np.array(harrism_t.nonzero()).T#返回非零值的坐标的矩阵
#他们的Harris响应值
candidate_values = [harrism[c[0],c[1]] for c in coords]
#对候选点进行harris响应值进行排序
index = np.argsort(candidate_values)[::-1]#将x中的元素从小到大排列,提取其对应的index(索引),然后输出到y
#将可行点的位置保存在数组里
allowed_locations = np.zeros(harrism.shape)
allowed_locations[min_dist:-min_dist,min_dist:-min_dist] = 1
#按照min_distance原则,选择最佳harris点
filters_coords = []
for i in index:
if allowed_locations[coords[i,0],coords[i,1]] == 1:
filters_coords.append(coords[i])
allowed_locations[(coords[i,0]-min_dist):(coords[i,0]+min_dist),(coords[i,1]-min_dist):coords[i,1]+min_dist] = 0
return filters_coords im = np.array(Image.open(r'D:\cvImageSamples\lena.png'),dtype=np.float32) hr1 = harris_response1(im[:,:,0])
hr2 = harris_response2(im[:,:,0])
fig, ax = plt.subplots(1,3)
ax[0].imshow(im[:,:,0],cmap='gray')
ax[1].imshow(hr1, cmap='gray')
ax[2].imshow(hr2, cmap='gray')
plt.show()

临时起意写的文章,没有写成md格式。只好截图了。文字版本访问https://zhuanlan.zhihu.com/p/148127081

【论文阅读】Harris角点算法的更多相关文章

  1. Harris角点算法

    特征点检测广泛应用到目标匹配.目标跟踪.三维重建等应用中,在进行目标建模时会对图像进行目标特征的提取,常用的有颜色.角点.特征点.轮廓.纹理等特征.现在开始讲解常用的特征点检测,其中Harris角点检 ...

  2. 【论文阅读】分布一致性算法Paxos 《The Part-Time Parliament》

    论文原文.翻译稿.PPt:https://1drv.ms/u/s!Ak-jGl23kTuMimOZzV-MyLQUYmsN?e=DL1xHD

  3. OpenCV计算机视觉学习(13)——图像特征点检测(Harris角点检测,sift算法)

    如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice 前言 ...

  4. Harris角点

    1. 不同类型的角点 在现实世界中,角点对应于物体的拐角,道路的十字路口.丁字路口等.从图像分析的角度来定义角点可以有以下两种定义: 角点可以是两个边缘的角点: 角点是邻域内具有两个主方向的特征点: ...

  5. Harris角点(转载)

    1. 不同类型的角点 在现实世界中,角点对应于物体的拐角,道路的十字路口.丁字路口等.从图像分析的角度来定义角点可以有以下两种定义: 角点可以是两个边缘的角点: 角点是邻域内具有两个主方向的特征点: ...

  6. 论文阅读——Visual inertial odometry using coupled nonlinear optimization

    简介:论文提出一种新的视觉里程计算法,其直接利用带噪声的IMU数据和视觉特征位置来优化相机位姿.不同于对IMU和视觉数据运行分离的滤波器,这种算法将它们纳入联合的非线性优化框架中.视觉特征的透视重投影 ...

  7. harris角点检测的简要总结

    目录 1. 概述相关 2. 原理详解 1) 算法思想 2) 数学模型 3) 优化推导 3. 具体实现 1) 详细步骤 2) 最终实现 4. 参考文献 1. 概述相关 harris角点检测是一种特征提取 ...

  8. Harris角点检测算法优化

    Harris角点检测算法优化 一.综述 用 Harris 算法进行检测,有三点不足:(1 )该算法不具有尺度不变性:(2 )该算法提取的角点是像素级的:(3 )该算法检测时间不是很令人满意. 基于以上 ...

  9. 特征提取算法(4)——Harris角点提取

    1.角点 1.1 特征点与角点 特征点是计算机视觉算法的基础,使用特征点来代表图像的内容. 角点是一类重要的点特征,图像分析的角度来定义: 角点可以是两个边缘的角点: 角点是邻域内具有两个主方向的特征 ...

随机推荐

  1. asp.net MVC3.0 中@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction

    asp.net MVC3.0 中@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction 1.带有Render的方法返回值是v ...

  2. select 下拉模糊查询

    http://ivaynberg.github.io/select2/ https://github.com/ https://github.com/ivaynberg.github.io/selec ...

  3. PHP 操作结果集对象方法

    <?php header('Content-type:text/html;charset=utf-8'); //建立 或者 关闭mysql服务器 @符号用于屏蔽错误信息 $link=@mysql ...

  4. Java-LinkedList围圈的人名

    import java.util.*; public class Example12_7 { public static void main(String[] args) { int m=5; Lin ...

  5. 【转】团队项目的Git分支管理规范

    原文地址: http://blog.jboost.cn/git-branch.html 分支管理 创建项目时(一般是服务型项目,工具型或辅助型项目可以简单一些),会针对不同环境创建三个常设分支: de ...

  6. Python面向对象的特征跟私有属性

     面向对象的三大特征 继成.封装.多态: 继承:一个类可以继承一个或多个类,被继承的类叫做父类,继承的类叫做子类 封装:将数据和方法放在了一个类中就构成了封装 多态:指的一类事物有多重形态,一个抽象类 ...

  7. 剑指Offer之裴波那契数列

    题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0,第1项是1). n<=39 解法1:递归解法 public int Fibonacc ...

  8. Android_四大组件之ContentProvider

    一.概述 ContentProvider(内容提供者)管理对结构化数据集的访问,它们封装数据,并提供用于定义数据安全性的机制.其他应用,通过Context的ContentResolver对象 作为客户 ...

  9. Java的基本数据类型及其封装类

    Java的基本数据类型及其封装类 一.8种基本数据类型 二.基本数据类型的包装类及大小 三.基本数据类型和封装类的区别 定义不同.封装类是对象,基本数据类型不是: 使用方式不同.封装类需要先new初始 ...

  10. PriorityBlockingQueue 和 Executors.newCachedThreadPool()

    1.PriorityBlockingQueue里面存储的对象必须是实现Comparable接口. 2.队列通过这个接口的compare方法确定对象的优先级priority. 规则是:当前和其他对象比较 ...