Skip to content

Commit

Permalink
Merge branch 'mpd'
Browse files Browse the repository at this point in the history
  • Loading branch information
deseilligny committed Dec 16, 2024
2 parents 05d17a9 + 00a5164 commit e27e930
Show file tree
Hide file tree
Showing 15 changed files with 838 additions and 150 deletions.
2 changes: 2 additions & 0 deletions MMVII/include/MMVII_Bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ void BenchBaseImage(); ///< Global bench on image
void BenchImNDim();
void BenchIm3D(); ///< Bench on fulll 3D Images + "Layer" images


void BenchGlobImage2d(); ///< Global bench on image
void BenchFileImage(); ///< Global bench on image
void BenchImFilterV1V2(); ///< Temporary, check that new implementation are close enough to V1's


void TestTimeV1V2(); ///< Not a formal Bench, require visual inspection
Expand Down
2 changes: 1 addition & 1 deletion MMVII/include/MMVII_ImageInfoExtract.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ double ValueStableInterpoleExtr(double V1,double V2,double V3);


template <class Type> double MoyAbs(cIm2D<Type> aImIn); ///< Compute average of Abs of Image
template <class Type> cPt2dr ValExtre(cIm2D<Type> aImIn); ///< X -> Min, Y -> Max
template <class Type> std::pair<Type,Type> ValExtre(cIm2D<Type> aImIn); ///< X -> Min, Y -> Max

/// Class to store results of extremum
struct cResultExtremum
Expand Down
1 change: 1 addition & 0 deletions MMVII/include/MMVII_Images.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ template <class Type,const int Dim> class cDataTypedIm : public cDataGenUnTypedI
double L2Dist(const cDataTypedIm<Type,Dim> & aV,bool Avg=true) const; ///< Dist som square
double SqL2Dist(const cDataTypedIm<Type,Dim> & aV,bool Avg=true) const; ///< Square L2Dist
double LInfDist(const cDataTypedIm<Type,Dim> & aV) const; ///< Dist max
double SafeMaxRelDif(const cDataTypedIm<Type,Dim> & aV,tREAL8 aEps) const; ///< Maximal safe relative dif
double L1Norm(bool Avg=true) const; ///< Norm som abs
double L2Norm(bool Avg=true) const; ///< Norm square
double LInfNorm() const; ///< Nomr max
Expand Down
10 changes: 8 additions & 2 deletions MMVII/include/MMVII_NonLinear2DFiltering.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ template <class Type> void SelfLabMaj(cIm2D<Type> aImIn,const cBox2di &);


/// Basic laplacien
cIm2D<tREAL4> Lapl(cIm2D<tREAL4> aImIn); // Well linear ...
template <class Type> cIm2D<Type> Lapl(cIm2D<Type> aImIn); // Well linear ...

/// return the label majoritar in a neighbourhood
template<class Type> cIm2D<Type> LabMaj(cIm2D<Type> aImIn,const cBox2di &);



/// Extincion function = dist of image (V!=0) to its complementar (V==0)
void MakeImageDist(cIm2D<tU_INT1> aImIn,const std::string & aNameChamfer="32");
// No longer implemented, used MMV1
// void MakeImageDist(cIm2D<tU_INT1> aImIn,const std::string & aNameChamfer="32");



Expand Down
1 change: 1 addition & 0 deletions MMVII/include/MMVII_SysCo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _MMVII_SYSCO_H_
#define _MMVII_SYSCO_H_


#include "MMVII_DeclareCste.h"
#include "MMVII_Mappings.h"
#include "MMVII_AllClassDeclare.h"
Expand Down
6 changes: 6 additions & 0 deletions MMVII/include/MMVII_nums.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ double RandInInterval(double a,double b); ///< Uniform distribution in [a,b]
double RandInInterval(const cPt2dr &interval); ///< Uniform distribution in [interval.x,interval.y]
double RandInInterval_C(const cPt2dr &interval); ///< Uniform distribution in [-interval.y,-interval.x]U[interval.x,interval.y]

int RandUnif_M_N(int aM,int aN); ///< Uniform disrtibution in [M,N]

