histograms and matching 主講人:虞台文. content overview basic histogram structure accessing...
TRANSCRIPT
Content
Overview Basic Histogram Structure Accessing Histograms Basic Manipulations with Histograms Color Spaces Histogram Comparisons Back Projection
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);
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;
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);
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
OpenCV Color Space Conversion
void cvCvtColor(
const CvArr* src,
CvArr* dst,
int code
)
void cvCvtColor(
const CvArr* src,
CvArr* dst,
int code
)
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
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
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()