Skip to content

Commit

Permalink
Merge branch 'mpd'
Browse files Browse the repository at this point in the history
  • Loading branch information
deseilligny committed Jun 10, 2024
2 parents b6619df + 0197e01 commit f7591b3
Show file tree
Hide file tree
Showing 31 changed files with 1,765 additions and 101 deletions.
11 changes: 11 additions & 0 deletions MMVII/Doc/Methods/CodedTarget-Theory.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
\chapter{Coded target}
\label{Chap:CodedTarget}

%-----------------------------------------------------------------------
%-----------------------------------------------------------------------
%-----------------------------------------------------------------------

\section{Todo}

\begin{itemize}
\item {\tt 2023-12-14-CurTestClino/Calib-1/Processing/} target partially occluded are recognized as others,
for example {\tt 043\_0078.JPG}, target {\tt 66 (?)} is interpreted as {\tt 34} ;
\end{itemize}


%-----------------------------------------------------------------------
%-----------------------------------------------------------------------
Expand Down
78 changes: 73 additions & 5 deletions MMVII/include/MMVII_2Include_Tiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ template <const int Dim> bool EqualPt(const cPtxd<tREAL8,Dim> & aP1,const cPtxd
*/


template <class Type> class cTiling : public cTilingIndex<Type::Dim>
template <class Type> class cTiling : public cTilingIndex<Type::TheDim>
{
public :
typedef cTilingIndex<Type::Dim> tTI;
typedef cTilingIndex<Type::TheDim> tTI;
typedef typename tTI::tRBox tRBox;
typedef typename tTI::tRPt tRPt;
typedef typename tTI::tIPt tIPt;

typedef typename Type::tPrimGeom tPrimGeom;
typedef typename Type::tArgPG tArgPG;
static constexpr int Dim = Type::Dim;
static constexpr int Dim = Type::TheDim;

typedef std::list<Type> tCont1Tile;
typedef std::vector<tCont1Tile> tVectTiles;
Expand Down Expand Up @@ -248,14 +248,21 @@ FakeUseIt(aDistWMargin);
tArgPG mArgPG;
};


/** We consider 2d point that are valuated with z()
* Extract point that do not contain any point > in a neighbourhood of size aDist,
* Non Const vect because they are sorted at the begining of process
*/
std::vector<cPt3dr> FilterMaxLoc(std::vector<cPt3dr> & aVpt,tREAL8 aDist);

/** Sometime we only need to put points in a spatial index, this
* class make the interface allowing to use simple point in spatial indexing
*/

template <const int TheDim> class cPointSpInd
template <const int Dim> class cPointSpInd
{
public :
static constexpr int Dim = TheDim;
static constexpr int TheDim = Dim;
typedef cPtxd<tREAL8,TheDim> tPrimGeom;
typedef int tArgPG; /// unused here

Expand Down Expand Up @@ -293,6 +300,67 @@ template <const int TheDim> class cGeneratePointDiff
};


template <class TypePrim,class TypeObj,class TypeCalcP2 >
void IndexeseFilterMaxLoc
(
TypePrim *, // Type specifier
std::vector<int> & aVInd,
const std::vector<TypeObj> & aVPt,
const TypeCalcP2 & aCalc,
tREAL8 aDist
)
{
// compute box of points
cTplBoxOfPts<tREAL8,TypePrim::TheDim> aBoxOfPt;
for (const auto & aPt : aVPt)
aBoxOfPt.Add(aCalc(aPt));

cTplBox<tREAL8,TypePrim::TheDim> aBox = aBoxOfPt.CurBox();

// estimate number of case
int aNbCase = std::min
(
round_up(aVPt.size()/30.0) ,
round_up( 0.1*(aBox.NbElem()/pow(aDist,TypePrim::TheDim)) )
);


// creat tiling + clear indexe
cTiling<cPointSpInd<TypePrim::TheDim>> aTiling(aBox,true,aNbCase,-1);
aVInd.clear();

// parse and add
for (size_t aKPt=0 ; aKPt<aVPt.size(); aKPt++)
{
auto aLpt = aTiling.GetObjAtDist(aCalc(aVPt.at(aKPt)),aDist);
if (aLpt.empty())
{
aTiling.Add(aCalc(aVPt.at(aKPt)));
aVInd.push_back(aKPt);
}
}
}

template <class TypePrim,class TypeObj,class TypeCalcP2 >
std::vector<TypeObj>
FilterMaxLoc
(
TypePrim *, // Type specifier
const std::vector<TypeObj> & aVPt,
const TypeCalcP2 & aCalc,
tREAL8 aDist
)
{
std::vector<int> aVInd;
IndexeseFilterMaxLoc((TypePrim*) nullptr,aVInd,aVPt,aCalc,aDist);

std::vector<TypeObj> aRes;
for (const auto & aInd : aVInd)
aRes.push_back(aVPt.at(aInd));
return aRes;
}



};
#endif // _MMVII_Tiling_H_
48 changes: 48 additions & 0 deletions MMVII/include/MMVII_ExtractLines.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef _MMVII_EXTRACT_LINES_H_
#define _MMVII_EXTRACT_LINES_H_