/** Class for mapping object R->R */
class cFctrRR
{
Expand Down Expand Up @@ -324,6 +326,8 @@ template <> class tElemNumTrait<tINT2> : public tBaseNumTrait<tStdInt>
{
public :
static tINT2 DummyVal() {MMVII_INTERNAL_ERROR("No DummyVal for type");return 0;}
static tINT2 MaxVal() {return std::numeric_limits<tINT2>::max();}
static tINT2 MinVal() {return std::numeric_limits<tINT2>::min();}
static bool Signed() {return true;}
static eTyNums TyNum() {return eTyNums::eTN_INT2;}
typedef tREAL4 tFloatAssoc;
Expand Down Expand Up @@ -353,6 +357,8 @@ template <> class tElemNumTrait<tINT8> : public tBaseNumTrait<tINT8>
template <> class tElemNumTrait<tREAL4> : public tBaseNumTrait<tStdDouble>
{
public :
static tREAL4 MaxVal() {return std::numeric_limits<tREAL4>::max();}
static tREAL4 MinVal() {return std::numeric_limits<tREAL4>::min();}
static tREAL4 DummyVal() {return std::nanf("");}
static tREAL4 Accuracy() {return 1e-2f;}
static bool Signed() {return true;} ///< Not usefull but have same interface
Expand Down
2 changes: 1 addition & 1 deletion MMVII/include/V1VII.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template <class Type> std::string ToStrComMMV1(const cTplBox<Type,2> & aBox)
void ExportHomMMV1(const std::string & aIm1,const std::string & aIm2,const std::string & SH,const std::vector<cPt2di> & aVP);
void ExportHomMMV1(const std::string & aIm1,const std::string & aIm2,const std::string & SH,const std::vector<cPt2dr> & aVP);

void MakeStdIm8BIts(cIm2D<tREAL4> aImIn,const std::string& aName);
void MakeStdIm8BIts(const cIm2D<tREAL4> &aImIn,const std::string& aName);



Expand Down
1 change: 1 addition & 0 deletions MMVII/src/Bench/BenchImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ void BenchGlobImage(cParamExeBench & aParam)
BenchRectObj();
BenchBaseImage();
BenchGlobImage2d();
BenchImFilterV1V2();

aParam.EndBench();
}
Expand Down
14 changes: 14 additions & 0 deletions MMVII/src/ImagesBase/BaseImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ template <class Type,const int Dim>
}


template <class Type,const int Dim>
double cDataTypedIm<Type,Dim>::SafeMaxRelDif(const cDataTypedIm<Type,Dim> & aI2,tREAL8 aEps) const
{
tPB::AssertSameArea(aI2);
double aRes = 0;
for (int aK=0 ; aK<NbElem() ; aK++)
{
tREAL8 aV1 = mRawDataLin[aK];
tREAL8 aV2 = aI2.mRawDataLin[aK];
UpdateMax(aRes,fabs(aV1-aV2)/std::max(aEps,std::max(std::fabs(aV1),std::fabs(aV2))));
}

return aRes;
}

template <class Type,const int Dim>
double cDataTypedIm<Type,Dim>::LInfDist(const cDataTypedIm<Type,Dim> & aI2) const
Expand Down
240 changes: 240 additions & 0 deletions MMVII/src/ImagesFiltrLinear/Deriche.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
#include "MMVII_Linear2DFiltering.h"

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

namespace MMVII
{


class Canny_Deriche_Param
{
public :
Canny_Deriche_Param(tREAL8 alpha);
tREAL8 a,a1,a2,a3,a4;
tREAL8 b1,b2;

tREAL8 mAmpl;
};

Canny_Deriche_Param::Canny_Deriche_Param(tREAL8 alpha)
{
tREAL8 exp_alpha = (tREAL8) exp( (double) - alpha);
tREAL8 exp_2alpha = exp_alpha * exp_alpha;

tREAL8 kd = - (1-exp_alpha)*(1-exp_alpha)/exp_alpha;
tREAL8 ks = (1-exp_alpha)*(1-exp_alpha)/(1+ 2*alpha*exp_alpha - exp_2alpha);

a = kd * exp_alpha;
b1 = 2 * exp_alpha;
b2 = exp_2alpha;

a1 = ks;
a2= ks * exp_alpha * (alpha-1) ;
a3 = ks * exp_alpha * (alpha+1);
a4 = ks * exp_2alpha;


mAmpl = (2*(b1-a-2*b2))/(1-b1+b2);
}

/* Merci a Canny, Rachid Deriche et Tuan Dang */

template <class TypeOut,class TypeIn>
void deriche_ll // Deriche Low Level interface
(
TypeOut * IGX,
TypeOut * IGY,
TypeIn * IE,
tINT8 DX,
tINT8 DY,
tREAL8 alpha
)
{
// TypeOut *YP, *YM;
//int i, j;

cPt2di aSz(DX,DY);

cIm2D<TypeOut> aImYP(aSz);
cIm2D<TypeOut> aImYM(aSz);

TypeOut * YP = aImYP.DIm().RawDataLin();
TypeOut * YM = aImYM.DIm().RawDataLin();


const Canny_Deriche_Param p (alpha);

/***********************************************/
/***** Derivation selon LIGNE : on fixe y *****/
/***********************************************/
/**** Filtrage de Gauche a Droite ****/
for (int i=0; i< DY; i++) {
YM[i*DX+0] = 0;
YM[i*DX+1] = 0;
for (int j=2; j< DX; j++) {
YM[i*DX+j] = p.a * (tREAL8)IE[i*DX+j-1]
+ p.b1 * YM[i*DX + j-1]
- p.b2 * YM[i*DX + j-2] ;
}
}
/**** Filtrage de Droite a Gauche ****/
for (int i=0; i< DY; i++) {
YP[i*DX+DX-1] = 0;
YP[i*DX+DX-2] = 0;
for (int j= DX-3; j >= 0; j--) {
YP[i*DX+j] = -p.a *(tREAL8)IE[i*DX+j+1]
+ p.b1 * YP[i*DX + j+1]
- p.b2 * YP[i*DX + j+2] ;
}
}
/**** Derivee selon LIGNE ****/
for (int i=0; i< DY; i++) {
for (int j=0; j< DX; j++) {
IGX[i*DX + j] = YP[i*DX + j] + YM[i*DX + j] ;

}
}
/*******************************************************************/
/***** Lissage suivant COLONNE --> composante en x du gradient *****/
/*******************************************************************/
/**** Filtrage de Gauche a Droite ****/
for (int j=0; j< DX; j++) {
YM[0*DX+j]= 0;
YM[1*DX+j]= 0;
for (int i= 2; i< DY; i++) {
YM[i*DX+j] = p.a1 * IGX[i*DX+j] + p.a2 * IGX[(i-1)*DX + j]
+ p.b1 * YM[(i-1)*DX + j] - p.b2 * YM[(i-2)*DX + j];
}
}
/**** Filtrage de Droite a Gauche ****/
for (int j=0; j< DX; j++) {
YP[(DY-1)*DX+j] =0;
YP[(DY-2)*DX+j] =0;
for (int i= DY-3; i>= 0; i--) {
YP[i*DX+j] = p.a3 * IGX[(i+1)*DX+j] - p.a4 * IGX[(i+2)*DX+j]
+ p.b1 * YP[(i+1)*DX+j] - p.b2 * YP[(i+2)*DX+j];
}
}
/**** Lissage suivant COLONNE ****/
for (int i= 0; i< DY; i++) {
for (int j= 0; j< DX; j++) {
IGX[i*DX + j] = YP[i*DX + j] + YM[i*DX + j];
}
}

/************************************************/
/***** Derivation selon COLONNE : on fixe x *****/
/************************************************/
/**** Filtrage de Gauche a Droite ****/
for (int j=0; j< DX; j++) {
YM[0*DX+j] = 0;
YM[1*DX+j] = 0;
for (int i=2; i< DY; i++) {
YM[i*DX+j] = p.a * (tREAL8)IE[(i-1)*DX+j]
+ p.b1 * YM[(i-1)*DX +j]
- p.b2 * YM[(i-2)*DX + j] ;
}
}
/**** Filtrage de Droite a Gauche ****/
for (int j=0; j< DX; j++) {
YP[(DY-1)*DX+j] = 0;
YP[(DY-2)*DX+j] = 0;
for (int i= DY-3; i >= 0; i--) {
YP[i*DX+j] = -p.a * (tREAL8)IE[(i+1)*DX+j]
+ p.b1 * YP[(i+1)*DX + j]
- p.b2 * YP[(i+2)*DX+j] ;
}
}
/**** Derivee selon COLONNE ****/
for (int i=0; i< DY; i++) {
for (int j=0; j< DX; j++) {
IGY[i*DX + j] = YP[i*DX + j] + YM[i*DX + j];
}
}
/******************************************************************/
/* Lissage suivant LIGNE --> composante en y du gradient *****/
/******************************************************************/
/**** Filtrage de Gauche a Droite ****/

for (int i=0; i< DY; i++) {
YM[i*DX+0]= 0;
YM[i*DX+1]= 0;
for (int j= 2; j< DX; j++) {
YM[i*DX+j] = p.a1 * IGY[i*DX+j] + p.a2 * IGY[i*DX + j-1]
+ p.b1 * YM[i*DX + j-1] - p.b2 * YM[i*DX + j-2];
}
}

/**** Filtrage de Droite a Gauche ****/
for (int i=0; i< DY; i++) {
YP[i*DX+ DX-1] =0;
YP[i*DX+ DX-2] =0;
for (int j= DX-3; j>= 0; j--) {
YP[i*DX+j] = p.a3 * IGY[i*DX+j+1] - p.a4 * IGY[i*DX+j+2]
+ p.b1 * YP[i*DX+j+1] - p.b2 * YP[i*DX+j+2];
}
}
/**** Lissage suivant LIGNE ****/
for (int i= 0; i< DY; i++) {
for (int j= 0; j< DX; j++) {
IGY[i*DX + j] = YP[i*DX + j] + YM[i*DX + j];
}
}
// Not in initial code , but in mmv1

for (int i= 0; i< DY; i++) {
for (int j= 0; j< DX; j++) {
IGX[i*DX + j] /= p.mAmpl;
IGY[i*DX + j] /= p.mAmpl;
}
}

}

template<class Type> void ComputeDeriche(cImGrad<Type> & aResGrad,const cDataIm2D<Type> & aImIn,double aAlpha)
{
aImIn.AssertSameArea(aResGrad.mGx.DIm());
aImIn.AssertSameArea(aResGrad.mGy.DIm());

deriche_ll
(
aResGrad.mGx.DIm().RawDataLin(),
aResGrad.mGy.DIm().RawDataLin(),
aImIn.RawDataLin(),
aImIn.Sz().x(),
aImIn.Sz().y(),
aAlpha
);

/*
auto aV1In = cMMV1_Conv<Type>::ImToMMV1(aImIn);
auto aV1Gx = cMMV1_Conv<Type>::ImToMMV1(aResGrad.mGx.DIm());
auto aV1Gy = cMMV1_Conv<Type>::ImToMMV1(aResGrad.mGy.DIm());
ELISE_COPY
(
aV1In.all_pts(),
deriche(aV1In.in_proj(),aAlpha,10),
Virgule(aV1Gx.out(),aV1Gy.out())
);
*/
}


template<class Type> cImGrad<Type> Deriche(const cDataIm2D<Type> & aImIn,double aAlpha)
{
cImGrad<Type> aResGrad(aImIn.Sz());
ComputeDeriche(aResGrad,aImIn,aAlpha);
return aResGrad;
}


template void deriche_ll(tREAL4 *IGX,tREAL4 * IGY,tREAL4 * IE,tINT8 DX,tINT8 DY,tREAL8 alpha);
template cImGrad<tREAL4> Deriche(const cDataIm2D<tREAL4> & aImIn,double aAlpha);
template void ComputeDeriche(cImGrad<tREAL4> & aResGrad,const cDataIm2D<tREAL4> & aImIn,double aAlpha);

};


Loading

0 comments on commit e27e930

Please sign in to comment.