#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. 手机短号(hdu2081)

    这里字符串的输入用gets_s()函数. #include<stdio.h> using namespace std; int main() { int N; scanf_s(" ...

  2. 100道MySQL数据库经典面试题解析(收藏版)

    前言 100道MySQL数据库经典面试题解析,已经上传github啦 https://github.com/whx123/JavaHome/tree/master/Java面试题集结号 公众号:捡田螺 ...

  3. Java 8 中如何优雅的处理集合

    Java 8 中如何优雅的处理集合(Stream API) 在Java中,集合和数组是我们经常会用到的数据结构,需要经常对他们做增.删.改.查.聚合.统计.过滤等操作.相比之下,关系型数据库中也同样有 ...

  4. Altera的Cyclone系列器件命名规则

    Altera的Cyclone系列器件命名规则如下 器件系列 + 器件类型(是否含有高速串行收发器) +  LE逻辑单元数量 + 封装类型 + 高速串行收发器的数量(没有则不写) + 引脚数目 + 器件 ...

  5. Docker虚拟机配置手札(centos)

    一.Docker只支持CentOS7及以上系统,不支持6.x系统 二.yum安装Docker 1.安装相关环境和设置仓库 yum install -y yum-utils device-mapper- ...

  6. MySQL知识-MySQL不同版本多实例

    一.不同版本多实例   0.软连接不同版本软件,修改环境变量 [root@db01 database]# ln -s mysql-5.6.46-linux-glibc2.12-x86_64 mysql ...

  7. python - 怎样使用 requests 模块发送http请求

    最近在学python自动化,怎样用python发起一个http请求呢? 通过了解 request 模块可以帮助我们发起http请求 步骤: 1.首先import 下 request 模块 2.然后看请 ...

  8. NIO 的非阻塞式网络通信

    1.阻塞与非阻塞   ①  传统的 IO 流都是阻塞式的.也就是说,当一个线程调用 read() 或 write()时, 该线程被阻塞,直到有一些数据被读取或写入,该线程在此期间不能执行其他任务. 因 ...

  9. 【JVM】关于OOM的二三事

    组织架构 严格来说,StackOverflowError和OutOfMemoryError都属于错误,而不是异常. java.lang.StackOverflowError public class ...

  10. 【Spring】JdbcTemplate的使用,查询,增、删、改

    数据库名:taobaodb 配置文件: JdbcTemplate主要提供以下五类方法: execute方法:可以用于执行任何SQL语句,一般用于执行DDL语句: update方法及batchUpdat ...