#include "MMVII_Image2D.h"
#include "MMVII_Interpolators.h"
#include "MMVII_Mappings.h"


namespace MMVII
Expand Down Expand Up @@ -251,6 +254,51 @@ template <class Type> class cExtractLines
std::vector<cPt2di> mPtsCont; ///< List of point in mImMasqCont
};


/** Class for extracting a line arround a point, for now its very specialized in the extraction of
* direction in checkboard, may evolve to things more general ?
*/

class cScoreTetaLine : public tFunc1DReal // herit from tFunc1DReal for optimization in cOptimByStep
{
public :
/// constructor : aL length of the segment, aStep step of discretization in a segment
cScoreTetaLine(cDataIm2D<tREAL4> &,const cDiffInterpolator1D & ,tREAL8 aL,tREAL8 aStep);

/// extract the 2 angle of line in checkboar, aStepInit & aStepLim => used in cOptimByStep
std::pair<tREAL8,tREAL8> Tetas_CheckBoard(const cPt2dr& aC,tREAL8 aStepInit,tREAL8 aStepLim);

typedef tREAL8 t2Teta[2];
/// Assure that teta1->teta2 is trigo and teta1<Pi
static void NormalizeTeta(t2Teta &);

const tREAL8 & Length() const; ///< Accessor
cDataIm2D<tREAL4> * DIm() const; ///< Accessor

private :

/// fix center of reusing the data (to avoid cost for cTabulatedDiffInterpolator)
void SetCenter(const cPt2dr & aC);

/// Extract the initial values of tetas by testing all at a given step (in pixel)
tREAL8 GetTetasInit(tREAL8 aStepPix,int aCurSign);
/// Refine the value with a limit step in pixel
tREAL8 Refine(tREAL8 aTeta0,tREAL8 aStepPix,int aSign);

/// Value as tFunc1DReal
cPt1dr Value(const cPt1dr& aPt) const override;

cDataIm2D<tREAL4> * mDIm;
tREAL8 mLength;
int mNb;
tREAL8 mStepAbsc;
tREAL8 mStepTeta;
cTabulatedDiffInterpolator mTabInt;
cPt2dr mC;
tREAL8 mCurSign; /// used to specify an orientaion of segment
};


};
#endif // _MMVII_EXTRACT_LINES_H_
//
7 changes: 7 additions & 0 deletions MMVII/include/MMVII_Geom2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace MMVII
typedef cSegment<tREAL8,2> tSeg2dr;



/** \file MMVII_Geom2D.h
\brief contain classes for geometric manipulation, specific to 2D space :
2D line, 2D plane, rotation, ...
Expand Down Expand Up @@ -95,10 +96,16 @@ template <class Type> class cSegment2DCompiled : public cSegmentCompiled<Type,2>
Type Dist(const tPt& aPt) const; ///< Faster than upper class
const tPt & Normal() const {return mNorm;}


tPt InterSeg(const cSegment2DCompiled<Type> &,tREAL8 aMinAngle=1e-5,bool *IsOk=nullptr);
private :
tPt mNorm;
};

/** this class a represent a "closed" segment , it has same data than cSegment2DCompiled,
* but as a set/geometric primitive, it is limited by extremities
*/

