Coder Social home page Coder Social logo

ycc789741ycc / hog-bgr-with-visualization Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 2.39 MB

HOG feature descriptor, the kind of feature transform before we put our image into SVM. This repository also provides hog visualization both before and after doing block normalization.

License: Other

Python 100.00%
opencv numpy computer-vision hog-features hog-features-extraction python

hog-bgr-with-visualization's Introduction

HOG-BGR-with-visualization

HOG feature descriptor, a kind of feature transform before we put our image into SVM or NN.

In this API, I split hog feature into BGR channel respectively, it's a little different from hog in skimage, but this API still support grayscale image.
This API divides orients of gradient into 9 bins and each bin represent 0 20 40 60 ... 160.

Furthermore, due to hog's performance has some relationship with tuning parameters, so this repository provides hog visualization both before and after doing block normalization.

Environment

Python>=3.9.1
numpy>=1.20.0
opencv-python>=4.5.1.48

Installation

pip install hogBGR  

Demo

Original Picture
Cover

import cv2
from hogBGR import HOG
from hogBGR import HOGvisualized
from hogBGR import util

HOG

Let's create a 16x16 (pixels) cell, 2x2 (cells) block hog image.

img = cv2.imread(r'hogBGR/example/rose.png')
cell_hogfeature = HOG.Cell_HOG(img,cell_size=(16,16))
hog = HOG.BlockNorm_HOG(cell_hogfeature,block_size=(2,2))

or

img = cv2.imread(r'hogBGR/example/rose.png')
hog = HOG.HOGfeature(img,cell_size=(16,16),block_size=(2,2),flatten=False)

Take a visualization

res = HOGvisualized.visualize_HOG(hog[:,:,:,0,0,:],15)
cv2.imshow("HOG feature with block normaliztion",res)

or

util.BlockNormaliztionHOG_Show(img,one_cell=True)

Below shows hog image in each cell of blocks. (First method would only show first cell of blocks)

Cover

HOG without block normalization

Let's create a 16x16 (pixels) cell hog image.

img = cv2.imread(r'hogBGR/example/rose.png')
cell_hogfeature = HOG.Cell_HOG(img,cell_size=(16,16))

Take a visualization

res = HOGvisualized.visualize_HOG(cell_hogfeature,15)
cv2.imshow("part1 - HOG feature without block normaliztion",res)

or

util.NonBlockNormaliztionHOG_Show(img)

Below shows hog image before block normalization

Cover

Gray scale input image is also supported

Orginal Picture
Cover

Visualization
Cover

Simplified visualization

You can try the result with yourself if you want a faster visualization.

res = HOGvisualized.Fast_visualize_HOG(hogfeature,7)

hog-bgr-with-visualization's People

Contributors

ycc789741ycc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

don-charlie-pc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.