123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- /**
- * @file Graph.h
- * @brief a simple graph interface for superregion growing
- * @author Björn Fröhlich
- * @date 08/19/2009
- */
- #ifndef GRAPHINCLUDE
- #define GRAPHINCLUDE
- #include "vislearning/cbaselib/Example.h"
- #include <set>
- namespace OBJREC {
- class Node
- {
- protected:
- //! list of the neighbor nodes
- std::vector<Node*> neighbors;
- //! is it a borderregion?
- bool atborder;
- //! number of the region for lookup in Examples
- int number;
- //! actual class label of the region
- int label;
- //! size of the region in pixel
- int size;
- //! used to compute the centroid of the region
- int amountx, amounty;
- //! saving the bounding box
- int minx, miny, maxx, maxy;
- //! probabilities for each class
- std::vector<double> probs;
- public:
- /**
- * simple constructor
- */
- Node(int n);
- /**
- * adds a neighbor to the current node
- * @param nb pointer to a neighbor
- */
- void addNeighbor(Node *nb);
- /**
- * set atborder to true if the region is a border region
- * @param nblabel changed label of the neighbor
- */
- void change(int nblabel);
- /**
- * returns the label of the node
- * @return
- */
- int getLabel() const;
- /**
- * return size of region
- * @return
- */
- int getSize() const;
- /**
- * set a new label
- * @param l
- */
- void setLabel(int l);
- /**
- * returns true if region is a borderregion
- * @return
- */
- bool isAtBorder();
- /**
- * returns the neighbors of the node
- * @param nb
- */
- void getNeighbors(std::vector<Node*> &nb) const;
- /**
- * returns the number of the region for lookup in Examples
- * @return
- */
- int getRegion() const;
- /**
- * returns the number of the region for lookup in Examples
- * @return
- */
- int getNumber() const {
- return number;
- };
- /**
- * increments the size of the actual region
- * @param s
- */
- void incSize(int s = 1);
- /**
- * add the position of a pixel of the region
- * used to compute the centroid of the region
- * @param x
- * @param y
- */
- void addPos(int x, int y);
- /**
- * returns the postion of the centroid of the region
- * @param x
- * @param y
- */
- void getCentroid(int &x, int &y) const;
- /**
- * set probabilities for each class
- * @param _probs vector of probabilities
- */
- void setProbs(std::vector<double> _probs);
- /**
- * get the max of width and height
- * @return max of width and height of the region
- */
- int getSpan() const;
- /**
- * return the bounding box
- * @param x0
- * @param y0
- * @param x1
- * @param y1
- */
- void getRect(int &x0, int &y0, int &x1, int &y1);
- /**
- * save node information in filestream
- * @param fout outputfilestream
- */
- int store(std::ofstream & fout);
- };
- class RegionGraph
- {
- protected:
- //! the nodes of the graph
- std::vector<Node*> nodes;
- public:
- /**
- * simple constructor
- */
- RegionGraph() {};
- ~RegionGraph();
- void get(std::vector<Node*> &n) const;
- /**
- * creates the graph out of a region matrix
- * @param mask region label for each pixel
- * @param rgcount number of different regions
- */
- void computeGraph(const NICE::Matrix &mask, const int &rgcount);
- /**
- * creates the graph ot of a region matrix mask
- * @param regions
- * @param mask
- */
- void computeGraph(const Examples ®ions, const NICE::Matrix &mask);
- /**
- * returns the number of nodes
- * @return number of nodes
- */
- int size() const;
- /**
- * get pointer to the i-th node
- * @param i number of node
- * @return node
- */
- Node* operator[](int i) const;
- void write(std::string file);
- };
- } //namespace
- #endif
|