Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较OpenCV中的直方图并将相似性指数标准化_C_Opencv_Histogram - Fatal编程技术网

比较OpenCV中的直方图并将相似性指数标准化

比较OpenCV中的直方图并将相似性指数标准化,c,opencv,histogram,C,Opencv,Histogram,我正在使用最新版本的OpenCV框架(2.4.6.0)进行图像处理。 当0是最小相似性值,而1是最大相似性值时,我必须比较两个直方图以获得集合[0;1]中的浮点值 我的代码如下: CvHistogram* create_histogram( IplImage** image, IplImage* mask ) { int num_bins = 8; float xranges[] = { 0, 255 }; float* ranges[] = { xranges, xra

我正在使用最新版本的OpenCV框架(
2.4.6.0
)进行图像处理。 当
0
是最小相似性值,而
1
是最大相似性值时,我必须比较两个直方图以获得集合
[0;1]
中的
浮点值

我的代码如下:

CvHistogram* create_histogram( IplImage** image, IplImage* mask )
{
    int num_bins = 8;
    float xranges[] = { 0, 255 };
    float* ranges[] = { xranges, xranges, xranges };
    int hist_size[] = { num_bins, num_bins, num_bins };
    CvHistogram* hist = cvCreateHist(3, hist_size, CV_HIST_ARRAY, ranges, 1);
    cvCalcHist(image, hist, 0, mask);
    cvNormalizeHist(hist, 1);
    return hist;
}

void set_histogram( T_FRAME &frame, T_FRAME &mask, T_APPEARANCE &appearance, const T_RECT rect )
{
    cvSetImageROI(frame, rect);
    cvSetImageROI(mask, rect);
    IplImage* b = cvCreateImage(cvGetSize(frame), frame->depth, 1);
    IplImage* g = cvCreateImage(cvGetSize(frame), frame->depth, 1);
    IplImage* r = cvCreateImage(cvGetSize(frame), frame->depth, 1);
    cvSplit(frame, b, g, r, NULL);
    IplImage* bgr_plane[]   = { b, g, r };
    CvHistogram* histogram  = create_histogram(bgr_plane, mask);
    appearance.hist = histogram;
    cvReleaseImage(&b);
    cvReleaseImage(&g);
    cvReleaseImage(&r);
    cvResetImageROI(frame);
    cvResetImageROI(mask);
}
注:
typedef IplImage*T_框架

因此,我创建了两个外观模型并比较了它们的直方图:

void create_appearence( T_FRAME &frame, T_FRAME &mask, T_APPEARANCE &appearance, const T_RECT rect )
{
    set_histogram(frame, mask, appearance, rect);
}

float get_similarity( T_APPEARANCE &appearance_A, T_APPEARANCE &appearance_B )
{
    return cvCompareHist(appearance_A.hist, appearance_B.hist, CV_COMP_CHISQR);
}
作为输出,根据(我假设)直方图之间距离的定义,程序不会返回
[0;1]
中的值(例如:
-41
14
,等等)(请参阅)

是否有一种方法来规范这些指数


您好,Vi.

您可以使用类似sigmoid的函数。它们可以将任何值的间隔压缩到[0;1]

为了解决这个问题,我使用了Bhattacharyya距离(
CV_COMP_Bhattacharyya
)而不是卡方

float get_similarity( T_APPEARANCE &appearance_A, T_APPEARANCE &appearance_B )
{
    return cvCompareHist(appearance_A.hist, appearance_B.hist, CV_COMP_BHATTACHARYYA);
}
因此,
cvCompareHist
根据需要在
[0;1]
中返回一个值

请注意,方法
CV_COMP_BHATTACHARYYA
仅适用于标准化直方图