Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

easy ;)

you get the maximum using minMaxLoc:

double M;
Point pM;
minMaxLoc(mat, 0,&M, 0, &pM);

then you remove the max value from your Mat, and do it again:

Mat mc = mat.clone(); // leave original histogram intact 
mc.at<float>(pM) = 0; // careful with the type !

double M2;
Point pM2;minMaxLoc(mc, 0,&M2, 0, &pM2);
// now M2 is the "second largest" item in your hist ;)

easy ;)

you get the maximum using minMaxLoc:

double M;
Point pM;
minMaxLoc(mat, 0,&M, 0, &pM);

then you remove the max value from your Mat, and do it again:

Mat mc mat2 = mat.clone(); // leave original histogram histogram(?) intact 
mc.at<float>(pM) mat2.at<float>(pM) = 0; // careful with the type !

double M2;
Point pM2;minMaxLoc(mc, pM2;
minMaxLoc(mat2, 0,&M2, 0, &pM2);
// now M2 is the "second largest" item in your hist ;)

easy ;);)

the whole trick is using a copy for "deleting" the largest bin (and not deleting the bin, just resetting its value)

you get the maximum using minMaxLoc:minMaxLoc, as usual:

double M;
Point pM;
minMaxLoc(mat, 0,&M, 0, &pM);

then you removereset the max value from your Mat, and do it again:

Mat mat2 = mat.clone(); // leave original histogram(?) intact 
mat2.at<float>(pM) = 0; // careful with the type !

double M2;
Point pM2;
minMaxLoc(mat2, 0,&M2, 0, &pM2);
// now M2 is the "second largest" item in your hist ;)