histograms and matching 主講人:虞台文. content overview basic histogram structure accessing...

49
Histograms and Matching 主主主 主主主

Upload: marcus-gerard-randall

Post on 17-Dec-2015

236 views

Category:

Documents


1 download

TRANSCRIPT

Histograms and Matching

主講人:虞台文

Content

Overview Basic Histogram Structure Accessing Histograms Basic Manipulations with Histograms Color Spaces Histogram Comparisons Back Projection

Histograms and Matching

Overview

Histograms

Histogram of an Image

Histogram for Skin Color

Applications

Object Detection Image Retrieval Gesture Recognition

Histograms and Matching

Basic Histogram Structure

CvHistogram Multidimensional Histograms

typedef struct CvHistogram{ int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; // for uniform histograms float** thresh2; // for nonuniform histograms CvMatND mat; // embedded matrix header

// for array histograms} CvHistogram;

typedef struct CvHistogram{ int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; // for uniform histograms float** thresh2; // for nonuniform histograms CvMatND mat; // embedded matrix header

// for array histograms} CvHistogram;

Create Histogram

CvHistogram* cvCreateHist( int dims, int* sizes, int type, float** ranges = NULL, int uniform = 1);

CvHistogram* cvCreateHist( int dims, int* sizes, int type, float** ranges = NULL, int uniform = 1);

Defer Set Ranges

Used when calling cvCreateHist with ranges = NULL.

Clear and Release Histogram

Histograms and Matching

Accessing Histograms

Access Bin Data

Direct Access of Bin Data

typedef struct CvHistogram{ int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; // for uniform histograms float** thresh2; // for nonuniform histograms CvMatND mat; // embedded matrix header

// for array histograms} CvHistogram;

typedef struct CvHistogram{ int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; // for uniform histograms float** thresh2; // for nonuniform histograms CvMatND mat; // embedded matrix header

// for array histograms} CvHistogram;

hist->mat.data.fl

Direct Access of Histogram Information

typedef struct CvHistogram{ int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; // for uniform histograms float** thresh2; // for nonuniform histograms CvMatND mat; // embedded matrix header

// for array histograms} CvHistogram;

typedef struct CvHistogram{ int type; CvArr* bins; float thresh[CV_MAX_DIM][2]; // for uniform histograms float** thresh2; // for nonuniform histograms CvMatND mat; // embedded matrix header

// for array histograms} CvHistogram;

Histograms and Matching

Basic Manipulations with Histograms

Calculate Histogram

void cvCalcHist( IplImage** image, CvHistogram* hist, int accumulate=0, const CvArr* mask=NULL);

void cvCalcHist( IplImage** image, CvHistogram* hist, int accumulate=0, const CvArr* mask=NULL);

More Operations

Example Graylevel Histogram

Example Graylevel Histogram

DownloadTest Program

DownloadTest Program

Graylevel Histogram

0

500

1000

1500

2000

2500

3000

0 20 40 60 80 100 120 140 160 180 200 220 240

Graylevel

Freq

ency

Histograms and Matching

Color Spaces

Color Spaces

RGB Color Space

HSV Color Space

YCbCr Color Space

YCbCr Color Space

Color Space Conversion

Article

Some Algorithms

Applet

OpenCV Color Space Conversion

void cvCvtColor(

const CvArr* src,

CvArr* dst,

int code

)

void cvCvtColor(

const CvArr* src,

CvArr* dst,

int code

)

Skin Color Detection by HSV and RGB

Automatic Face Detection

Histogram Usage Examples

Example Hue-Sat Histogram

Example Hue-Sat Histogram

0 5 10 15 20 25 0

9

18

27

0

2,000

4,000

6,000

8,000

10,000

12,000

14,000

16,000

Fre

q.

Satuation

Hue

DownloadTest Program

DownloadTest Program

Histograms and Matching

Histogram Comparisons

Histogram Comparisons in OpenCV

#define CV_COMP_CORREL 0#define CV_COMP_CHISQR 1#define CV_COMP_INTERSECT 2#define CV_COMP_BHATTACHARYYA 3

Histogram Comparisons in OpenCV

#define CV_COMP_CORREL 0#define CV_COMP_CHISQR 1#define CV_COMP_INTERSECT 2#define CV_COMP_BHATTACHARYYA 3

Correlation Method(CV_COMP_CORREL)

1 21 2 2 2

1 2

( ) ( )( , ) i

correl

i

H i H id H H

H H

1( ) ( ) ( )k k kN jH i H i H j

1 21 ( , ) 1correld H H

maximummismatch

perfectmatch

Histogram Comparisons in OpenCV

#define CV_COMP_CORREL 0#define CV_COMP_CHISQR 1#define CV_COMP_INTERSECT 2#define CV_COMP_BHATTACHARYYA 3

Chi-square Method(CV_COMP_CHISQR)

2

1 21 2

1 2

( ) ( )( , )

( ) ( )chi squarei

H i H id H H

H i H i

1 20 ( , )chi squared H H

badmismatch

perfectmatch

Histogram Comparisons in OpenCV

#define CV_COMP_CORREL 0#define CV_COMP_CHISQR 1#define CV_COMP_INTERSECT 2#define CV_COMP_BHATTACHARYYA 3

Intersection Method(CV_COMP_INTERSECT)

1 2 1 2( , ) min( ( ), ( ))intersectioni

d H H H i H i

1 20 ( , ) 1intersectiond H H

totalmismatch

perfectmatch

H1 and H2 are normalized to one before comparing

Histogram Comparisons in OpenCV

#define CV_COMP_CORREL 0#define CV_COMP_CHISQR 1#define CV_COMP_INTERSECT 2#define CV_COMP_BHATTACHARYYA 3

BHATTACHARYYA Method(CV_COMP_BHATTACHARYYA)

1 20 ( , ) 1Bhattacharyyad H H

totalmismatch

perfectmatch

1 21 2

1 2

( ) ( )( , ) 1Bhattacharyya i

i i

H i H id H H

H H

Histogram Comparisons in OpenCV

Histograms and Matching

Back Projection

Back Projection

Back projection is a way of recording how well the pixels or patches of pixels fit the distribution of pixels in a histogram model– cvCalcBackProject()

– cvCalcBackProjectPatch()

Back Projection

Back projection is a way of recording how well the pixels or patches of pixels fit the distribution of pixels in a histogram model– cvCalcBackProject()

– cvCalcBackProjectPatch()

cvCalcBackProject

Example

DownloadTest Program

DownloadTest Program

Patch-Based Projection

Patch-Based Projection

Patch-Based Projection