00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <qvdta/qvmser.h>
00026
00027 void getMSERContours(const QVImage<uChar, 1> &image, const QList<QVMSER> &MSERList, QList< QVPolyline > &polylineMSERList)
00028 {
00029 const uInt rows = image.getRows(), cols = image.getCols();
00030
00031 QVImage<uChar> notImage(cols, rows);
00032 for (uInt col = 0; col < cols; col++)
00033 for (uInt row = 0; row < rows; row++)
00034 notImage(col, row) = 255 - image(col, row);
00035
00036 for (uInt msers = 0; msers < MSERList.size(); msers++)
00037 {
00038 QVPolyline polylineMSER = getConnectedSetBorderContourThreshold(notImage,
00039 MSERList.at(msers).seed, 255 - MSERList.at(msers).threshold);
00040 polylineMSERList.append (polylineMSER);
00041 }
00042 }
00043
00044 void getMSER(const QVImage<uChar,1> &image, QList<QVMSER> &MSERList, const int delta, const int minArea, const int maxArea, const double diffAreaThreshold)
00045 {
00047
00048 QVComponentTree componentTree(image);
00049
00051
00052 uInt histogram[256];
00053 double q_function[256];
00054
00055 for (uInt node = 0; node < componentTree.getNumNodes(); node++)
00056 {
00057 int firstThres = componentTree.firstThreshold(node), lastThres = componentTree.lastThreshold(node);
00058
00059 if (lastThres - firstThres - 2*delta - 2 < 0)
00060 continue;
00061
00062
00063 for (int threshold = firstThres, lastHistogramValue; threshold <= lastThres; threshold++)
00064 {
00065 uInt area = componentTree.area(node)[threshold];
00066 if(area != 0)
00067 lastHistogramValue = area;
00068 histogram[threshold] = lastHistogramValue;
00069 }
00070
00071
00072 for (int threshold = firstThres + delta; threshold <= lastThres - delta; threshold++)
00073 {
00074 q_function[threshold] = (double)(histogram[threshold + delta] - histogram[threshold - delta]) / histogram[threshold];
00075 }
00076
00077
00078 int lastMSERThreshold = -1, minLastMSERThreshold = 0;
00079 for (int threshold = firstThres + delta + 1; threshold <= lastThres - delta - 1; threshold++)
00080 {
00081 if ( ((int)histogram[threshold] < minArea) || ((int)histogram[threshold] > maxArea) )
00082 continue;
00083
00084 if ( (q_function[threshold + 1] > q_function[threshold]) && (q_function[threshold - 1] > q_function[threshold]) )
00085
00086 {
00087 if (lastMSERThreshold == -1)
00088
00089 {
00090 lastMSERThreshold = threshold;
00091 minLastMSERThreshold = threshold;
00092 }
00093 else
00094 if (PROPORTIONAL_DISTANCE((float)histogram[lastMSERThreshold], (float)histogram[threshold]) < diffAreaThreshold)
00095
00096 {
00097 if (q_function[minLastMSERThreshold] > q_function[threshold])
00098 minLastMSERThreshold = threshold;
00099 }
00100 else
00101 {
00102 MSERList.append(QVMSER(QPoint(componentTree.seedX(node), componentTree.seedY(node)), minLastMSERThreshold));
00103 lastMSERThreshold = threshold;
00104 minLastMSERThreshold = threshold;
00105 }
00106 }
00107 }
00108 if (lastMSERThreshold != -1)
00109 MSERList.append(QVMSER(QPoint(componentTree.seedX(node), componentTree.seedY(node)), minLastMSERThreshold));
00110 }
00111
00112 }
00113