PARP Research Group | Universidad de Murcia |
src/qvltmser/qvltmser_ds.hGo to the documentation of this file.00001 /* 00002 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012. 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 #ifndef QVLTMSER_DS_H 00026 #define QVLTMSER_DS_H 00027 00028 #include <QVImage> 00029 #include <QVector> 00030 #include <QVMSER> 00031 00032 // Class for boundary pixels (it is a priority queue of stacks, with high priority for darker gray levels: 00033 class QVLtmserBoundary { 00034 public: 00035 // Index of maximum priority entry on the queue (-1 if empty): 00036 int maxStackPr; 00037 00038 // Constructor: 00039 // * pGreyLevels: number of gray levels of image. 00040 // * pWidth, pHeight: image dimensions. 00041 QVLtmserBoundary(uInt pWidth, uInt pHeight, uInt pGreyLevels); 00042 00043 // Heap initialization: 00044 void initHeap(QVector< int > &histogram); 00045 00046 // Push a new pixel in boundary, for a given gray level: 00047 void pushPixel(uInt greyLevel, uInt pixel); 00048 00049 // Pop a pixel from boundary (returns true if it has been possible, false otherwise): 00050 bool popPixel(uInt greyLevel, uInt &pixel); 00051 00052 protected: 00053 // Image size: 00054 uInt width, height; 00055 00056 // Number of gray levels: 00057 uInt greyLevels; 00058 00059 // Number of pixels to process: 00060 uInt numPixels; 00061 00062 // Length of stacks: 00063 QVector<int> stackLength; 00064 00065 // Start of each stack (-1 if it will never have any pixel): 00066 QVector<int> stackStart; 00067 00068 // The heap is implemented in a compressed manner. Array stackStart contains the start index of each stack 00069 // (for a given priority), or -1 if that stack is empty, while array stackLength contains the corresponding 00070 // top of the stack. The first array will be initialized once at the beginning, using the image histogram. 00071 // Note: Coordinates of pixels have been previously transformed to ints (int_value=(y*num_cols)+x). 00072 QVector<uInt> heap; 00073 00074 // Get index of stack with greater priority (-1 if heap is empty) 00075 int getMaxStackPr(); 00076 }; 00077 00078 // Class for each individual component of the component stack: 00079 class QVLtmserComponent { 00080 public: 00081 // Constructor: 00082 QVLtmserComponent(uInt pGreyLevel); 00083 00084 // Destructor. 00085 ~QVLtmserComponent(); 00086 00087 // Current and minimum gray levels of component: 00088 uChar greyLevel, greyLevelMin; 00089 00090 // Seed pixel: (at the deepest point of component): 00091 uInt seedX, seedY; 00092 00093 // Number of pixels that the component has in the current grayLevel: 00094 uInt numPixels; 00095 00096 // History of areas of the component: 00097 QVector<uInt> *history; 00098 00099 // Static class members: pointer to result seed list and algorithm parameters: 00100 static QHash<QPoint,QVMSER> theSeedList; 00101 static uInt minArea; 00102 static uInt maxArea; 00103 static uChar delta; 00104 static float delta_threshold; 00105 00106 // Set seed of component: 00107 void setSeed(uInt r, uInt c); 00108 00109 // Add a new pixel to component: 00110 void addPixel(uChar pGreyLevel); 00111 00112 // Test if component is a MSER: 00113 void testMSER(); 00114 00115 // Raise gray level to "newGreyLevel", updating variables "greyLevel" and "numPixels", and history of component: 00116 void upGreyLevel(uInt newGreyLevel); 00117 00118 // Add another component to this component: 00119 void addComponent(QVLtmserComponent &otherComponent, uInt newlevel); 00120 00121 private: 00122 // Reference counter to history (to delete it in destructor when counter reaches zero): 00123 uInt countRefsHistory; 00124 }; 00125 00126 // Class for component stack: 00127 class QVLtmserComponentStack { 00128 public: 00129 // Constructor: 00130 // * pGreyLevels: Number of possible gray levels: 00131 QVLtmserComponentStack(uInt pGreyLevels); 00132 00133 // Destructor: 00134 ~QVLtmserComponentStack(); 00135 00136 // Components of stack are stored as pointers in a vector: 00137 QVector<QVLtmserComponent*> *components; 00138 00139 // Initialize component stack: 00140 void initComponents(); 00141 00142 // Push a new component in the stack (its gray level must be lesser than the gray level of component that 00143 // was until now in the top): 00144 void pushComponent(uInt aGreyLevel, int r, int c); 00145 00146 // Pop and destroy the component in the top of the stack: 00147 void popComponent(); 00148 00149 // Get index in vector corresponding to top (returns -1 if empty): 00150 int getPosTop(); 00151 00152 protected: 00153 00154 // Number of gray levels: 00155 uInt greyLevels; 00156 00157 // Position of top in "components". If empty, posTop=-1: 00158 int posTop; 00159 }; 00160 00161 #endif |