Simplified hog computing

Source: Internet
Author: User

Hog has been using it for a long time. Today I tried to write

Most of the functions used are MATLAB toolbox functions.

Where is the gradient histogram difference not written?

The code shows a method for finally displaying a vector graph.

If the program compilation is incorrect, please correct it.

The first is the main program:

clc;clear;image = imread('crop001019.png');figure;imshow(image);image = double(image);image = imresize(image,[128 64]);block = zeros(16,16);cell = 8;block = 16;for i = 0:1:14    for j = 0:1:6        for n = 1:1:16            for k = 1:1:16                block(n,k) = image(i*8+n,j*8+k);            end        end        feature = hist(block);        for e = 1:1:2            for t = 1:1:2                result(i*2+e,j*2+t,:) = feature(e,t,:);            end        end    endendw = result;bs = 8;bim1 = zeros(bs, bs);bim1(:,round(bs/2):round(bs/2)+1) = 1;bim = zeros([size(bim1) 9]);bim(:,:,1) = bim1;for i = 2:9,  bim(:,:,i) = imrotate(bim1, -(i-1)*20, 'crop');ends = size(w);    w(w < 0) = 0;    im = zeros(bs*s(1), bs*s(2));for i = 1:s(1),  iis = (i-1)*bs+1:i*bs;  for j = 1:s(2),    jjs = (j-1)*bs+1:j*bs; %     k = find(w(i,j,:)==max(w(i,j,:)));%     if length(k)>1%         k = k(1);%     end    for k=1:1:9        im(iis,jjs) = im(iis,jjs) + bim(:,:,k) * w(i,j,k);    end  endendscale = max(w(:));im = uint8(im * (255/scale));% im = uint8(im);figure;imshow(im);

The hist is used to calculate the gradient histogram of each block.

Returns a 2*2*9 matrix.

The Code is as follows:

function feature = hist(block)block = block;feature = zeros(2,2,9);for i = 0:1:1    for j = 0:1:1        for k = 1:1:8            for n = 1:1:8                cell(k,n) = block(i*8+k,j*8+n);            end        end        hx = [-1,0,1];        hy = -hx';        Fx = imfilter(double(cell),hx);        Fy = imfilter(double(cell),hy);        Q = atan2(Fy,Fx);        Q = abs(Q);        Q = Q.*180./pi;        Q = round(Q);        for u = 1:1:64            if Q(u)>=0&Q(u)<20 feature(i+1,6) = feature(i+1,6) + 1; end            if Q(u)>=20&Q(u)<40 feature(i+1,5) = feature(i+1,5) + 1; end            if Q(u)>=40&Q(u)<60 feature(i+1,4) = feature(i+1,4) + 1; end            if Q(u)>=60&Q(u)<80 feature(i+1,3) = feature(i+1,3) + 1; end            if Q(u)>=80&Q(u)<100 feature(i+1,2) = feature(i+1,2) + 1; end            if Q(u)>=100&Q(u)<120 feature(i+1,1) = feature(i+1,1) + 1; end            if Q(u)>=120&Q(u)<140 feature(i+1,9) = feature(i+1,9) + 1; end            if Q(u)>=140&Q(u)<160 feature(i+1,8) = feature(i+1,8) + 1; end            if Q(u)>=160&Q(u)<=180 feature(i+1,7) = feature(i+1,7) + 1; end        end    endendfeature = feature./64;

There is something that can be optimized or wrong, please point it out.

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.