Harris Algorithm Python implementation

Source: Internet
Author: User

Harris is most commonly used as a feature detection algorithm.

First file harris.py

<pre name= "code" class= "python" >from scipy.ndimage import filtersfrom numpy import *from pylab import *def Compute_h Arris_response (im,sigma=3): Imx=zeros (Im.shape) #计算导数 filters.gaussian_filter (IM, (SIGMA,SIGMA), (0,1), IMX) Imy=zero S (im.shape) Filters.gaussian_filter (IM, (Sigma,sigma), (1,0), Imy) Wxx=filters.gaussian_filter (imx*imx,sigma) #计算har RIS matrix component Wxy=filters.gaussian_filter (IMX*IMY,SIGMA) wyy=filters.gaussian_filter (imy*imy,sigma) Wdet=Wxx*Wyy-Wxy **2 #计算矩阵的特征值和迹 wtr=wxx+wyy return wdet/wtrdef get_harris_points (harrisim,min_dist=10,threshold=0.1): Conner_ Threshold=harrisim.max () *threshold harrisim_t= (harrisim>conner_threshold) * Coords=array (Harrisim_t.nonzero () ). T Candidate_values=[harrisim[c[0],c[1]] for C in coords] Index=argsort (candidate_values) Allowed_locations=zeros (        Harrisim.shape) Allowed_locations[min_dist:-min_dist,min_dist:-min_dist]=1 filtered_coords=[] for i in index: If allowed_locationS[coords[i,0],coords[i,1]]==1:filtered_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# here to ensure min_dist*min_ Dist only has a Harris feature point return filtered_coordsdef plot_harris_points (image,filtered_coords): Figure () Gray () imshow (image) plot ([p[1] for P in Filtered_coords],[p[0]for p in filtered_coords], ' + ') axis (' Off ') show ()

A second file test algorithm

From PIL import imagefrom numpy import *import harrisfrom pylab import *from scipy.ndimage import Filtersim=array (image.op En (' 33.jpg '). Convert (' L ')) Harrisim=harris.compute_harris_response (IM) filtered_coords=harris.get_harris_points ( Harrisim) harris.plot_harris_points (im,filtered_coords)



Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Harris Algorithm Python implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.