#ifndef REGBOUNDARYB_HH #define REGBOUNDARYB_HH //////////////////////////////////////////////////////////////////////////// //! author="Robert Crida" //! lib=DERARegTrack //! date="23/3/98" //! userlevel=Develop //! docentry="Applications.Image Processing.DERA Small Target Detection" //! file="amma/Applications/DERARegTrack/RegBoundaryB.hh" //! rcsid="$Id: RegBoundaryB.hh,v 1.2 1998/10/26 09:39:10 ees1cg Exp $" #include "amma/PriQueueL.hh" #include "amma/ByteImag.hh" #include "amma/RGBImage.hh" #include "amma/IntImage.hh" #include "amma/Vector2d.hh" #include "amma/Mom012d2.hh" #include "amma/Matrix2d.hh" #include "amma/Num/NumLabel.hh" #include "amma/BRefCnt.hh" #include "amma/BRefCntPtr.hh" #include "amma/IndNeig2.hh" #include "amma/SArray1d.hh" // -------------------------------------------------------------------------- // ********** RegBoundaryBC *********************************************** // -------------------------------------------------------------------------- //: Stores a region boundary as well as statistcs // // This is an implementation or body class. As a result the handle class // RegBoundaryC should be used.

// // Used by RegOrderedGrowC to represent intermediate stages in the region // growing process. It stores a labelled image of the region as well as // statistics of the region and boundary. The statistics are updated // incrementally when a pixel is added to the region.

class RegBoundaryBC: public BodyRefCounterC { private: PriQueueLC _queue; //: Priority queue of points in current boundary // Top of queue is the next point on the boundary to be added to the region ByteImageC _image; //: Scratch buffer which represents the region // Pixels are labelled according to whether they are background, current // boundary, internal boundary or region. Note that points in the internal // boundary are also in the region. ImageRectangleC _limit; //: Bounding box for growing the current boundary // The segmentation algorithm will not include points outside this boundary. ImageRectangleC _bound; //: Bounding box on the region NumLabelC _label; //: Label assigned to the region NumLabelC _cluster; //: Label assigned during motion clustering Vector2dC _meanPos; //: Centre of mass of the region Vector2dC _motion; //: Estimated motion vector for the region Moments012d2C _moments; //: 2nd order moments of the region BRCPtrC _previous; //: Handle to region in previous image. RealT _regionAverage; //: Average intensity of the region RealT _currentAverage; //: Average intensity of the current boundary RealT _internalAverage; //: Average intensity of the internal boundary UIntT _numRegionPixels; //: Number of pixels in the region UIntT _numCurrentPixels; //: Number of pixels in the current boundary UIntT _numInternalPixels; //: Number of pixels in the internal boundary void AddRegion (RealT val, const PixelC &pos); //: Adds a pixel to the region statistics //!param: val - pixel intensity //!param: pos - pixel position void AddCurrent (RealT val, const PixelC &pos); //: Adds a pixel to the current boundary statistics //!param: val - pixel intensity //!param: pos - pixel position void SubCurrent (RealT val); //: Removes a pixel from the current boundary statistics void AddInternal (RealT val); //: Adds a pixel to the internal boundary statistics void SubInternal (RealT val); //: Removes a pixel from the internal boundary statistics enum RegLabelsT {LabelExternal=0, LabelCurrent, LabelInternal, LabelRegion}; //: Scratch growing buffer value definitions public: RegBoundaryBC (const ImageRectangleC &rect, const NumLabelC &label); //: Constructor //!param: rect - image rectangle of the scene for segmentation buffer //!param: label - label to assign to this region RegBoundaryBC (const RegBoundaryBC &oth); //: Copy constructor clips label image // Makes a completely new copy. RegBoundaryBC & Copy () const; //: Makes a deep copy protected: void AddPixel (const PixelC &pos, const ByteImageC &scene); RealT AverageContrast () const; RealT GradientContrast () const; RealT Compactness () const; //: Ratio of perimeter to area const PixelC GetNextPixel (); //: Finds next pixel from the current boundary // Uses a priority queue to do this. Points are added to the queue in // AddPixel but it is removed here. void AddRegionToImage (ImageC &image) const; //: Inserts labelled region into image // The region is labelled with the value specified in the constructor. The // boundary is labelled with the same value with bit 16 set. void AddOverlayToImage (RGBImageC &scene, const ByteRGBValueC &colour) const; //: Inserts overlay of region into image //!param: scene - colour image of the scene //!param: colour - colour to use for labelling region boundaries // The internal boundary of the region is labelled in the scene image as // pixels with the specified colour. NumLabelC GetLabel () const; //: Access to the label of the region void SetLabel (const NumLabelC &label); //: Specify a label value for the region NumLabelC GetCluster () const; //: Access to the motion cluster of the region void SetCluster (const NumLabelC &label); //: Specify a motion cluster value for the region UIntT GetRegionSize () const; //: The number of pixels in the region Vector2dC GetMeanPos () const; //: Centre of mass of the region Vector2dC GetMotion () const; //: Motion vector of the region void SetMotion (Vector2dC motion); //: Specify the motion vector of the region Matrix2d2C GetMoments () const; //: Gets 2nd order moments of region as a covariance matrix void SetPreviousRegion (RegBoundaryBC &previous); //: Sets a handle to previous region // This is used to track the history of the region. At each point in time // there is a handle to the region at the previous point in time. This is // set during motion tracking. RegBoundaryBC & PreviousRegion (); //: Gets handle to same region in previous image IndexNeigh2dC GetNeighbourhood () const; //: Returns neighbourhood list of pixels in the region friend class RegBoundaryC; //: Handle class }; #endif