網(wǎng)站首頁 編程語言 正文
Harris 角點(diǎn)檢測算法
1. 角點(diǎn)
角點(diǎn)是水平方向、垂直方向變化都很大的像素。
角點(diǎn)檢測算法的基本思想:?
? ? ? ? 使用一個(gè)固定窗口在圖像上進(jìn)行任意方向上的滑動,比較滑動前與滑動后兩種情況,窗口中的像素灰度變化程度,如果存在任意方向上的滑動,都有著較大灰度變化,那么我們可以認(rèn)為該窗口中存在角點(diǎn)。
? ? ? ? 目前,角點(diǎn)檢測算法還不是十分完善,許多算法需要依賴大量的訓(xùn)練集和冗余數(shù)據(jù)來防止和減少錯(cuò)誤的特征的出現(xiàn)。對于角點(diǎn)檢測算法的重要評價(jià)標(biāo)準(zhǔn)是:其對多幅圖像中相同或者相似特征的檢測能力,并且能夠應(yīng)對光照變化、或者圖像旋轉(zhuǎn)等影響。
關(guān)于角點(diǎn)的具體描述可以有幾種:
- 一階導(dǎo)數(shù)(即灰度的梯度)的局部最大所對應(yīng)的像素點(diǎn);
- 兩條及兩條以上邊緣的交點(diǎn);
- 圖像中梯度值和梯度方向的變化速率都很高的點(diǎn);?
- 角點(diǎn)處的一階導(dǎo)數(shù)最大,二階導(dǎo)數(shù)為零,指示物體邊緣變化不連續(xù)的方向。 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
三類角點(diǎn)檢測算法:
- 基于二值圖像的角點(diǎn)檢測;
- 基于輪廓曲線的角點(diǎn)檢測;
- 基于灰度圖像的角點(diǎn)檢測:基于梯度、基于模板和基于模板和梯度組合三類方法;常見的基于模板的角點(diǎn)檢測算法有:Kitchen-Rosenfeld角點(diǎn)檢測算法,Harris角點(diǎn)檢測算法,KLT角點(diǎn)檢測算法及SUSAN角點(diǎn)檢測算法?;谀0宓姆椒ㄖ饕强紤]像素領(lǐng)域點(diǎn)灰度的變化,即亮度的變化。
2. 流程
(1)找出角點(diǎn)
用高斯算子求出像素水平方向和垂直方向的梯度dx, dy,–> 對梯度的平方dxdx ,dydy, dxdy濾波得到Wxx ,Wxy,Wyy --> 在求的(WxxWyy - Wxy**2)/(Wxx + Wyy)作為候選角點(diǎn)。
(2)篩選角點(diǎn)
根據(jù)閾值篩選角點(diǎn)–> 取得角點(diǎn)的坐標(biāo) -->根據(jù)角點(diǎn)坐標(biāo)得到角點(diǎn)所在的行 --> 在角點(diǎn)周圍,刪除掉其他角點(diǎn)。–> result
(3)標(biāo)記角點(diǎn)
3. 實(shí)現(xiàn)
from PIL import Image import numpy as np import matplotlib.pyplot as plt from scipy.ndimage import filters ## 1.找出角點(diǎn) ### 1.1 步驟:img求導(dǎo) --> imx ,imy 濾波-->Wxx ,Wxy,Wyy --> (Wxx*Wyy - Wxy**2)/(Wxx + Wyy) def compute_harris_response(img,sigma=3): ? ? # 求梯度 ? ? imgx,imgy ?= np.zeros(img.shape),np.zeros(img.shape) ? ? filters.gaussian_filter(img,(sigma,sigma),(0,1),imgx) ? ? filters.gaussian_filter(img,(sigma,sigma),(1,0),imgy) # [260,263] ? ? # 對梯度進(jìn)行高斯濾波 ? ? wxx = filters.gaussian_filter(imgx**2,sigma) ? ? wyy = filters.gaussian_filter(imgy**2,sigma) # [260,263] ? ? wxy = filters.gaussian_filter(imgx*imgy,sigma)# [260,263] ? ? ## 求行列式和跡 ? ? wdet = wxx*wyy -wxy**2 ? ? wtr = wxx + wyy ? ? return ?wdet/wtr ## 2 篩選角點(diǎn) ### 2.1 步驟:根據(jù)閾值篩選角點(diǎn)--> 取得角點(diǎn)的坐標(biāo) -->根據(jù)角點(diǎn)坐標(biāo)得到角點(diǎn)所在的行 ?--> # --> 在角點(diǎn)周圍,刪除掉其他角點(diǎn) def get_harris_points(harri,min_dist=4,threshold=0.1): ? ? corner_thre = harri.max()*threshold ?# 角點(diǎn)閾值 ? ? mask = (harri > corner_thre)*1 ?# 取出大于閾值的點(diǎn)為候選角點(diǎn) ? ? cords = np.array(mask.nonzero()).T ?# 取候選角點(diǎn)的坐標(biāo) ? ? values = [harri[i[0],i[1]] for i in cords] ?# 候選角點(diǎn)的值 ? ? cls = np.argsort(values) ? ? # 對角點(diǎn)排序得到排序后的序列號,序列號也是候選角點(diǎn)所在的行 ? ? loc = np.zeros(harri.shape) ? # 劃出可行性區(qū)域 ? ? loc[min_dist:-min_dist,min_dist:-min_dist] = 1 ? ? re_cords = [] ? ? for i in cls: ?# 篩選角點(diǎn)。先取出角點(diǎn),角點(diǎn)周圍的點(diǎn)不再取出 ? ? ? ? if loc[cords[i,0],cords[i,1]] == 1 : ? ? ? ? ? ? re_cords.append(cords[i]) ? ? ? ? ? ? loc[cords[i,0]-min_dist:cords[i,0]+min_dist,cords[i,1]-min_dist:cords[i,1]+min_dist]=0 ? ? return re_cords def plot_harri(img,cords): ? ? plt.figure() ? ? plt.gray() ? ? plt.imshow(img) ? ? plt.plot([i[1] for i in cords],[i[0] for i in cords],'.') ? ? plt.axis('off') ? ? plt.show() ## 3 測試 if __name__ == '__main__': ? ? img = np.array(Image.open('luna.png').convert('L')) ? ? harri = compute_harris_response(img) ? ? re_cords = get_harris_points(harri) ? ? plot_harri(img,re_cords)
原文鏈接:https://blog.csdn.net/qq_35732321/article/details/123717928
相關(guān)推薦
- 2022-08-04 Python?threading和Thread模塊及線程的實(shí)現(xiàn)_python
- 2023-04-06 Python中有哪些關(guān)鍵字及關(guān)鍵字的用法_python
- 2022-09-10 Python學(xué)習(xí)筆記嵌套循環(huán)詳解_python
- 2023-01-02 Kotlin?RadioGroup與ViewPager實(shí)現(xiàn)底層分頁按鈕方法_Android
- 2022-10-17 多階段構(gòu)建優(yōu)化Go?程序Docker鏡像_Golang
- 2022-07-04 PyCharm如何配置SSH和SFTP連接遠(yuǎn)程服務(wù)器_python
- 2021-12-15 由于redis服務(wù)器cpu100%的問題導(dǎo)致網(wǎng)站宕機(jī)訪問大量出現(xiàn)504gateway time-ou
- 2022-10-25 如何利用Python和matplotlib更改縱橫坐標(biāo)刻度顏色_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支