A list,

This topic is a leaf recognition system based on HU invariant moment in MATLAB. By calculating the geometric features of various leaves, determine what kind of leaves they belong to.

Geometric moments were proposed by Hu(Visual Pattern Recognition by Moment Invariants) in 1962 and have invariance of translation, rotation and scale.





These seven invariants form a set of eigenquantities, and Hu.M. K. proved in 1962 that they have invariance of rotation, scaling and translation.

In fact, in the process of the recognition of objects in the image, only and invariance is better, several other invariant moment of error is large, some scholars believe that only based on the second-order moment invariant moment descriptions of a two-dimensional object is the true with rotation, scaling and translation invariance (and just are composed of second order moment). But I didn’t prove it was true.

The feature quantity composed of Hu moment for image recognition has the advantage of fast speed, but the disadvantage is the low recognition rate. I have done gesture recognition, for the segmented gesture contour map, the recognition rate is about 30%, for the pictures with rich texture, the recognition rate is even worse, only about 10%. This is partly due to the fact that Hu moment invariants only use low-order moments (at most, third-order moments), so details of the image cannot be well described, leading to incomplete description of the image.

Hu invariants are generally used to identify large objects in the image, and the shape of the object is well described. The texture features of the image should not be too complex, such as the shape of fruit, or the recognition effect of simple characters in the license plate will be relatively better.

The definition is as follows:

① The definition of (P + Q) order invariant moment:

② For digital images, discretization is defined as:

(3) The definition of normalized central moment:

(4) the Hu moment definition

Ii. Source code

close all
clear all
clc
tic
f=imread('test.tif'); % read test graph A=double(f); % convert gray value to double precision g=mat2gray(A); % gray value normalization0to1K = between im2bw (g,0.4); % binarization, threshold0.4
 imshow(k);
k=1-k; % inversion se = strel ('disk'.6); fc=imclose(k,se); % closed operation fc=imfill(fc,'hole'); % to fill hole figure, imshow (fc); se=strel('disk'.8); fco=imopen(fc,se); Figure,imshow(FCO); BW=fco; trainset=train(); trainset2=train2(); % imshow(f,[]); [L,num] = bwlabel(BW); % markupfor t=1:num [r c]=find(L==t); r1=min(r); c1=min(c); r2=max(r); c2=max(c); IM{t}=BW(r1:r2,c1:c2); % figure; imshow(BW(r1:r2,c1:c2)) phi=invmoments(IM{t}); Pset{t}=phi; d(t)=norm(abs(log(Pset{t}(1:7-)))abs(log(trainset(1:7)))); % match with the training sample d2(t)=norm(abs(log(Pset{t}(1:7-)))abs(log(trainset2(1:7))));
  
 
end
function [trainset]= train( )
%TRAIN Summary of this function goes here
%   Detailed explanation goes here

     f= imread('train_1.tif');
 A=double(f);
g=mat2gray(A);
k=im2bw(g,0.4);

k=1-k;
se=strel('disk'.6);
fc=imclose(k,se);
fc=imfill(fc,'hole');

se=strel('disk'.15);
fco=imopen(fc,se);
%BW=im2bw(I,0.001);
%BW=imfill(BW,'hole'); 
%SE=strel('disk'.10); %BW=imopen(BW,SE); % figure; imshow(BW); BW=fco; [r c]=find(BW==1);
    r1=min(r);
    c1=min(c);
    r2=max(r);
    c2=max(c);
    function phi = invmoments(F)
%INVMOMENTS Compute invariant moments of image.
%   PHI = INVMOMENTS(F) computes the moment invariants of the image
%   F. PHI is a seven-element row vector containing the moment
%   invariants as defined in equations (11.3- 17) through (11.3- 23) of
%   Gonzalez and Woods, Digital Image Processing, 2nd Ed.
%
%   F must be a 2-D, real, nonsparse, numeric or logical matrix.

%   Copyright 2002- 2004. R. C. Gonzalez, R. E. Woods, & S. L. Eddins
%   Digital Image Processing Using MATLAB, Prentice-Hall, 2004
%   $Revision: 1.5 $  $Date: 2003/11/21 14:39:19 $

if (ndims(F) ~= 2) | issparse(F) | ~isreal(F) | ~(isnumeric(F) | ...
                                                    islogical(F))
   error(['F must be a 2-D, real, nonsparse, numeric or logical '.'matrix.']); 
end

F = double(F);

phi = compute_phi(compute_eta(compute_m(F)));
  
%-------------------------------------------------------------------%
function m = compute_m(F)

[M, N] = size(F);
[x, y] = meshgrid(1:N, 1:M);
  
% Turn x, y, and F into column vectors to make the summations a bit
% easier to compute in the following.
x = x(:);
y = y(:);
F = F(:);
  
% DIP equation (11.3- 12)
m.m00 = sum(F);
% Protect against divide-by-zero warnings.
if (m.m00 == 0)
   m.m00 = eps;
end
Copy the code

3. Operation results

Fourth, note

Version: 2014 a