diff --git a/src/trace/siox.h b/src/trace/siox.h
index 4020fe343d8c9d77f78321e6d2b6ca4f8d85bc9e..42fd304219237be2f1772d9a30efeb9eec6bc0ff 100644 (file)
--- a/src/trace/siox.h
+++ b/src/trace/siox.h
-#ifndef __SIOX_SEGMENTATOR_H__\r
-#define __SIOX_SEGMENTATOR_H__\r
-/*\r
- Copyright 2005, 2006 by Gerald Friedland, Kristian Jantz and Lars Knipping\r
-\r
- Conversion to C++ for Inkscape by Bob Jamison\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
- */\r
-\r
-#include <map>\r
-#include <vector>\r
-\r
-namespace org\r
-{\r
-namespace siox\r
-{\r
-\r
-/**\r
- * Image segmentator based on\r
- *<em>SIOX: Simple Interactive Object Extraction</em>.\r
- * <P>\r
- * To segmentate an image one has to perform the following steps.\r
- * <OL><LI>Construct an instance of <code>SioxSegmentator</code>.\r
- * </LI><LI>Create a confidence matrix, where each entry marks its\r
- * corresponding image pixel to belong to the foreground, to the\r
- * background, or being of unknown type.\r
- * </LI><LI>Call <code>segmentate</code> on the image with the confidence\r
- * matrix. This stores the result as new foreground confidence into\r
- * the confidence matrix, with each entry being either\r
- * zero (<code>CERTAIN_BACKGROUND_CONFIDENCE</code>) or one\r
- * (<code>CERTAIN_FOREGROUND_CONFIDENCE</code>).\r
- * </LI><LI>Optionally call <code>subpixelRefine</code> to areas\r
- * where pixels contain both foreground and background (e.g.\r
- * object borders or highly detailed features like flowing hairs).\r
- * The pixel are then assigned confidence values bwetween zero and\r
- * one to give them a measure of "foregroundness".\r
- * This step may be repeated as often as needed.\r
- * </LI></OL>\r
- * <P>\r
- * For algorithm documentation refer to\r
- * G. Friedland, K. Jantz, L. Knipping, R. Rojas:<i>\r
- * Image Segmentation by Uniform Color Clustering\r
- * -- Approach and Benchmark Results</i>,\r
- * <A HREF="http://www.inf.fu-berlin.de/inst/pubs/tr-b-05-07.pdf">Technical Report B-05-07</A>,\r
- * Department of Computer Science, Freie Universitaet Berlin, June 2005.<br>\r
- * <P>\r
- * See <A HREF="http://www.siox.org/" target="_new">http://www.siox.org</A> for more information.<br>\r
- * <P>\r
- * Algorithm idea by Gerald Friedland.\r
- *\r
- * @author Gerald Friedland, Kristian Jantz, Lars Knipping\r
- * @version 1.12\r
- */\r
-\r
-/**\r
- * Helper class for storing the minimum distances to a cluster centroid\r
- * in background and foreground and the index to the centroids in each\r
- * signature for a given color.\r
- */\r
-class Tupel {\r
-public:\r
-\r
- Tupel()\r
- {\r
- minBgDist = 0.0f;\r
- indexMinBg = 0;\r
- minFgDist = 0.0f;\r
- indexMinFg = 0;\r
- }\r
- Tupel(float minBgDistArg, long indexMinBgArg,\r
- float minFgDistArg, long indexMinFgArg)\r
- {\r
- minBgDist = minBgDistArg;\r
- indexMinBg = indexMinBgArg;\r
- minFgDist = minFgDistArg;\r
- indexMinFg = indexMinFgArg;\r
- }\r
- Tupel(const Tupel &other)\r
- {\r
- minBgDist = other.minBgDist;\r
- indexMinBg = other.indexMinBg;\r
- minFgDist = other.minFgDist;\r
- indexMinFg = other.indexMinFg;\r
- }\r
- Tupel &operator=(const Tupel &other)\r
- {\r
- minBgDist = other.minBgDist;\r
- indexMinBg = other.indexMinBg;\r
- minFgDist = other.minFgDist;\r
- indexMinFg = other.indexMinFg;\r
- return *this;\r
- }\r
- virtual ~Tupel()\r
- {}\r
-\r
- float minBgDist;\r
- long indexMinBg;\r
- float minFgDist;\r
- long indexMinFg;\r
-\r
- };\r
-\r
-\r
-class CLAB\r
-{\r
-public:\r
- CLAB()\r
- {\r
- C = L = A = B = 0.0f;\r
- }\r
- CLAB(float lArg, float aArg, float bArg)\r
- {\r
- C = 0.0f;\r
- L = lArg;\r
- A = aArg;\r
- B = bArg;\r
- }\r
- CLAB(const CLAB &other)\r
- {\r
- C = other.C;\r
- L = other.L;\r
- A = other.A;\r
- B = other.B;\r
- }\r
- CLAB &operator=(const CLAB &other)\r
- {\r
- C = other.C;\r
- L = other.L;\r
- A = other.A;\r
- B = other.B;\r
- return *this;\r
- }\r
- virtual ~CLAB()\r
- {}\r
-\r
- float C;\r
- float L;\r
- float A;\r
- float B;\r
-};\r
-\r
-\r
-class SioxSegmentator\r
-{\r
-public:\r
-\r
- /** Confidence corresponding to a certain foreground region (equals one). */\r
- static const float CERTAIN_FOREGROUND_CONFIDENCE; //=1.0f;\r
-\r
- /** Confidence for a region likely being foreground.*/\r
- static const float FOREGROUND_CONFIDENCE; //=0.8f;\r
-\r
- /** Confidence for foreground or background type being equally likely.*/\r
- static const float UNKNOWN_REGION_CONFIDENCE; //=0.5f;\r
-\r
- /** Confidence for a region likely being background.*/\r
- static const float BACKGROUND_CONFIDENCE; //=0.1f;\r
-\r
- /** Confidence corresponding to a certain background reagion (equals zero). */\r
- static const float CERTAIN_BACKGROUND_CONFIDENCE; //=0.0f;\r
-\r
-\r
- /**\r
- * Constructs a SioxSegmentator Object to be used for image segmentation.\r
- *\r
- * @param w X resolution of the image to be segmentated.\r
- * @param h Y resolution of the image to be segmentated.\r
- * @param limits Size of the cluster on LAB axises.\r
- * If <code>null</code>, the default value {0.64f,1.28f,2.56f}\r
- * is used.\r
- */\r
- SioxSegmentator(int w, int h, float *limitsArg, int limitsSize);\r
-\r
- /**\r
- * Destructor\r
- */\r
- virtual ~SioxSegmentator();\r
-\r
-\r
- /**\r
- * Segmentates the given image with information from the confidence\r
- * matrix.\r
- * <P>\r
- * The confidence entries of <code>BACKGROUND_CONFIDENCE</code> or less\r
- * are mark known background pixel for the segmentation, those\r
- * of at least <code>FOREGROUND_CONFIDENCE</code> mark known\r
- * foreground pixel for the segmentation. Any other entry is treated\r
- * as region of unknown affiliation.\r
- * <P>\r
- * As result, each pixel is classified either as foregroound or\r
- * background, stored back into its <code>cm</code> entry as confidence\r
- * <code>CERTAIN_FOREGROUND_CONFIDENCE</code> or\r
- * <code>CERTAIN_BACKGROUND_CONFIDENCE</code>.\r
- *\r
- * @param image Pixel data of the image to be segmentated.\r
- * Every integer represents one ARGB-value.\r
- * @param imageSize number of values in image\r
- * @param cm Confidence matrix specifying the probability of an image\r
- * belonging to the foreground before and after the segmentation.\r
- * @param smoothness Number of smoothing steps in the post processing.\r
- * @param sizeFactorToKeep Segmentation retains the largest connected\r
- * foreground component plus any component with size at least\r
- * <CODE>sizeOfLargestComponent/sizeFactorToKeep</CODE>.\r
- * @return <CODE>true</CODE> if the segmentation algorithm succeeded,\r
- * <CODE>false</CODE> if segmentation is impossible\r
- */\r
- bool segmentate(unsigned long *image, int imageSize,\r
- float *cm, int cmSize,\r
- int smoothness, double sizeFactorToKeep);\r
-\r
- /**\r
- * Clears given confidence matrix except entries for the largest connected\r
- * component and every component with\r
- * <CODE>size*sizeFactorToKeep >= sizeOfLargestComponent</CODE>.\r
- *\r
- * @param cm Confidence matrix to be analysed\r
- * @param threshold Pixel visibility threshold.\r
- * Exactly those cm entries larger than threshold are considered\r
- * to be a "visible" foreground pixel.\r
- * @param sizeFactorToKeep This method keeps the largest connected\r
- * component plus any component with size at least\r
- * <CODE>sizeOfLargestComponent/sizeFactorToKeep</CODE>.\r
- */\r
- void keepOnlyLargeComponents(float *cm, int cmSize,\r
- float threshold,\r
- double sizeFactorToKeep);\r
-\r
- /**\r
- * Depth first search pixels in a foreground component.\r
- *\r
- * @param cm confidence matrix to be searched.\r
- * @param i starting position as index to confidence matrix.\r
- * @param threshold defines the minimum value at which a pixel is\r
- * considered foreground.\r
- * @param curlabel label no of component.\r
- * @return size in pixel of the component found.\r
- */\r
- int depthFirstSearch(float *cm, int i, float threshold, int curLabel);\r
-\r
- /**\r
- * Refines the classification stored in the confidence matrix by modifying\r
- * the confidences for regions which have characteristics to both\r
- * foreground and background if they fall into the specified square.\r
- * <P>\r
- * The can be used in displaying the image by assigning the alpha values\r
- * of the pixels according to the confidence entries.\r
- * <P>\r
- * In the algorithm descriptions and examples GUIs this step is referrered\r
- * to as <EM>Detail Refinement (Brush)</EM>.\r
- *\r
- * @param x Horizontal coordinate of the squares center.\r
- * @param y Vertical coordinate of the squares center.\r
- * @param brushmode Mode of the refinement applied, <CODE>ADD_EDGE</CODE>\r
- * or <CODE>SUB_EDGE</CODE>. Add mode only modifies pixels\r
- * formerly classified as background, sub mode only those\r
- * formerly classified as foreground.\r
- * @param threshold Threshold for the add and sub refinement, deciding\r
- * at the confidence level to stop at.\r
- * @param cf The confidence matrix to modify, generated by\r
- * <CODE>segmentate</CODE>, possibly already refined by privious\r
- * calls to <CODE>subpixelRefine</CODE>.\r
- * @param brushsize Halfed diameter of the square shaped brush.\r
- *\r
- * @see #segmentate\r
- */\r
- void subpixelRefine(int x, int y, int brushmode,\r
- float threshold, float *cf, int brushsize);\r
-\r
- /**\r
- * Refines the classification stored in the confidence matrix by modifying\r
- * the confidences for regions which have characteristics to both\r
- * foreground and background if they fall into the specified area.\r
- * <P>\r
- * The can be used in displaying the image by assigning the alpha values\r
- * of the pixels according to the confidence entries.\r
- * <P>\r
- * In the algorithm descriptions and examples GUIs this step is referrered\r
- * to as <EM>Detail Refinement (Brush)</EM>.\r
- *\r
- * @param area Area in which the reworking of the segmentation is\r
- * applied to.\r
- * @param brushmode Mode of the refinement applied, <CODE>ADD_EDGE</CODE>\r
- * or <CODE>SUB_EDGE</CODE>. Add mode only modifies pixels\r
- * formerly classified as background, sub mode only those\r
- * formerly classified as foreground.\r
- * @param threshold Threshold for the add and sub refinement, deciding\r
- * at the confidence level to stop at.\r
- * @param cf The confidence matrix to modify, generated by\r
- * <CODE>segmentate</CODE>, possibly already refined by privious\r
- * calls to <CODE>subpixelRefine</CODE>.\r
- *\r
- * @see #segmentate\r
- */\r
- bool subpixelRefine(int xa, int ya, int dx, int dy,\r
- int brushmode,\r
- float threshold, float *cf);\r
- /**\r
- * A region growing algorithms used to fill up the confidence matrix\r
- * with <CODE>CERTAIN_FOREGROUND_CONFIDENCE</CODE> for corresponding\r
- * areas of equal colors.\r
- * <P>\r
- * Basically, the method works like the <EM>Magic Wand<EM> with a\r
- * tolerance threshold of zero.\r
- *\r
- * @param cm confidence matrix to be searched\r
- * @param image image to be searched\r
- */\r
- void fillColorRegions(float *cm, int cmSize, unsigned long *image);\r
-\r
-private:\r
-\r
- /**\r
- * Prevent this from being used\r
- */\r
- SioxSegmentator();\r
-\r
- /** error logging **/\r
- void error(char *format, ...);\r
-\r
- /** trace logging **/\r
- void trace(char *format, ...);\r
-\r
- typedef enum\r
- {\r
- ADD_EDGE, /** Add mode for the subpixel refinement. */\r
- SUB_EDGE /** Subtract mode for the subpixel refinement. */\r
- } BrushMode;\r
-\r
- // instance fields:\r
-\r
- /** Horizontal resolution of the image to be segmentated. */\r
- int imgWidth;\r
-\r
- /** Vertical resolution of the image to be segmentated. */\r
- int imgHeight;\r
-\r
- /** Stores component label (index) by pixel it belongs to. */\r
- int *labelField;\r
-\r
- /**\r
- * LAB color values of pixels that are definitly known background.\r
- * Entries are of form {l,a,b}.\r
- */\r
- std::vector<CLAB> knownBg;\r
-\r
- /**\r
- * LAB color values of pixels that are definitly known foreground.\r
- * Entries are of form {l,a,b}.\r
- */\r
- std::vector<CLAB> knownFg;\r
-\r
- /** Holds background signature (a characteristic subset of the bg.) */\r
- std::vector<CLAB> bgSignature;\r
-\r
- /** Holds foreground signature (a characteristic subset of the fg).*/\r
- std::vector<CLAB> fgSignature;\r
-\r
- /** Size of cluster on lab axis. */\r
- float *limits;\r
-\r
- /** Maximum distance of two lab values. */\r
- float clusterSize;\r
-\r
- /**\r
- * Stores Tupels for fast access to nearest background/foreground pixels.\r
- */\r
- std::map<unsigned long, Tupel> hs;\r
-\r
- /** Size of the biggest blob.*/\r
- int regionCount;\r
-\r
- /** Copy of the original image, needed for detail refinement. */\r
- long *origImage;\r
- long origImageSize;\r
-\r
- /** A flag that stores if the segmentation algorithm has already ran.*/\r
- bool segmentated;\r
-\r
-};\r
-\r
-} //namespace siox\r
-} //namespace org\r
-\r
-#endif /* __SIOX_SEGMENTATOR_H__ */\r
-\r
+#ifndef __SIOX_H__
+#define __SIOX_H__
+/**
+ * Copyright 2005, 2006 by Gerald Friedland, Kristian Jantz and Lars Knipping
+ *
+ * Conversion to C++ for Inkscape by Bob Jamison
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Note by Bob Jamison:
+ * After translating the siox.org Java API to C++ and receiving an
+ * education into this wonderful code, I began again,
+ * and started this version using lessons learned. This version is
+ * an attempt to provide an dependency-free SIOX engine that anyone
+ * can use in their project with minimal effort.
+ *
+ * Many thanks to the fine people at siox.org.
+ */
+
+#include <string>
+#include <vector>
+
+#define HAVE_GLIB
+
+#ifdef HAVE_GLIB
+#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#endif
+
+
+namespace org
+{
+
+namespace siox
+{
+
+
+//########################################################################
+//# C L A B
+//########################################################################
+
+/**
+ *
+ */
+class CieLab
+{
+public:
+
+ /**
+ *
+ */
+ CieLab()
+ {
+ init();
+ C = 0;
+ L = A = B = 0.0f;
+ }
+
+
+ /**
+ *
+ */
+ CieLab(unsigned long rgb);
+
+
+ /**
+ *
+ */
+ CieLab(float lArg, float aArg, float bArg)
+ {
+ init();
+ C = 0;
+ L = lArg;
+ A = aArg;
+ B = bArg;
+ }
+
+
+ /**
+ *
+ */
+ CieLab(const CieLab &other)
+ {
+ init();
+ C = other.C;
+ L = other.L;
+ A = other.A;
+ B = other.B;
+ }
+
+
+ /**
+ *
+ */
+ CieLab &operator=(const CieLab &other)
+ {
+ init();
+ C = other.C;
+ L = other.L;
+ A = other.A;
+ B = other.B;
+ return *this;
+ }
+
+ /**
+ *
+ */
+ virtual ~CieLab()
+ {}
+
+ /**
+ * Retrieve a CieLab value via index.
+ */
+ virtual float operator()(unsigned int index)
+ {
+ if (index==0) return L;
+ else if (index==1) return A;
+ else if (index==2) return B;
+ else return 0;
+ }
+
+
+ /**
+ *
+ */
+ virtual void add(const CieLab &other)
+ {
+ C += other.C;
+ L += other.L;
+ A += other.A;
+ B += other.B;
+ }
+
+
+ /**
+ *
+ */
+ virtual void mul(float scale)
+ {
+ L *= scale;
+ A *= scale;
+ B *= scale;
+ }
+
+
+ /**
+ *
+ */
+ virtual unsigned long toRGB();
+
+ /**
+ * Approximate cube roots
+ */
+ double cbrt(double x);
+
+ /**
+ *
+ */
+ double qnrt(double x);
+
+ /**
+ * Raise to the 2.4 power
+ */
+ double pow24(double x);
+
+ /**
+ * Squared Euclidian distance between this and another color
+ */
+ float diffSq(const CieLab &other);
+
+ /**
+ * Computes squared euclidian distance in CieLab space for two colors
+ * given as RGB values.
+ */
+ static float diffSq(unsigned int rgb1, unsigned int rgb2);
+
+ /**
+ * Computes squared euclidian distance in CieLab space for two colors
+ * given as RGB values.
+ */
+ static float diff(unsigned int rgb0, unsigned int rgb1);
+
+
+ unsigned int C;
+ float L;
+ float A;
+ float B;
+
+private:
+
+ /**
+ *
+ */
+ void init();
+
+
+};
+
+
+//########################################################################
+//# S I O X I M A G E
+//########################################################################
+
+/**
+ * This is a generic image type that provides a consistent interface
+ * to Siox, so that developers will not need to worry about data arrays.
+ */
+class SioxImage
+{
+public:
+
+ /**
+ * Create an image with the given width and height
+ */
+ SioxImage(unsigned int width, unsigned int height);
+
+ /**
+ * Copy constructor
+ */
+ SioxImage(const SioxImage &other);
+
+ /**
+ * Assignment
+ */
+ SioxImage &operator=(const SioxImage &other);
+
+ /**
+ * Clean up after use.
+ */
+ virtual ~SioxImage();
+
+ /**
+ * Returns true if the previous operation on this image
+ * was successful, else false.
+ */
+ virtual bool isValid();
+
+ /**
+ * Sets whether an operation was successful, and whether
+ * this image should be considered a valid one.
+ * was successful, else false.
+ */
+ virtual void setValid(bool val);
+
+ /**
+ * Set a pixel at the x,y coordinates to the given value.
+ * If the coordinates are out of range, do nothing.
+ */
+ virtual void setPixel(unsigned int x,
+ unsigned int y,
+ unsigned int pixval);
+
+ /**
+ * Set a pixel at the x,y coordinates to the given r, g, b values.
+ * If the coordinates are out of range, do nothing.
+ */
+ virtual void setPixel(unsigned int x, unsigned int y,
+ unsigned int a,
+ unsigned int r,
+ unsigned int g,
+ unsigned int b);
+
+ /**
+ * Get a pixel at the x,y coordinates given. If
+ * the coordinates are out of range, return 0
+ */
+ virtual unsigned int getPixel(unsigned int x, unsigned int y);
+
+
+ /**
+ * Return the image data buffer
+ */
+ virtual unsigned int *getImageData();
+
+ /**
+ * Set a confidence value at the x,y coordinates to the given value.
+ * If the coordinates are out of range, do nothing.
+ */
+ virtual void setConfidence(unsigned int x,
+ unsigned int y,
+ float conf);
+
+ /**
+ * Get a confidence value at the x,y coordinates given. If
+ * the coordinates are out of range, return 0
+ */
+ virtual float getConfidence(unsigned int x, unsigned int y);
+
+ /**
+ * Return the confidence data buffer
+ */
+ virtual float *getConfidenceData();
+
+ /**
+ * Return the width of this image
+ */
+ virtual int getWidth();
+
+ /**
+ * Return the height of this image
+ */
+ virtual int getHeight();
+
+ /**
+ * Saves this image as a simple color PPM
+ */
+ bool writePPM(const std::string fileName);
+
+
+
+#ifdef HAVE_GLIB
+
+ /**
+ * Special constructor to create an image from a GdkPixbuf.
+ */
+ SioxImage(GdkPixbuf *buf);
+
+ /**
+ * Creates a GdkPixbuf from this image. The user must
+ * remember to destroy the image when no longer needed.
+ * with g_free(pixbuf)
+ */
+ GdkPixbuf *getGdkPixbuf();
+
+#endif
+
+private:
+
+ SioxImage()
+ {}
+
+ /**
+ * Assign values to that of another
+ */
+ void assign(const SioxImage &other);
+
+ /**
+ * Initialize values. Used by constructors
+ */
+ void init(unsigned int width, unsigned int height);
+
+ bool valid;
+
+ unsigned int width;
+
+ unsigned int height;
+
+ unsigned long imageSize;
+
+ /**
+ * Pixel data
+ */
+ unsigned int *pixdata;
+
+ /**
+ * Confidence matrix data
+ */
+ float *cmdata;
+
+private:
+
+ /**
+ * Error logging
+ */
+ void error(char *fmt, ...) G_GNUC_PRINTF(2,3);
+
+};
+
+
+
+//########################################################################
+//# S I O X O B S E R V E R
+//########################################################################
+class Siox;
+
+/**
+ * This is a class for observing the progress of a Siox engine. Overload
+ * the methods in your subclass to get the desired behaviour.
+ */
+class SioxObserver
+{
+public:
+
+ /**
+ * Constructor. Context can point to anything, and is usually
+ * used to point to a C++ object or C state object, to delegate
+ * callback processing to something else. Use NULL to ignore.
+ */
+ SioxObserver(void *contextArg) : context(NULL)
+ { context = contextArg; }
+
+ /**
+ * Destructor
+ */
+ virtual ~SioxObserver()
+ { }
+
+ /**
+ * Informs the observer how much has been completed.
+ * Return false if the processing should be aborted.
+ */
+ virtual bool progress(float /*percentCompleted*/)
+ {
+ return true;
+ }
+
+ /**
+ * Send an error string to the Observer. Processing will
+ * be halted.
+ */
+ virtual void error(const std::string &/*msg*/)
+ {
+ }
+
+protected:
+
+ void *context;
+
+};
+
+
+
+//########################################################################
+//# S I O X
+//########################################################################
+
+/**
+ *
+ */
+class Siox
+{
+public:
+
+ /**
+ * Confidence corresponding to a certain foreground region (equals one).
+ */
+ static const float CERTAIN_FOREGROUND_CONFIDENCE; //=1.0f;
+
+ /**
+ * Confidence for a region likely being foreground.
+ */
+ static const float FOREGROUND_CONFIDENCE; //=0.8f;
+
+ /**
+ * Confidence for foreground or background type being equally likely.
+ */
+ static const float UNKNOWN_REGION_CONFIDENCE; //=0.5f;
+
+ /**
+ * Confidence for a region likely being background.
+ */
+ static const float BACKGROUND_CONFIDENCE; //=0.1f;
+
+ /**
+ * Confidence corresponding to a certain background reagion (equals zero).
+ */
+ static const float CERTAIN_BACKGROUND_CONFIDENCE; //=0.0f;
+
+ /**
+ * Construct a Siox engine
+ */
+ Siox();
+
+ /**
+ * Construct a Siox engine. Use null to ignore
+ */
+ Siox(SioxObserver *observer);
+
+ /**
+ *
+ */
+ virtual ~Siox();
+
+ /**
+ * Extract the foreground of the original image, according
+ * to the values in the confidence matrix. If the operation fails,
+ * sioxImage.isValid() will be false.
+ * backgroundFillColor is any ARGB color, such as 0xffffff (white)
+ * or 0x000000 (black)
+ */
+ virtual SioxImage extractForeground(const SioxImage &originalImage,
+ unsigned int backgroundFillColor);
+
+private:
+
+ SioxObserver *sioxObserver;
+
+ /**
+ * Progress reporting
+ */
+ bool progressReport(float percentCompleted);
+
+ /**
+ * Flag this as false during processing to abort
+ */
+ bool keepGoing;
+
+ /**
+ * Our signature limits
+ */
+ float limits[3];
+
+ /**
+ * Image width
+ */
+ unsigned int width;
+
+ /**
+ * Image height
+ */
+ unsigned int height;
+
+ /**
+ * Image size in pixels
+ */
+ unsigned long pixelCount;
+
+ /**
+ * Image data
+ */
+ unsigned int *image;
+
+ /**
+ * Image confidence matrix
+ */
+ float *cm;
+
+ /**
+ * Markup for image editing
+ */
+ int *labelField;
+
+
+ /**
+ * Maximum distance of two lab values.
+ */
+ float clusterSize;
+
+ /**
+ * Initialize the Siox engine to its 'pristine' state.
+ * Performed at the beginning of extractForeground().
+ */
+ void init();
+
+ /**
+ * Clean up any debris from processing.
+ */
+ void cleanup();
+
+ /**
+ * Error logging
+ */
+ void error(char *fmt, ...) G_GNUC_PRINTF(2,3);
+
+ /**
+ * Trace logging
+ */
+ void trace(char *fmt, ...) G_GNUC_PRINTF(2,3);
+
+ /**
+ * Stage 1 of the color signature work. 'dims' will be either
+ * 2 for grays, or 3 for colors
+ */
+ void colorSignatureStage1(CieLab *points,
+ unsigned int leftBase,
+ unsigned int rightBase,
+ unsigned int recursionDepth,
+ unsigned int *clusters,
+ const unsigned int dims);
+
+ /**
+ * Stage 2 of the color signature work
+ */
+ void colorSignatureStage2(CieLab *points,
+ unsigned int leftBase,
+ unsigned int rightBase,
+ unsigned int recursionDepth,
+ unsigned int *clusters,
+ const float threshold,
+ const unsigned int dims);
+
+ /**
+ * Main color signature method
+ */
+ bool colorSignature(const std::vector<CieLab> &inputVec,
+ std::vector<CieLab> &result,
+ const unsigned int dims);
+
+
+ /**
+ *
+ */
+ void keepOnlyLargeComponents(float threshold,
+ double sizeFactorToKeep);
+
+ /**
+ *
+ */
+ int depthFirstSearch(int startPos, float threshold, int curLabel);
+
+
+ /**
+ *
+ */
+ void fillColorRegions();
+
+ /**
+ * Applies the morphological dilate operator.
+ *
+ * Can be used to close small holes in the given confidence matrix.
+ */
+ void dilate(float *cm, int xres, int yres);
+
+ /**
+ * Applies the morphological erode operator.
+ */
+ void erode(float *cm, int xres, int yres);
+
+ /**
+ * Normalizes the matrix to values to [0..1].
+ */
+ void normalizeMatrix(float *cm, int cmSize);
+
+ /**
+ * Multiplies matrix with the given scalar.
+ */
+ void premultiplyMatrix(float alpha, float *cm, int cmSize);
+
+ /**
+ * Blurs confidence matrix with a given symmetrically weighted kernel.
+ */
+ void smooth(float *cm, int xres, int yres,
+ float f1, float f2, float f3);
+
+ /**
+ * Squared Euclidian distance of p and q.
+ */
+ float sqrEuclidianDist(float *p, int pSize, float *q);
+
+
+
+
+};
+
+
+
+
+} // namespace siox
+} // namespace org
+
+#endif /* __SIOX_H__ */
+//########################################################################
+//# E N D O F F I L E
+//########################################################################
+
+
+