class cClosedSeg2D
{
public :
Expand Down
55 changes: 55 additions & 0 deletions MMVII/include/MMVII_HeuristikOpt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef _MMVII_Heuristik_Opt_H_
#define _MMVII_Heuristik_Opt_H_

#include "MMVII_Ptxd.h"


namespace MMVII
{

/** \file "MMVII_HeuristikOpt.h"
\brief Declaration functionnalities for optimization that are not based on local linearization,
typicall used on image matching
*/

/** Class for optimizing by local descent function that are not differenciable. Method :
*
* - multi-step approach
* - iteratively research the optimum in a neigourhood (for example can be V4 or V8 if dim=2)
* - take cautious not to visit twice the same point (this is the only "non trivial part")
*/

typedef std::vector<std::list<int>> tVLInt;

template <const int Dim> class cOptimByStep
{
public :
typedef cPtxd<tREAL8,Dim> tPtR;
typedef cPtxd<int,Dim> tPtI;
typedef cDataMapping<tREAL8,Dim,1> tMap;

cOptimByStep(const tMap & aMap,bool IsMin,tREAL8 aMaxDInfInit,int aDist1Max=Dim);
std::pair<tREAL8,tPtR> Optim(const tPtR & ,tREAL8 aStepInit,tREAL8 aStepLim,tREAL8 aMul=0.5);

private :
std::pair<tREAL8,tPtR> CurValue() const;
bool DoOneStep(tREAL8 aStep); ///< return false if point go too far from init
// void OneStep(const tPtR
tREAL8 Value(const tPtR& aPt) const;

const tMap & mFunc; ///< contain the func to optimize
tREAL8 mSign; ///< +1 for min, -1 for max
cWhichMin<tPtR,tREAL8> mWMin; ///< store best result and arg-best
tREAL8 mMaxDInfInit; ///< maximal dist to initial value we accept
int mDist1Max; ///< max dist-1 of neighboorhooud
std::vector<cPtxd<int,Dim>> mINeigh; ///< list of integer neighboorhoud
const tVLInt & mIndNextN; ///< given last neigh, will give fast access to next neigh
tPtR mPt0; ///< memorize init point to avoid we go too far

};



}; // namespace MMVII

#endif // _MMVII_Heuristik_Opt_H_
2 changes: 2 additions & 0 deletions MMVII/include/MMVII_Image2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ class cRGBImage
void Write(const std::string &,const cPt2di & aP0,double aDyn=1,const cRect2& =cRect2::TheEmptyBox) const; // 1 to 1
/*
*/
// transformate the RGB internal image in gray
void ResetGray();

/// set values iff param are OK, RGB image are made for visu, not for intensive computation
void SetRGBPix(const cPt2di & aPix,int aR,int aG,int aB);
Expand Down
109 changes: 109 additions & 0 deletions MMVII/include/MMVII_ImageMorphoMath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#ifndef _MMVII_MorphoMat_H_
#define _MMVII_MorphoMat_H_

#include "MMVII_Image2D.h"


namespace MMVII
{

/** \file "MMVII_ImageMorphoMath.h"
\brief Declaration functionnalities for morpho-mat & graph like processing
*/

/* *********************************************** */
/* */
/* Graph & Flag of bits */
/* */
/* *********************************************** */

/** Class for representing the connected component of 8-neigboorhoud, using Freeman code */

class cCCOfOrdNeigh
{
public :
bool mIs1; // is it a component with 1
int mFirstBit; // First neighboor (include)
int mLastBit; // last neighboor (exclude)
};


/// class for storing a subset of neighboors as flag of bit on Freman neighbourhood


class cFlag8Neigh
{
public :

cFlag8Neigh() : mFlag(0) {}
cFlag8Neigh(tU_INT1 aFlag) : mFlag(aFlag) {}

/// If bit to 1 , safe because work with bit<0 or bit>=8 (a bit slower ...)
inline bool SafeIsIn(size_t aBit) const { return (mFlag& (1<<mod(aBit,8))) != 0; }

inline void AddNeigh(size_t aBit) { mFlag |= (1<<aBit); }

/** return the description of 4-connected component of neigbourhoud
* WARN : case empty of full (flag 0/255) generate no components, which can be good or not,
* eventually will add the other option
*/
inline const std::vector<cCCOfOrdNeigh> & ConComp() const
{
static std::vector<std::vector<cCCOfOrdNeigh> > aVCC;
static bool First=true;
if (First)
{
First = false;
ComputeCCOfeNeigh(aVCC);
}
return aVCC.at(mFlag);
}

/// compute the number of connected component of a given neighbourhood flag
inline int NbConComp() const { return ConComp().size(); }

private :
tU_INT1 mFlag;

static void ComputeCCOfeNeigh(std::vector<std::vector<cCCOfOrdNeigh>> & aVCC);
};

/** Compute, as a flag of bit, the set of Fremaan-8 neighboor that are > over a pixel,
* to have a strict order, for value==, the comparison is done on Y then X */
template <class Type> cFlag8Neigh FlagSup8Neigh(const cDataIm2D<Type> & aDIm,const cPt2di & aPt);


/** Given a point, that is a "topologicall saddle" (i.e multiple connected component of points >) ,
* carecterize the "importance" of saddle */
template <class Type> tREAL8 CriterionTopoSadle(const cDataIm2D<Type> & aDIm,const cPt2di & aPixC);


/** Put in vector "VPts", the connected component of a seed , of point having the same colour in Image,
* update with "NewMarq" */

void ConnectedComponent
(
std::vector<cPt2di> & aVPts, // Vector of results
cDataIm2D<tU_INT1> & aDIm, // Image marquing point of CC to compute
const std::vector<cPt2di> & aNeighbourhood, // generally 4 or 8 neighbourhood
const std::vector<cPt2di>& aSeed, // seeds of the connected component
int aMarqInit=1, // will extract CC of point having this colour
int aNewMarq=0, // will marq points reached with this colour
bool Restore=false // if true restore initial marq at end
);

/** Idem, current and simplified case where the seed is a single point */
void ConnectedComponent
(
std::vector<cPt2di> & , cDataIm2D<tU_INT1> & , const std::vector<cPt2di> & aNeighbourhood,
const cPt2di& aSeed, // seed of the connected component
int aMarqInit=1, int aNewMarq=0, bool Restore=false
);

};





#endif // _MMVII_MorphoMat_H_
Loading

0 comments on commit f7591b3

Please sign in to comment.