src/qvdta/qvmser.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
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         // Prune low areas from image, with component tree
00048         QVComponentTree componentTree(image);
00049 
00051         // Tree transversing
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                 // We obtain histogram
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                 // Calculate 'q' function (from the paper)
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                 // Get local minima of the function, and append them to MSER list
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                                 // We have a minimum in the q function
00086                                 {
00087                                 if (lastMSERThreshold == -1)
00088                                         // We don't have any previous local minima in the node
00089                                         {
00090                                         lastMSERThreshold = threshold;
00091                                         minLastMSERThreshold = threshold;
00092                                         }
00093                                 else
00094                                         if (PROPORTIONAL_DISTANCE((float)histogram[lastMSERThreshold], (float)histogram[threshold]) < diffAreaThreshold)
00095                                                 // if distance with last minima isn't enough, we just actialize minimun MSER
00096                                                 {
00097                                                 if (q_function[minLastMSERThreshold] > q_function[threshold])
00098                                                                 minLastMSERThreshold = threshold;
00099                                                 }
00100                                         else    // We have a previous minima, and far enough from the actual minimum, we add the smallest MSER found in the previous set of minimums
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 

Generated on Fri Feb 22 18:26:55 2008 for QVision by  doxygen 1.5.3