Python implementation of the harris algorithm, harrispython

Source: Internet
Author: User

Python implementation of the harris algorithm, harrispython

Harris is the most common feature detection algorithm.

First file harris. py

<Pre name = "code" class = "python"> from scipy. ndimage import filtersfrom numpy import * from pylab import * def compute_harris_response (im, sigma = 3): imx = zeros (im. shape) # Calculate the derivative filters. gaussian_filter (im, (sigma, sigma), (0, 1), imx) imy = zeros (im. shape) filters. gaussian_filter (im, (sigma, sigma), (1, 0), imy) Wxx = filters. gaussian_filter (imx * imx, sigma) # Calculate the harris matrix component Wxy = filters. gaussian_filter (imx * imy, sigma) Wyy = filters. gaussian_filter (imy * imy, sigma) Wdet = Wxx * Wyy-Wxy ** 2 # Calculate the matrix feature value and trace 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) * 1 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 # ensure that min_dist * min_dist has only one harris feature point return filtered_coordsdef plot_harris_points, filtered_coords): figure () gray () imshow (image) plot ([p [1] for p in filtered_coords], [p [0] for p in filtered_coords], '+') axis ('off') show ()

Algorithm for testing the second file 

from PIL import Imagefrom numpy import *import harrisfrom pylab import *from scipy.ndimage import filtersim=array(Image.open('33.jpg').convert('L'))harrisim=harris.compute_harris_response(im)filtered_coords=harris.get_harris_points(harrisim)harris.plot_harris_points(im,filtered_coords)




How to Implement the DES algorithm using Python

Original. Write it yourself. DES security is not as high as other algorithms, and it should not be very complicated,
 
Implementation of prim algorithm or kruscal Algorithm in Python

Kruskal:
# Include "stdio. h"
# Include "stdlib. h"
# Include "iostream"
Using namespace std;
# Define MAXE 100 // MAXE is the maximum number of edges.
Struct edges
{
Int bv, TV, w; // edge set type. It stores the starting vertex bv, ending vertex TV, and weight w of an edge.
} Edges;
Typedef struct edges edgeset [MAXE];
// Find the connected set of v
Int seeks (int set [], int v)
{
Int I = v;
While (set [I]> 0)

I = set [I];
Return I;
}
Void kruskal (edgeset ge, int n, int e)
{
Int set [MAXE], v1, v2, I, j;
For (I = 1; I <= n; I ++)
Set [I] = 0;
I = 1; // I indicates the number of edges in the generated tree to be obtained. The initial value is 1.
J = 1; // j indicates the subscript in ge. The initial value is 1.
While (j <n & I <= e) // check whether the edge is added to the Spanning Tree by edge weight in ascending order.
{
V1 = seeks (set, ge [I]. bv); // determine the connected set of vertex v
V2 = seeks (set, ge [I]. TV );
Cout <ge [I]. bv <":" <v1 <"," <ge [I]. TV <":" <v2 <endl;
If (v1! = V2) // when v1 and v2 are not in the same vertex set, make sure that this edge should be selected into the Spanning Tree.
{
Cout <"(" <ge [I]. bv <"," <ge [I]. TV <")" <ge [I]. w <endl;
Set [v1] = v2;
J ++;
}
I ++;
}
}
Int main ()
{
Edgeset ee;
Int n, e; // n indicates the number of knots in the graph, and e indicates the number of edges in the graph.
N = 6;
E = 3;
For (int I = 1; I <= e; I ++)
{
Scanf_s ("% d", & ee [I]. bv );
Scanf_s ("% d", & ee [I]. TV );
Scanf_s ("% d", & ee [I]. w );
}
// The edge set graph represented by ee is arranged in ascending order of Weight Values.
Printf ("Minimum Spanning Tree edge set and its weight: \ n ");
Kruskal (ee, n, e );
System (... the remaining full text>

Related Article

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.