开发者

OpenCV and c++ ; compare two binary images and get an output (result )

I want to compare two bina开发者_JAVA技巧ry images and get an output as a result .

How can i do this ??

Can i use cvSobel() to do that??

Binary image has white edges and is there a way to count white pixels or something ???

Thank you !


try cv::compare: http://opencv.willowgarage.com/documentation/cpp/operations_on_arrays.html#cv-compare

cv::Mat img1 = ...
cv::Mat img2 = ...
cv::Mat result = ...

int threshold = (double)(img1.rows * img1.cols) * 0.7; 

cv::compare(img1 , img2  , result , cv::CMP_EQ );
int similarPixels  = countNonZero(result);

if ( similarPixels  > threshold ) {
   cout << "similar" << endl;
}


Here is a function that I have written, based on the following paper. (One should CHECK my CODE! it would be greatly appreciated!) Paper to look after: A J Baddeley: An error metric for binary images

Also the author has a statistic package, where the code can be found. It is called "spatstat" www.spatstat.org. To use the spatstat first download the R-Stat from http://www.r-project.org/. The error metric is available as a function called 'deltametric'. To see the help file, type help(deltametric).

Description of code: The input of this function two filename, which should be binary image files! The return value is the Baddeley Error metric number. One should include the OpenCV headers and namespace also!

float baddeleyerror (const char * a_file, const char* b_file)
{
Mat A,B,Adist,Bdist,Z;
double c=5;
double p=2;
double nelem;
double minval, maxval;

A=imread(a_file,0);
B=imread(b_file,0);

nelem=A.rows*A.cols;

A=A>1;
B=B>1;
distanceTransform(A,Adist,CV_DIST_L1,3);
distanceTransform(B,Bdist,CV_DIST_L1,3);

min(Adist, c, Adist);
min(Bdist, c, Bdist);

minMaxLoc(Adist, &minval, &maxval, 0, 0);
Adist.convertTo(Adist, CV_8UC1, 255/maxval, 1);

minMaxLoc(Bdist, &minval, &maxval, 0, 0);
Bdist.convertTo(Bdist, CV_8UC1, 255/maxval, 1);

pow(abs(Adist-Bdist),p,Z);

return (pow(sum(Z).val[0]/nelem, 1/p));
}


Why not use a straightforward comparison? (pixel by pixel) Sobel will take you O(pixels) anyway, so comparing pixel to pixel won't change complexity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