00001
00002
00003 #ifndef _SEGMENTS_PLUS_BASE_H_
00004 #define _SEGMENTS_PLUS_BASE_H_
00005
00006 #include <vector>
00007 #include <map>
00008
00009 #include <kernel/jafarMacro.hpp>
00010 #include <image/Image.hpp>
00011 #include <jmath/jblas.hpp>
00012
00013 namespace jafar {
00014 namespace dseg {
00015 class SegmentsSet;
00016 class SegmentProbabilityEstimator;
00017 class SegmentHypothesis;
00018 class GrowStopCondition;
00019 struct PreprocessedImage {
00020 jafar::image::Image image;
00021 jafar::image::Image proba;
00022 jafar::image::Image dx;
00023 jafar::image::Image dy;
00024 jafar::image::Image inasegment;
00025 };
00026 struct SegmentDebug {
00027 jafar::image::Image inasegment;
00028 jafar::image::Image proba;
00029 jafar::image::Image dx;
00030 jafar::image::Image dy;
00031 };
00032 struct GrowSegmentContext {
00033 SegmentHypothesis* segHyp;
00034 jafar::image::Image originalImage;
00035 jafar::image::Image proba;
00036 jafar::image::Image dx;
00037 jafar::image::Image dy;
00038 jafar::image::Image* inasegment;
00039 std::map<int, int> segmentToCount;
00040 double x_1;
00041 double x_2;
00042 double y_1;
00043 double y_2;
00044 int k_p;
00045 int k_n;
00046 GrowStopCondition* growStopCondition;
00047 };
00053 class DirectSegmentsBase {
00054 public:
00055 DirectSegmentsBase();
00056 virtual ~DirectSegmentsBase();
00057 protected:
00058 bool searchPoint( GrowSegmentContext& _context, double _searchStep, const jblas::vec2& _pi, double& _xr, double& _yr, double& _angler, int& _bestI, int _searchNbSteps);
00059 bool smartSearchPoint( GrowSegmentContext& _context, double _searchStep, const jblas::vec2& _pi, double& _xr, double& _yr, double& _angler, int& _bestI, int _searchNbSteps);
00060 void coloriage( double x_1, double y_1, double x_2, double y_2, image::Image& inasegment, int _value);
00063 void computeGradientValuesOnLine( double& a, double& b, double angle, double cosA, double sinA, float* _mag1, float* _mag2, float* _mag3, int j ) const;
00064 bool hasMaximumGradient( double _angle, double _cosA, double _sinA, float* _mag1 , float* _mag2, float* _mag3, int j ) const;
00065 bool growSegment( GrowSegmentContext& _context, int _step = 1 );
00066 SegmentHypothesis* attemptToMerge( SegmentHypothesis* segHyp, const image::Image& inasegment, SegmentsSet& segmentHypothesises , const std::map<int, int>& segmentToCount);
00067 private:
00072 JFR_DEFINE_PARAM_RW( int, searchNbSteps, setSearchNbSteps)
00078 JFR_DEFINE_PARAM_RW( double, maximalSearchStep, setMaximalSearchStep)
00083 JFR_DEFINE_PARAM_RW( double, thresholdGradColinearity, setThresholdGradColinearity )
00089 JFR_DEFINE_PARAM_RW( double, thresholdMaxGradient, setThresholdMaxGradient )
00093 JFR_DEFINE_PARAM_RO( double, minimumSegmentLength)
00097 JFR_DEFINE_PARAM_RW( SegmentProbabilityEstimator*, segmentProbabilityEstimator, setSegmentProbabilityEstimator )
00101 JFR_DEFINE_PARAM_RW( double, maximalSearchLength, setMaximalSearchLength)
00102 public:
00103 void setMinimumSegmentLength(double _minimumSegmentLength);
00104 protected:
00105 double minimumSegmentLengthPow2() const;
00106 protected:
00107 int segCount;
00108 void adjustStep( double& _step, int &_searchNbSteps ) const;
00109 private:
00110 double m_minimumSegmentLengthPow2;
00111 };
00112 }
00113 }
00114
00115
00116 #endif