Skip to content

Commit

Permalink
Chg ordi
Browse files Browse the repository at this point in the history
  • Loading branch information
deseilligny committed Mar 10, 2023
1 parent 013e158 commit 8282489
Showing 1 changed file with 94 additions and 76 deletions.
170 changes: 94 additions & 76 deletions MMVII/src/CodedTarget/cCircTargetExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ using namespace cNS_CodedTarget;
/* */
/* ********************************************* */

/** Store the result of a validated extracted circular target
*/

class cCircTargExtr
{
public :
cCircTargExtr(const cExtractedEllipse &);

cEllipse mEllipse;
tREAL8 mBlack;
tREAL8 mWhite;
Expand All @@ -51,6 +55,11 @@ cCircTargExtr::cCircTargExtr(const cExtractedEllipse & anEE) :
/* */
/* ********************************************* */

/** Class for computing the circular code: make a polar representation , offers mapping polar/cart
*
*
* */

class cCCDecode
{
public :
Expand All @@ -63,17 +72,19 @@ class cCCDecode
const cOneEncoding * EnCode() const;
private :

tREAL8 Dev(int aK1,int aK2) const;
tREAL8 Avg(int aK1,int aK2) const;
tREAL8 DevOfPhase(int aK0) const;

tREAL8 K2Rho (int aK) const;
tREAL8 K2Teta(int aK) const;
int Rho2K (tREAL8 aR) const;
cPt2dr KTetaRho2Im(const cPt2di & aKTetaRho) const;
// Aggregation
tREAL8 StdDev(int aK1,int aK2) const; ///< standard deviation of the interval
tREAL8 Avg(int aK1,int aK2) const; ///< average of the interval
tREAL8 TotalStdDevOfPhase(int aK0) const; ///< Sum of standard dev, on all interval, for a given stard

// Geometric correspondances
tREAL8 K2Rho (int aK) const; /// index of rho 2 real rho
tREAL8 K2Teta(int aK) const; /// index of teta 2 real teta
int Rho2K (tREAL8 aR) const; /// real rho 2 index of rho
cPt2dr KTetaRho2Im(const cPt2di & aKTetaRho) const; /// index rho-teta 2 cartesian coordinates
tREAL8 RhoOfWeight(const tREAL8 &) const;


cCircTargExtr & mEE;
const cDataIm2D<tREAL4> & mDIm;
const cFullSpecifTarget & mSpec;
Expand All @@ -100,8 +111,75 @@ class cCCDecode
const cOneEncoding * mEnCode;
};

// ============== constructor ============================

cCCDecode::cCCDecode(cCircTargExtr & anEE,const cDataIm2D<tREAL4> & aDIm,const cFullSpecifTarget & aSpec) :
mEE (anEE),
mDIm (aDIm),
mSpec (aSpec),
mOK (true),
mPixPerB (10),
mNbRho (20),
mNbB (mSpec.NbBits()),
mNbTeta (mPixPerB * mNbB),
mRho0 ((mSpec.Rho_0_EndCCB()+mSpec.Rho_1_BeginCode()) /2.0),
mRho1 (mSpec.Rho_2_EndCode() +0.2),
mImPolar (cPt2di(mNbTeta,mNbRho)),
mDIP (mImPolar.DIm()),
mAvg ( mNbTeta,nullptr,eModeInitImage::eMIA_Null ),
mDAvg ( mAvg.DIm()),
mKR0 ( Rho2K(RhoOfWeight(0.25)) ) ,
mKR1 ( Rho2K(RhoOfWeight(0.75)) ) ,
mPhase0 (-1),
mBlack (mEE.mBlack),
mWhite (mEE.mWhite),
mBWAmpl (mWhite-mBlack),
mBWAvg ((mBlack+mWhite)/2.0),
mEnCode (nullptr)
{

// compute a polar image
for (int aKTeta=0 ; aKTeta < mNbTeta; aKTeta++)
{
for (int aKRho=0 ; aKRho < mNbRho; aKRho++)
{
cPt2dr aPt = KTetaRho2Im(cPt2di(aKTeta,aKRho));
tREAL8 aVal = mDIm.DefGetVBL(aPt,-1);
if (aVal<0)
{
mOK=false;
return;
}

mDIP.SetV(cPt2di(aKTeta,aKRho),aVal);
}
}

if (!mOK)
return;

// compute an image
for (int aKTeta=0 ; aKTeta < mNbTeta; aKTeta++)
{
std::vector<tREAL8> aVGray;
for (int aKRho=mKR0 ; aKRho <= mKR1; aKRho++)
{
aVGray.push_back(mDIP.GetV(cPt2di(aKTeta,aKRho)));
}
mDAvg.SetV(aKTeta,NonConstMediane(aVGray));
}

ComputePhaseTeta() ;
if (!mOK) return;

ComputeCode(true);
if (!mOK) return;
}

// ============= Agregation on interval : StdDev , Avg, TotalStdDevOfPhase ====


tREAL8 cCCDecode::Dev(int aK1,int aK2) const
tREAL8 cCCDecode::StdDev(int aK1,int aK2) const
{
cComputeStdDev<tREAL8> aCS;
for (int aK=aK1 ; aK<aK2 ; aK++)
Expand All @@ -121,28 +199,31 @@ tREAL8 cCCDecode::Avg(int aK1,int aK2) const
return aSom / (aK2-aK1);
}

tREAL8 cCCDecode::DevOfPhase(int aK0) const
tREAL8 cCCDecode::TotalStdDevOfPhase(int aK0) const
{
tREAL8 aSum=0;
for (int aKBit=0 ; aKBit<mNbB ; aKBit++)
{
int aK1 = aK0+aKBit*mPixPerB;
aSum += Dev(aK1+1,aK1+mPixPerB-1);
aSum += StdDev(aK1+1,aK1+mPixPerB-1);
}

return aSum / mNbB;
}


//=================

void cCCDecode::ComputePhaseTeta()
{
cWhichMin<int,tREAL8> aMinDev;

for (int aK0=0 ;aK0< mPixPerB ; aK0++)
aMinDev.Add(aK0,DevOfPhase(aK0));
aMinDev.Add(aK0,TotalStdDevOfPhase(aK0));

mPhase0 = aMinDev.IndexExtre();

if ( (aMinDev.ValExtre() > 0.1 * Dev(0,mNbTeta))
if ( (aMinDev.ValExtre() > 0.1 * StdDev(0,mNbTeta))
|| (aMinDev.ValExtre() > 0.05 * mBWAmpl)
)
{
Expand Down Expand Up @@ -206,69 +287,6 @@ tREAL8 cCCDecode::RhoOfWeight(const tREAL8 & aW) const
return (1-aW) * mSpec.Rho_1_BeginCode() + aW * mSpec.Rho_2_EndCode();
}

cCCDecode::cCCDecode(cCircTargExtr & anEE,const cDataIm2D<tREAL4> & aDIm,const cFullSpecifTarget & aSpec) :
mEE (anEE),
mDIm (aDIm),
mSpec (aSpec),
mOK (true),
mPixPerB (10),
mNbRho (20),
mNbB (mSpec.NbBits()),
mNbTeta (mPixPerB * mNbB),
mRho0 ((mSpec.Rho_0_EndCCB()+mSpec.Rho_1_BeginCode()) /2.0),
mRho1 (mSpec.Rho_2_EndCode() +0.2),
mImPolar (cPt2di(mNbTeta,mNbRho)),
mDIP (mImPolar.DIm()),
mAvg ( mNbTeta,nullptr,eModeInitImage::eMIA_Null ),
mDAvg ( mAvg.DIm()),
mKR0 ( Rho2K(RhoOfWeight(0.25)) ) ,
mKR1 ( Rho2K(RhoOfWeight(0.75)) ) ,
mPhase0 (-1),
mBlack (mEE.mBlack),
mWhite (mEE.mWhite),
mBWAmpl (mWhite-mBlack),
mBWAvg ((mBlack+mWhite)/2.0),
mEnCode (nullptr)
{

// compute a polar image
for (int aKTeta=0 ; aKTeta < mNbTeta; aKTeta++)
{
for (int aKRho=0 ; aKRho < mNbRho; aKRho++)
{
cPt2dr aPt = KTetaRho2Im(cPt2di(aKTeta,aKRho));
tREAL8 aVal = mDIm.DefGetVBL(aPt,-1);
if (aVal<0)
{
mOK=false;
return;
}

mDIP.SetV(cPt2di(aKTeta,aKRho),aVal);
}
}

if (!mOK)
return;

// compute an image
for (int aKTeta=0 ; aKTeta < mNbTeta; aKTeta++)
{
std::vector<tREAL8> aVGray;
for (int aKRho=mKR0 ; aKRho <= mKR1; aKRho++)
{
aVGray.push_back(mDIP.GetV(cPt2di(aKTeta,aKRho)));
}
mDAvg.SetV(aKTeta,NonConstMediane(aVGray));
}

ComputePhaseTeta() ;
if (!mOK) return;

ComputeCode(true);
if (!mOK) return;
}



void cCCDecode::Show(const std::string & aPrefix)
Expand Down

0 comments on commit 8282489

Please sign in to comment.