Пример #1
0
void MakeFCol()
{
     Tiff_Im Tif("../TMP/f3Reduc4.tif");
     Tiff_Im NewTif
             (
                 "../TMP/Col.tif",
		 Tif.sz(),
		 GenIm::u_int1,
		 Tiff_Im::No_Compr,
		 Tiff_Im::RGB, 
		   ElList<Arg_Tiff> ()
                 + Arg_Tiff(Tiff_Im::ATiles(Pt2di(1024,1024)))
		 + Arg_Tiff(Tiff_Im::APlanConf(Tiff_Im::Chunky_conf))
             );
      ELISE_COPY
      (
         Tif.all_pts(),
         its_to_rgb
         (Virgule(
              Tif.in(0),
              FX,
	      Abs((FY%512)-256)
         )),
	NewTif.out()
      );
}
Пример #2
0
void cImage_LumRas::CalculShadeByDiff()
{

   mImShade.Resize(mAppli.mImGr.sz());

   std::string aNameOut = mDir+ "LumRas_"+StdPrefix(mName) + ".tif";
   Tiff_Im TifTest
           (
                 aNameOut.c_str(),
                 mIm.sz(),
                 // GenIm::u_int1,
                 GenIm::real4,
                 Tiff_Im::No_Compr,
                 Tiff_Im::BlackIsZero
           );

    Fonc_Num aFRas  =  FLoc(6,50,mIm);
    Fonc_Num aFStd  =  FLoc(6,50,mAppli.mImGr);
    Tiff_Im::Create8BFromFonc("Test-Ras.tif",mIm.sz(),aFRas*100);
    Tiff_Im::Create8BFromFonc("Test-Std.tif",mIm.sz(),aFStd*100);
// Fonc_Num     cImage_LumRas::FLoc(int aNbIter,int aSzW,Fonc_Num aF)

   ELISE_COPY(mImShade.all_pts(),(aFRas-aFStd),mImShade.out());

   ELISE_COPY
   (
      TifTest.all_pts(),
      // Max(0,Min(255,128 * (1 + 2*mImShade.in()))),
      mImShade.in(),
      TifTest.out()
   );

}
Пример #3
0
void PartitionRenato(int argc,char** argv)
{
    std::string aName;
    double  aPropSzW=0.1,aSeuil=75;
    double aPropExag = 0.1;
    int aNbIter = 3;
    ElInitArgMain
    (
        argc,argv,
        LArgMain()  << EAMC(aName,"Name Input"),
        LArgMain()  <<  EAM(aPropSzW,"PropSzW",true,"Prop Size of W, def =0.1")
                     <<  EAM(aSeuil,"Seuil",true,"Threshold beetween Black & White, Def=75")
    );
    

    Tiff_Im aTIn = Tiff_Im::UnivConvStd(aName);
    Pt2di aSz = aTIn.sz();
    int aSzW = round_ni((euclid(aSz)*aPropSzW) / sqrt(aNbIter));
    Im2D_REAL4 anIm0(aSz.x,aSz.y);
    Im2D_REAL4 anIm1(aSz.x,aSz.y);
    Im2D_U_INT1 aImInside(aSz.x,aSz.y,1);

    ELISE_COPY(anIm0.all_pts(),255-aTIn.in(),anIm0.out());

    int aNbF = 3;
    for (int aKF=0 ; aKF<aNbF ; aKF++)
    {
        Im2D_REAL4 anImFond(aSz.x,aSz.y);
        Fonc_Num aFIn = anIm0.in(0);
        for (int aK=0 ; aK<aNbIter ; aK++)
           aFIn = (rect_som(aFIn,aSzW)*aImInside.in(0)) / Max(1.0,rect_som(aImInside.in(0),aSzW));

       ELISE_COPY(anImFond.all_pts(),aFIn,anImFond.out());
       if (aKF == (aNbF-1))
       {
              Fonc_Num aF = anIm0.in()-anImFond.in();
              aF = aF / aSeuil;
              aF = (aF -0.1) / (1-2*aPropExag);
              aF = Max(0.0,Min(1.0,aF));
              ELISE_COPY(anIm1.all_pts(),255.0 *(1-aF),anIm1.out());
       }
       else
       {
            ELISE_COPY
            (
                 aImInside.all_pts(),
                 anIm0.in() < anImFond.in()+aSeuil,
                 aImInside.out()
            );
       }
       
    }
    


    Tiff_Im::Create8BFromFonc(std::string("Bin-")+StdPrefix(aName)+".tif",aTIn.sz(),anIm1.in());
}
Пример #4
0
bool MultiChannel<tData>::read_tiff( Tiff_Im &i_tiff ) // Tiff_Im is not const because of ReadVecOfIm
{
	if ( i_tiff.type_el()!=typeEl() ) return false;

	vector<Im2DGen *> tiffChannels = i_tiff.ReadVecOfIm();
	resize( i_tiff.sz().x, i_tiff.sz().y, i_tiff.nb_chan() );

	for ( size_t i=0; i<mChannels.size(); i++ )
		set( i, *(Im2D<tData,tBase>*)tiffChannels[i] );

	return true;
}
Пример #5
0
void Write_Vignette(string aDir, string aNameOut,vector<double> aParam,string aDirOut, Pt2di aSz){

    //Bulding the output file system
    ELISE_fp::MkDirRec(aDir + aDirOut);

    //Reading the image and creating the objects to be manipulated
    aNameOut=aDir + aDirOut + aNameOut;
    Tiff_Im aTF=Tiff_Im(aNameOut.c_str(), aSz, GenIm::real4, Tiff_Im::No_Compr, Tiff_Im::BlackIsZero);

    Im2D_REAL4  aIm(aSz.x,aSz.y);

    ELISE_COPY
    (
        aTF.all_pts(),
        aTF.in(),
        aIm.out()
    );

    REAL4 ** aData = aIm.data();

    for (int aY=0 ; aY<aSz.y  ; aY++)
        {
            for (int aX=0 ; aX<aSz.x  ; aX++)
            {
                double x0=aSz.x/2;
                double y0=aSz.y/2;
                double D=pow(aX-x0,2)+pow(aY-y0,2);
                double aCor=1+aParam[0]*D+aParam[1]*pow(D,2)+aParam[2]*pow(D,3);
                if(aCor<1){aData[aY][aX]=1;}else{aData[aY][aX]=aCor;}
            }
        }

        Tiff_Im  aTOut
        (
            aNameOut.c_str(),
            aSz,
            GenIm::real4,
            Tiff_Im::No_Compr,
            Tiff_Im::BlackIsZero
        );

        ELISE_COPY
            (
                aTOut.all_pts(),
                aIm.in(),
                aTOut.out()
            );

}
Пример #6
0
void  cPackObsLiaison::GetPtsTerrain
      (
          const cParamEstimPlan & aPEP,
          cSetName &                    aSelectorEstim,
          cArgGetPtsTerrain &           anArg,
          const char *                  anAttr
      )
{
    cStatObs  aSO(false);
    if ( aPEP.AttrSup().IsInit())
       anAttr =  aPEP.AttrSup().Val().c_str();
    ELISE_ASSERT
    (
         mIsMult,
         "Require PMUL for cPackObsLiaison::GetPtsTerrain"
    );
    cPonderationPackMesure aPPM = aPEP.Pond();
    aPPM.Add2Compens().SetVal(false);
    for
    (
           std::map<std::string,cObsLiaisonMultiple *>::iterator itOML=mDicoMul.begin();
           itOML!=mDicoMul.end();
           itOML++
    )
    {
          cObsLiaisonMultiple * anOLM = itOML->second;
          std::string aNameP = anOLM->Pose1()->Name();
          if (aSelectorEstim.IsSetIn(aNameP))
          {
              Im2D_Bits<1> aM(1,1);
              if (aPEP.KeyCalculMasq().IsInit())
              {
                  std::string aNameM =  
                        anAttr ?
                        mAppli.ICNM()->Assoc1To2(aPEP.KeyCalculMasq().Val(),aNameP,anAttr,true):
                        mAppli.ICNM()->StdCorrect(aPEP.KeyCalculMasq().Val(),aNameP,true);
                  aNameM = mAppli.DC() + aNameM;

                  Tiff_Im aTF = Tiff_Im::UnivConvStd(aNameM);
                  Pt2di aSz = aTF.sz();
                  aM = Im2D_Bits<1>(aSz.x,aSz.y);
                  ELISE_COPY(aTF.all_pts(),aTF.in_bool(),aM.out());
                  anArg.SetMasq(&aM);
              }
              anOLM->AddObsLM(aPPM,0,&anArg,(cArgVerifAero*)0,aSO,0);
              anArg.SetMasq(0);
          }
    }
}
Пример #7
0
void TestNtt(const std::string &aName)
{
    Tiff_Im aTF = Tiff_Im::StdConvGen(aName,1,true);

    Pt2di aSz = aTF.sz();
    Im2D_REAL4 aI0(aSz.x,aSz.y);
    ELISE_COPY( aTF.all_pts(),aTF.in(),aI0.out());

    int aWSz=2;

    TIm2D<REAL4,REAL8> aTIm(aI0);

     double aSomGlob=0.0;
     double aNbGlob=0.0;

     for (int aKdx=-aWSz ; aKdx<=aWSz ; aKdx+=aWSz)
     {
         printf("## ");
         for (int aKdy=-aWSz ; aKdy<=aWSz ; aKdy+=aWSz)
         {
             int aDx = aKdx;
             int aDy = aKdy;
             Pt2di aDep(aDx,aDy);
             Pt2di aP;
             RMat_Inertie aMat;
             for (aP.x = aWSz ; aP.x<aSz.x-aWSz ; aP.x++)
             {
                 for (aP.y=aWSz ; aP.y<aSz.y-aWSz ; aP.y++)
                 {
                      aMat.add_pt_en_place(aTIm.get(aP),aTIm.get(aP+aDep));
                 }
             }
             double aC = aMat.correlation();
             aC = 1-aC;
             if (dist8(aDep) == aWSz)
             {
                aSomGlob += aC;
                aNbGlob ++;
             }
             printf(" %4d",round_ni(10000*(aC)));
         }
         printf("\n");
     }
     aSomGlob /= aNbGlob;
     std::cout  <<  " G:" << aSomGlob << "\n";
     printf("\n\n");
  
}
Пример #8
0
void DebugDrag()
{
   std::string aDir = "/media/data1/Jeux-Tests/Dragon-2/MEC2Im-Epi_Im1_Right_IMGP7511_IMGP7512.tif-Epi_Im2_Left_IMGP7511_IMGP7512.tif/";
   std::string aNamePx = "Px1_Num6_DeZoom2_LeChantier.tif";
   std::string aNameMasq = "AutoMask_LeChantier_Num_5.tif";

   Tiff_Im aTP = Tiff_Im::StdConv(aDir+aNamePx);
   Tiff_Im aTM = Tiff_Im::StdConv(aDir+aNameMasq);

   double aMinPx;
   ELISE_COPY
   (
        aTP.all_pts(),
        aTP.in() * aTM.in(),
        VMin(aMinPx)
   );

   std::cout << "MIN PX " << aMinPx << "\n";
}
Пример #9
0
Im2D_Bits<1>  GetMasqSubResol(const std::string & aName,double aResol)
{
    Tiff_Im aTF = Tiff_Im::BasicConvStd(aName);

     Pt2di aSzF = aTF.sz();
     Pt2di aSzR = round_ni(Pt2dr(aSzF)/aResol);

     Im2D_Bits<1> aRes(aSzR.x,aSzR.y);


     Fonc_Num aFonc = aTF.in_bool_proj();
     aFonc = StdFoncChScale(aFonc,Pt2dr(0,0),Pt2dr(aResol,aResol));
     aFonc = aFonc > 0.75;

     ELISE_COPY (aRes.all_pts(), aFonc,aRes.out());




     return aRes;
}
Пример #10
0
void GMCube::Opt()
{ 
    REAL aCapaTot = 0;
    ElTimer aTimer;
    INT aCPT = 0;
    {
// if ((aCPT %10==0) || (aCPT>=155)) pSCA->NbChem();
           INT aCapa = pSCA->PccMaxFlow();
           aCapaTot += aCapa;

	   aCPT++;
           if ((aCPT%1 == 0) || (aCapa == 0))
                cout << "CPT " << aCPT 
		<< " Time : " << aTimer.uval() 
		<< " DCapa : " << aCapa 
                << " Som Capa = " << aCapaTot << "\n";



           {
cout << "AAAAAAAAAAA\n";
              Im2D_INT2 aZ = pSCA->Sol(0);

              Tiff_Im  aTif
                       (
                           "/home/pierrot/Data/Cox.tif",
                           mSz,
                           GenIm::u_int1,
                           Tiff_Im::No_Compr,
                           Tiff_Im::BlackIsZero 
                       );
              ELISE_COPY(aZ.all_pts(),aZ.in(),aTif.out());
              
	      ShowIm2(aZ,mW4);
cout << "BBBBBBBB\n";
	      return;
           }
    }
    
}
Пример #11
0
void cMMTP::DoOneEnv(Im2D_REAL4 anEnvRed,Im2D_Bits<1> aNewM,bool isMax,const cXML_ParamNuage3DMaille & aTargetNuage,const cXML_ParamNuage3DMaille & aCurNuage,double aRedFact)
{
    int aSign  = isMax ? 1 : - 1;
    int aDefVal = -(aSign * 32000);


    Fonc_Num  aFMasqBin;
    Fonc_Num fChCo = Virgule(FX,FY)/ (aRedFact);
    Fonc_Num aRes = FoncChCoordWithMasq(anEnvRed.in(aDefVal),aNewM.in(0),fChCo,aDefVal,aFMasqBin);

    aRes = aRes + mDilatAlti * aSign;
    aRes  =  isMax ? rect_max(aRes,mDilatPlani)  : rect_min(aRes,mDilatPlani);
    aRes = ::AdaptDynOut(aRes,aTargetNuage,aCurNuage);

    Tiff_Im  aFileRes = FileEnv(isMax?"EnvMax":"EnvMin",false);
    ELISE_COPY(rectangle(mBoxOutEnv._p0,mBoxOutEnv._p1),trans(aRes * aFMasqBin,-mBoxInEnv._p0),aFileRes.out());

    if (isMax)
    {
        Tiff_Im  aFileMasq = FileEnv("EnvMasq",true);
        ELISE_COPY(rectangle(mBoxOutEnv._p0,mBoxOutEnv._p1),trans(aFMasqBin,-mBoxInEnv._p0),aFileMasq.out());
    }
}
Пример #12
0
void SobelTestNtt(const std::string &aName)
{
    Tiff_Im aTF = Tiff_Im::StdConvGen(aName,1,true);

    Pt2di aSz = aTF.sz();
    Im2D_REAL4 aI0(aSz.x,aSz.y);
    ELISE_COPY( aTF.all_pts(),aTF.in(),aI0.out());

    Video_Win * aW=0;
    // aW = Video_Win::PtrWStd(aSz);

    if (aW)
    {
        ELISE_COPY(aW->all_pts(),Min(255,aI0.in()/256.0),aW->ogray());
        aW->clik_in();
    }
  
    Fonc_Num aF1 = sobel(aI0.in_proj());

    Fonc_Num aF2 = aI0.in_proj();
    for (int aK=0 ; aK<3 ; aK++)
        aF2 = rect_som(aF2,1) / 9.0;
    aF2 = sobel(aF2);

    if (aW)
    {
        ELISE_COPY(aW->all_pts(),Min(255, 200 * (aF1/Max(aF2,1e-7))),aW->ogray());
        aW->clik_in();
    }

    double aSF1,aSF2,aSomPts;
    ELISE_COPY(aI0.all_pts(),Virgule(aF1,aF2,1.0),Virgule(sigma(aSF1),sigma(aSF2),sigma(aSomPts)));

    std::cout << "Indice " << aSF1 / aSF2 << "\n";
  
}
Пример #13
0
template <class Type> void Bench_PackB_IM<Type>::TiffVerif()
{

   Pt2di SzDalle = Pt2di(mPer,64);

    Tiff_Im  aTifFile
    (
         ELISE_BFI_DATA_DIR "ex.tif",  
         sz,
         type_of_ptr((Type *)0),
         Tiff_Im::NoByte_PackBits_Compr,
         Tiff_Im::BlackIsZero,
            L_Arg_Opt_Tiff()
           +  Arg_Tiff(Tiff_Im::ATiles(SzDalle))
    );


    

    ELISE_COPY(aTifFile.all_pts(),pck.in(),aTifFile.out());
    INT VDIF;
    ELISE_COPY(aTifFile.all_pts(),Abs(pck.in()-aTifFile.in()),VMax(VDIF));

    BENCH_ASSERT(VDIF==0);

    if (type_of_ptr((Type *)0)==GenIm::u_int1)
    {
         PackB_IM<U_INT1> aPack2 = aTifFile.un_load_pack_bit_U_INT1();
         ELISE_COPY(aTifFile.all_pts(),Abs(pck.in()-aPack2.in()),VMax(VDIF));
         BENCH_ASSERT(VDIF==0);
    }
    if (type_of_ptr((Type *)0)==GenIm::u_int2)
    {
         PackB_IM<U_INT2> aPack2 = aTifFile.un_load_pack_bit_U_INT2();
         ELISE_COPY(aTifFile.all_pts(),Abs(pck.in()-aPack2.in()),VMax(VDIF));
         BENCH_ASSERT(VDIF==0);
    }
}
Пример #14
0
int HomFilterMasq_main(int argc,char ** argv)
{
    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;
    bool ExpTxt=false;
    std::string PostPlan="_Masq";
    std::string KeyCalcMasq;
    std::string KeyEquivNoMasq;
    std::string MasqGlob;
    double  aResol=10;
    bool AcceptNoMask;
    std::string aPostIn= "";
    std::string aPostOut= "MasqFiltered";
    std::string aOriMasq3D,aNameMasq3D;
    cMasqBin3D * aMasq3D = 0;

    Pt2dr  aSelecTer;


    ElInitArgMain
    (
        argc,argv,
        LArgMain()  << EAMC(aFullDir,"Full name (Dir+Pat)", eSAM_IsPatFile),
        LArgMain()
                    << EAM(PostPlan,"PostPlan",true,"Post to plan, Def : toto ->toto_Masq.tif like with SaisieMasq")
                    << EAM(MasqGlob,"GlobalMasq",true,"Global Masq to add to all image")
                    << EAM(KeyCalcMasq,"KeyCalculMasq",true,"For tuning masq per image")
                    << EAM(KeyEquivNoMasq,"KeyEquivNoMasq",true,"When given if KENM(i1)==KENM(i2), don't masq")
                    << EAM(aResol,"Resol",true,"Sub Resolution for masq storing, Def=10")
                    << EAM(AcceptNoMask,"ANM",true,"Accept no mask, def = true if MasqGlob and false else")
                    << EAM(ExpTxt,"ExpTxt",true,"Ascii format for in and out, def=false")
                    << EAM(aPostIn,"PostIn",true,"Post for Input dir Hom, Def=")
                    << EAM(aPostOut,"PostOut",true,"Post for Output dir Hom, Def=MasqFiltered")
                    << EAM(aOriMasq3D,"OriMasq3D",true,"Orientation for Masq 3D")
                    << EAM(aNameMasq3D,"Masq3D",true,"File of Masq3D, Def=AperiCloud_${OriMasq3D}.ply")
                    << EAM(aSelecTer,"SelecTer",true,"[Per,Prop] Period of tiling on ground selection, Prop=proporion of selected")
    );
    bool aHasOri3D =  EAMIsInit(&aOriMasq3D);
    bool HasTerSelec = EAMIsInit(&aSelecTer);


    #if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
     #endif
    SplitDirAndFile(aDir,aPat,aFullDir);
    if (EAMIsInit(&PostPlan))
    {
        CorrecNameMasq(aDir,aPat,PostPlan);
    }

    if (!EAMIsInit(&AcceptNoMask))
       AcceptNoMask = EAMIsInit(&MasqGlob) || aHasOri3D;


    cInterfChantierNameManipulateur * anICNM = cInterfChantierNameManipulateur::BasicAlloc(aDir);

    std::string aKeyOri;
    if (aHasOri3D)
    {
        anICNM->CorrecNameOrient(aOriMasq3D);
        if (! EAMIsInit(&aNameMasq3D))
        {
              aNameMasq3D = aDir + "AperiCloud_" + aOriMasq3D + "_polyg3d.xml";
        }
        if (ELISE_fp::exist_file(aDir+aNameMasq3D))
        {
            aMasq3D = cMasqBin3D::FromSaisieMasq3d(aDir+aNameMasq3D);
        }
        else
        {
            ELISE_ASSERT(EAMIsInit(&aSelecTer),"Unused OriMasq3D");
        }
        aKeyOri = "NKS-Assoc-Im2Orient@" + aOriMasq3D;
    }

    Im2D_Bits<1>  aImMasqGlob(1,1);
    if (EAMIsInit(&MasqGlob))
       aImMasqGlob = GetMasqSubResol(aDir+MasqGlob,aResol);


    const std::vector<std::string> *  aVN = anICNM->Get(aPat);
    std::vector<Im2D_Bits<1> >  aVMasq;

     std::vector<CamStenope *> aVCam;


    double aResolMoy = 0;

    for (int aKN = 0 ; aKN<int(aVN->size()) ; aKN++)
    {
        std::string aNameIm = (*aVN)[aKN];
        Tiff_Im aTF = Tiff_Im::StdConvGen(aNameIm,1,false);
        Pt2di aSzG = aTF.sz();
        Pt2di aSzR (round_ni(Pt2dr(aSzG)/aResol));
        Im2D_Bits<1> aImMasq(aSzR.x,aSzR.y,1);


        std::string aNameMasq = StdPrefix(aNameIm)+PostPlan + ".tif";
        if (EAMIsInit(&KeyCalcMasq))
        {
            aNameMasq = anICNM->Assoc1To1(KeyCalcMasq,aNameIm,true);
        }

        if (ELISE_fp::exist_file(aNameMasq))
        {
            Im2D_Bits<1> aImMasqLoc = GetMasqSubResol(aDir+aNameMasq,aResol);
            ELISE_COPY(aImMasq.all_pts(),aImMasq.in() && aImMasqLoc.in(0),aImMasq.out());
        }
        else
        {
             if (!AcceptNoMask)
             {
                 std::cout << "For Im " << aNameIm << " file " << aNameMasq << " does not exist\n";
                 ELISE_ASSERT(false,"Masq not found");
             }
        }

        if (EAMIsInit(&MasqGlob))
        {

            ELISE_COPY(aImMasq.all_pts(),aImMasq.in() && aImMasqGlob.in(0),aImMasq.out());
        }

        aVMasq.push_back(aImMasq);
        // Tiff_Im::CreateFromIm(aImMasq,"SousRes"+aNameMasq);
        if (aHasOri3D)
        {
            aVCam.push_back(anICNM->StdCamOfNames(aNameIm,aOriMasq3D));
            aResolMoy += aVCam.back()->GlobResol();
        }
    }
    if (aHasOri3D)
       aResolMoy /= aVCam.size();

    std::string anExt = ExpTxt ? "txt" : "dat";


    std::string aKHIn =   std::string("NKS-Assoc-CplIm2Hom@")
                       +  std::string(aPostIn)
                       +  std::string("@")
                       +  std::string(anExt);
    std::string aKHOut =   std::string("NKS-Assoc-CplIm2Hom@")
                        +  std::string(aPostOut)
                        +  std::string("@")
                       +  std::string(anExt);


    double aPeriodTer=0,aSeuilDistTer=0;
    if (HasTerSelec)
    {
       aPeriodTer = aSelecTer.x * aResolMoy;
       aSeuilDistTer = aPeriodTer * sqrt(aSelecTer.y);
    }

    double aNbInTer=0;
    double aNbTestTer=0;


    for (int aKN1 = 0 ; aKN1<int(aVN->size()) ; aKN1++)
    {
        for (int aKN2 = 0 ; aKN2<int(aVN->size()) ; aKN2++)
        {
             std::string aNameIm1 = (*aVN)[aKN1];
             std::string aNameIm2 = (*aVN)[aKN2];

             std::string aNameIn = aDir + anICNM->Assoc1To2(aKHIn,aNameIm1,aNameIm2,true);

             if (ELISE_fp::exist_file(aNameIn))
             {
                  bool UseMasq = true;
                  if (EAMIsInit(&KeyEquivNoMasq))
                  {
                       UseMasq =  (anICNM->Assoc1To1(KeyEquivNoMasq,aNameIm1,true) != anICNM->Assoc1To1(KeyEquivNoMasq,aNameIm2,true) );
                  }


                  TIm2DBits<1>  aMasq1 ( aVMasq[aKN1]);
                  TIm2DBits<1>  aMasq2 ( aVMasq[aKN2]);

                  ElPackHomologue aPackIn =  ElPackHomologue::FromFile(aNameIn);
                  ElPackHomologue aPackOut;
                  for (ElPackHomologue::const_iterator itP=aPackIn.begin(); itP!=aPackIn.end() ; itP++)
                  {
                      Pt2dr aP1 = itP->P1();
                      Pt2dr aP2 = itP->P2();
                      Pt2di aQ1 = round_ni(aP1/aResol);
                      Pt2di aQ2 = round_ni(aP2/aResol);

                      bool Ok = ((aMasq1.get(aQ1,0) && aMasq2.get(aQ2,0)) || (! UseMasq));

                      if (Ok &&  aHasOri3D)
                      {
                          Pt3dr  aPTer= aVCam[aKN1]->PseudoInter(aP1,*(aVCam[aKN2]),aP2);
                          if (aMasq3D && (! aMasq3D->IsInMasq(aPTer)))
                             Ok = false;

                          if (Ok && HasTerSelec)
                          {
                              bool OkTer =  (mod_real(aPTer.x,aPeriodTer) < aSeuilDistTer) && (mod_real(aPTer.y,aPeriodTer) < aSeuilDistTer);
                              Ok = OkTer;
                              aNbTestTer ++;
                              aNbInTer += OkTer;
                          }
                      }  

                      if (Ok)
                      {
                          ElCplePtsHomologues aCple(aP1,aP2);
                          aPackOut.Cple_Add(aCple);
                      }
                  }
                  std::string aNameOut = aDir + anICNM->Assoc1To2(aKHOut,aNameIm1,aNameIm2,true);
                  aPackOut.StdPutInFile(aNameOut);
                  std::cout << "IN " << aNameIn << " " << aNameOut  << " UseM " << UseMasq << "\n";
             }
        }
    }
    // std::vector<cImFMasq *> mVIm;

    if (HasTerSelec)
    {
        std::cout << "A Posteriori Prop=" << aNbInTer / aNbTestTer << "\n";
    }



   return EXIT_SUCCESS;
}
Пример #15
0
int PreparSift_Main(int argc,char ** argv)
{
    double aPEg = 1.0;
    double aPSrtEg = 3.0;
    double aPM = 2.0;


    std::string  aNameIn,aNameOut="Sift.tif";

    ElInitArgMain
    (
         argc,argv,
         LArgMain()  << EAMC(aNameIn,"Full name (Dir+Pattern)", eSAM_IsPatFile),
         LArgMain()  << EAM(aNameOut,"NameOut",true)
    );

    Tiff_Im aTif = Tiff_Im::StdConvGen(aNameIn,1,true);
    
    // Init Mems
    Pt2di aSz = aTif.sz();
    Im2D_U_INT2  anIm(aSz.x,aSz.y);

    Im1D_REAL8  aH(aNbH,0.0);


    // Load image
    {
       Symb_FNum aFTif(aTif.in());
       ELISE_COPY(aTif.all_pts(),aFTif,anIm.out()| (aH.histo().chc(aFTif)<<1) );
    }
    Im1D_REAL8  aHSqrt(aNbH,0.0);
    ELISE_COPY(aH.all_pts(),sqrt(aH.in()),aHSqrt.out());



    int aVMax =0;
    // Calcul Histo
    MakeFoncRepart(aH,&aVMax);
    MakeFoncRepart(aHSqrt);

    // Fonc Loc 

    Fonc_Num aFonc(Rconv(anIm.in_proj()));
    Fonc_Num aS1S2 = Virgule(aFonc,Square(aFonc));
    for (int aK=0 ; aK< TheNbIter ; aK++)
    {
        aS1S2 = rect_som(aS1S2,TheNbVois) / ElSquare(1+2*TheNbVois);
    }
    Symb_FNum aFS1 = aS1S2.v0();
    Symb_FNum aFS2 = aS1S2.v1()-Square(aFS1);
    Fonc_Num aFLoc = (anIm.in()-aFS1) / sqrt(Max(1.0,aFS2));

    // aFLoc = aFLoc * 20;
    aFLoc = atan(aFLoc) /(PI/2);

    
    // Symb_FNum aFonc(aTif.in());

    std::cout << "MaxMin "  << aVMax << "\n";

    Fonc_Num aFEg = aH.in()[anIm.in()];
    Fonc_Num aFEgS = aHSqrt.in()[anIm.in()];
    Fonc_Num aFM  = anIm.in() * (255.0 / aVMax);


    // Fonc_Num aFRes = (aFEg*aPEg + aFM * aPM + aFEgS*aPSrtEg + aFLoc) / (aPEg + aPM + aPSrtEg);

    Symb_FNum aFMoy = (aFEg*aPEg + aFM * aPM + aFEgS*aPSrtEg ) / (aPEg + aPM + aPSrtEg);
    Symb_FNum aFMarge = Min(64,Min(aFMoy,255-aFMoy));
    Fonc_Num aFRes  = aFMoy + aFMarge * aFLoc;


/*
    Fonc_Num aFRes = Max(0,Min(255,aFMoy + 60 * aFLoc));
*/

    Tiff_Im::Create8BFromFonc(aNameOut,aSz,aFRes);
    

     
    return EXIT_SUCCESS;
}
Пример #16
0
cElNuageLaser::cElNuageLaser
(
     const std::string & aNameFile,
     const char *  aNameOri,
     const char *  aNameGeomCible ,
     const char *  aNameGeomInit

)  :
   mVPts (),
   mQt   (0)
{
   std::string aNameBin = StdPrefix(aNameFile) + ".tif";
   if (! ELISE_fp::exist_file(aNameBin))
   {
       INT aNb = 3;
       FILE * aFP = ElFopen(aNameFile.c_str(),"r");
       ELISE_ASSERT(aFP!=0,"Cannot Open File for Laser Data");

       char Buf[10000];
       INT aCpt =0;
       while (aNb>=3)
       {
           aNb=0;
           char * got = fgets(Buf,10000,aFP);
           Pt3dr aP;
           if (got)
           {
              aNb = sscanf(Buf,"%lf %lf %lf",&aP.x,&aP.y,&aP.z);
           }
	   if (aNb>=3)
              mVPts.push_back(aP);
	   aCpt++;
       }

       INT aNbPts = (INT) mVPts.size();
       Im2D_REAL8 aImPts(aNbPts,3);
       REAL ** aData = aImPts.data();
       for (INT aK=0 ; aK<aNbPts ; aK++)
       {
	   Pt3dr aP = mVPts[aK];
           aData[0][aK] = aP.x;
           aData[1][aK] = aP.y;
           aData[2][aK] = aP.z;
       }

       Tiff_Im aFile
	       (
                  aNameBin.c_str(),
		  Pt2di(aNbPts,3),
		  GenIm::real8,
		  Tiff_Im::No_Compr,
		  Tiff_Im::BlackIsZero,
		     Tiff_Im::Empty_ARG
		  +  Arg_Tiff(Tiff_Im::ANoStrip())
               );
       ELISE_COPY(aImPts.all_pts(),aImPts.in(),aFile.out());
   }
   else
   {
       Tiff_Im aFile(aNameBin.c_str());
       Pt2di aSz = aFile.sz();
       Im2D_REAL8 aImPts(aSz.x,aSz.y);
       ELISE_COPY(aImPts.all_pts(),aFile.in(),aImPts.out());

       REAL ** aD = aImPts.data();
       mVPts.reserve(aSz.x);
       for (INT aK=0 ; aK<aSz.x ; aK++)
       {
           Pt3dr aP(aD[0][aK],aD[1][aK],aD[2][aK]);
           mVPts.push_back(aP);
       }
   }


   Ori3D_Std * aOri = 0;
   eModeConvGeom aMode = eConvId;

   if (aNameOri)
   {
       if (!strcmp(aNameGeomInit,"GeomCarto"))
       {
           if (!strcmp(aNameGeomCible,"GeomCarto"))
           {
               aMode = eConvId;
           }
           else if (!strcmp(aNameGeomCible,"GeomTerrain"))
           {
               aMode = eConvCarto2Terr;
           }
           else if (!strcmp(aNameGeomCible,"GeomTerIm1"))
           {
               aMode = eConvCarto2TerIm;
           }
           else
           {
              ELISE_ASSERT(false,"Bad GeomCible in cElNuageLaser::cElNuageLaser");
           }
       }
       else
       {
           ELISE_ASSERT(false,"Bad GeomInit in cElNuageLaser::cElNuageLaser");
       }
       if (aMode != eConvId)
          aOri = new Ori3D_Std (aNameOri) ;
   }

   for (INT aK=0 ; aK<INT( mVPts.size()); aK++)
   {
       Pt3dr aP = mVPts[aK];
       if (aOri)
       {
          if (aMode == eConvCarto2Terr)
             aP = aOri->carte_to_terr(aP);
          else if (aMode == eConvCarto2TerIm)
          {
             aP = aOri->carte_to_terr(aP);
             Pt2dr aP2 = aOri->to_photo(aP);
             aP.x = aP2.x;
             aP.y = aP2.y;
          }
          mVPts[aK] = aP;
       }

       REAL  aZ   =  aP.z;
       Pt2dr aP2 (aP.x,aP.y);
       if (aK==0)
       {
           mZMax = mZMin = aZ;
           mPInf =mPSup = aP2;
       }
       ElSetMin(mZMin,aZ);
       ElSetMax(mZMax,aZ);
       mPInf.SetInf(aP2);
       mPSup.SetSup(aP2);
   }
   delete aOri;
}
Пример #17
0
void  cMMTP::ConputeEnveloppe(const cComputeAndExportEnveloppe & aCAEE,const cXML_ParamNuage3DMaille & aCurNuage)
{

   mNameTargetEnv = mAppli.WorkDir() + TheDIRMergeEPI()  +  mAppli.PDV1()->Name() + "/NuageImProf_LeChantier_Etape_1.xml";

   mNameTargetEnv = aCAEE.NuageExport().ValWithDef(mNameTargetEnv);
   cXML_ParamNuage3DMaille aTargetNuage = StdGetFromSI(mNameTargetEnv,XML_ParamNuage3DMaille);
   mZoomTargetEnv = aTargetNuage.SsResolRef().Val();
   mSzTargetEnv =  aTargetNuage.NbPixel();
   double aZoomRel = mAppli.CurEtape()->DeZoomTer()/mZoomTargetEnv;

   mBoxOutEnv._p0 = round_ni(Pt2dr(mBoxOutGlob._p0) * aZoomRel);
   mBoxOutEnv._p1 = round_ni(Pt2dr(mBoxOutGlob._p1) * aZoomRel);
   mBoxInEnv._p0 = round_ni(Pt2dr(mBoxInGlob._p0) * aZoomRel);
   mBoxInEnv._p1 = round_ni(Pt2dr(mBoxInGlob._p1) * aZoomRel);



   ELISE_ASSERT(mP0Tiep==Pt2di(0,0),"Too lazy to handle box maping");


   double aPasPx =  mAppli.CurEtape()->GeomTer().PasPxRel0();
//=============== READ PARAMS  ====================
   double  aStepSsEch = aCAEE.SsEchFilter().Val();
   int     aSzFiltrer = aCAEE.SzFilter().Val();
   double  aProp = aCAEE.ParamPropFilter().Val();

   int     aDistProl = round_up(  ElMax(aCAEE.ProlResolCur().Val(),aCAEE.ProlResolCible().Val()/aZoomRel) /aStepSsEch);
   double  aDistCum =  (aCAEE.ProlDistAddMax().Val()  / (aPasPx*  aZoomRel));
   double aDistAdd =   (aCAEE.ProlDistAdd().Val()*aStepSsEch )  / (aPasPx);

   std::cout << "DIST CUM " << aDistCum << " DADD " << aDistAdd << "\n";


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

    ElTimer aChrono;

    int     aSeuilNbV = 2 * (1+2*aSzFiltrer); // Au moins une bande de 2 pixel pour inferer qqch
    Pt2di aSzRed = round_up(Pt2dr(mSzTiep)/aStepSsEch);

    Im2D_Bits<1>    aMasqRed(aSzRed.x,aSzRed.y,0);
    TIm2DBits<1>    aTMR(aMasqRed);
/*
    TIm2D<INT2,INT> aPMaxRed(aSzRed);
    TIm2D<INT2,INT> aPMinRed(aSzRed);
*/
    TIm2D<REAL4,REAL> aPMaxRed(aSzRed);
    TIm2D<REAL4,REAL> aPMinRed(aSzRed);

    // Calcul du filtre de reduction
    Pt2di aPRed;
    for (aPRed.y = 0 ; aPRed.y<aSzRed.y ; aPRed.y++)
    {
        for (aPRed.x = 0 ; aPRed.x<aSzRed.x ; aPRed.x++)
        {
             Pt2di aPR1 = round_ni(Pt2dr(aPRed)*aStepSsEch);
             int anX0 = ElMax(0,aPR1.x-aSzFiltrer);
             int anX1 = ElMin(mSzTiep.x-1,aPR1.x+aSzFiltrer);
             int anY0 = ElMax(0,aPR1.y-aSzFiltrer);
             int anY1 = ElMin(mSzTiep.y-1,aPR1.y+aSzFiltrer);
             std::vector<REAL> aVVals;
             Pt2di aVoisR1;
             for (aVoisR1.x=anX0 ; aVoisR1.x<=anX1 ; aVoisR1.x++)
             {
                  for (aVoisR1.y=anY0 ; aVoisR1.y<=anY1 ; aVoisR1.y++)
                  {
                     if (mTImMasqInit.get(aVoisR1))
                        aVVals.push_back( mTCBT.get(aVoisR1));
                        // aVVals.push_back( mTImProf.get(aVoisR1));
                  }
             }
             if (int(aVVals.size()) >= aSeuilNbV)
             {
                  REAL4 aVMax = KthValProp(aVVals,aProp);
                  REAL4 aVMin = KthValProp(aVVals,1-aProp);
                  aPMaxRed.oset(aPRed,aVMax);
                  aPMinRed.oset(aPRed,aVMin);
                  aTMR.oset(aPRed,1);
                  ELISE_ASSERT(aVMin<=aVMax,"Mic>Max !!!! in BasicMMTiep");
             }
             else
             {
                  aPMaxRed.oset(aPRed,-32000);
                  aPMinRed.oset(aPRed, 32000);
             }
        }
    }
    //Tiff_Im::Create8BFromFonc("TDifInit.tif",aSzRed,Max(0,Min(255,Iconv(aPMaxRed._the_im.in()-aPMinRed._the_im.in()))));

    Im2D_Bits<1> aNewM(1,1);
    Im2D_REAL4  aNewMax = ProlongByCont (aNewM,aMasqRed,aPMaxRed._the_im,aDistProl,aDistAdd,aDistCum);
    Im2D_REAL4  aNewMin = ProlongByCont (aNewM,aMasqRed,aPMinRed._the_im,aDistProl,-aDistAdd,aDistCum);
    ELISE_COPY(select(aNewM.all_pts(),!aNewM.in()),0,aNewMax.out()|aNewMin.out());

    // fChCo = Virgule(FX,FY)/ (aStepSsEch * aZoomRel);
    // fMasq = aNewM.in(0)[fChCo];
    // fMasqBin = fMasq>0.5;


    mDilatPlani = ElMax(aCAEE.DilatPlaniCible().Val(),round_up(aCAEE.DilatPlaniCur().Val()*aZoomRel));
    mDilatAlti  = ElMax(aCAEE.DilatAltiCible ().Val(),round_up(aCAEE.DilatPlaniCur().Val()*aZoomRel));
    
    DoOneEnv(aNewMax,aNewM,true ,aTargetNuage,aCurNuage,aStepSsEch * aZoomRel);
    DoOneEnv(aNewMin,aNewM,false,aTargetNuage,aCurNuage,aStepSsEch * aZoomRel);


    Fonc_Num  aFMasqBin;
    Fonc_Num fChCo = Virgule(FX,FY)/ aZoomRel;

std::cout  << "ZRRRR  " << aZoomRel <<  " 1/Z " << (1/aZoomRel) 
           <<   " ;; " << mAppli.CurEtape()->DeZoomTer() << " , " << mZoomTargetEnv << "\n";
// Tiff_Im::CreateFromIm(mContBT,DirOfFile(mNameTargetEnv)+"CONTBT.tif");


    Fonc_Num aFoncProf = FoncChCoordWithMasq(mContBT.in(0),mImMasqFinal.in(0),fChCo,0,aFMasqBin);
    aFoncProf = ::AdaptDynOut(aFoncProf,aTargetNuage,aCurNuage);

    Tiff_Im aFileProf = FileEnv("Depth",false);
    ELISE_COPY(rectangle(mBoxOutEnv._p0,mBoxOutEnv._p1),trans(aFoncProf,-mBoxInEnv._p0),aFileProf.out());


    Tiff_Im aFileMasq = FileEnv("Masq",true);
    ELISE_COPY(rectangle(mBoxOutEnv._p0,mBoxOutEnv._p1),trans(aFMasqBin,-mBoxInEnv._p0),aFileMasq.out());


#ifdef ELISE_X11
   if (0 && TheWTiePCor)
   {
       ELISE_COPY(TheWTiePCor->all_pts(),aFMasqBin,TheWTiePCor->odisc());
       std::cout << "AAAAAAAAAAAAAAAAAAAAa\n";
       TheWTiePCor->clik_in();
       ELISE_COPY(TheWTiePCor->all_pts(),aFileMasq.in(),TheWTiePCor->odisc());
       std::cout << "bbBBbbBBBBBBBbbb\n";
       TheWTiePCor->clik_in();
   }
#endif
}
void SaisieAppuisPredic(int argc, char ** argv,
                      Pt2di &aSzW,
                      Pt2di &aNbFen,
                      std::string &aFullName,
                      std::string &aDir,
                      std::string &aName,
                      std::string &aNamePt,
                      std::string &anOri,
                      std::string &aModeOri,
                      std::string &aNameMesure,
                      std::string &aTypePts,
                      std::string &aMasq3D,
                      std::string &PIMsFilter,
                      double &aFlou,
                      bool &aForceGray,
                      double &aZMoy,
                      double &aZInc,
                      std::string & aInputSec)
{
    MMD_InitArgcArgv(argc,argv);

    ElInitArgMain
            (
                argc,argv,
                LArgMain()  << EAMC(aFullName,"Full Name (Dir+Pattern)", eSAM_IsPatFile)
                            << EAMC(anOri,"Orientation", eSAM_IsExistDirOri)
                            << EAMC(aNamePt,"File for Ground Control Points", eSAM_IsExistFile)
                            << EAMC(aNameMesure,"File for Image Measurements", eSAM_IsExistFile),
                LArgMain()  << EAM(aSzW,"SzW",true,"Size of global window (Def 800 800)")
                            << EAM(aNbFen,"NbF",true,"Number of Sub Window (Def 2 2)")
                            << EAM(aFlou,"WBlur",true,"Size IN GROUND GEOMETRY of bluring for target")
                            << EAM(aTypePts,"Type",true,"in [MaxLoc,MinLoc,GeoCube]")
                            << EAM(aForceGray,"ForceGray",true,"Force gray image, def=true")
                            << EAM(aModeOri,"OriMode", true, "Orientation type (GRID) (Def=Std)")
                            << EAM(aZMoy,"ZMoy",true,"Average Z, Mandatory in PB", eSAM_NoInit)
                            << EAM(aZInc,"ZInc",true,"Incertitude on Z, Mandatory in PB", eSAM_NoInit)
                            << EAM(aMasq3D,"Masq3D",true,"3D Masq used for visibility", eSAM_NoInit)
                            << EAM(PIMsFilter,"PIMsF",true,"PIMs filter used for visibility", eSAM_NoInit)
                            << EAM(aInputSec,"InputSec",true,"PIMs filter used for visibility", eSAM_NoInit)
                );

    if (!MMVisualMode)
    {
        aTypePts = "eNSM_" + aTypePts;

        SplitDirAndFile(aDir,aName,aFullName);


        cInterfChantierNameManipulateur * aCINM = cInterfChantierNameManipulateur::BasicAlloc(aDir);
        aCINM->CorrecNameOrient(anOri);
        const cInterfChantierNameManipulateur::tSet  *  aSet = aCINM->Get(aName);

        //std::cout << "Nb Image =" << aSet->size() << "\n";
        ELISE_ASSERT(aSet->size()!=0,"No image found");

        if (aNbFen.x<0)
        {
            if (aSet->size() == 1)
            {
                aNbFen = Pt2di(1,2);
            }
            else if (aSet->size() == 2)
            {
                Tiff_Im aTF = Tiff_Im::StdConvGen(aDir+(*aSet)[0],1,false,true);
                Pt2di aSzIm = aTF.sz();
                aNbFen = (aSzIm.x>aSzIm.y) ? Pt2di(1,2) : Pt2di(2,1);
            }
            else
            {
                aNbFen = Pt2di(2,2);
            }
        }

        aCINM->MakeStdOrient(anOri,false);
    }
}
int ApplyParralaxCor_main(int argc, char ** argv)
{
	//std::string aNameIm, aNameIm2, aNameParallax, aNameDEM;
	std::string aNameIm, aNameParallax;
	std::string aNameOut = "";
	//Reading the arguments
	ElInitArgMain
		(
		argc, argv,
		LArgMain()
		<< EAMC(aNameIm, "Image to be corrected", eSAM_IsPatFile)
		//<< EAMC(aNameIm2, "Other image", eSAM_IsPatFile)
		<< EAMC(aNameParallax, "Paralax correction file", eSAM_IsPatFile),
		//<< EAMC(aNameDEM, "DEM file", eSAM_IsPatFile),
		LArgMain()
		<< EAM(aNameOut, "Out", true, "Name of output image (Def=ImName_corrected.tif")
		);

	std::string aDir, aPatIm;
	SplitDirAndFile(aDir, aPatIm, aNameIm);

	cout << "Correcting " << aNameIm << endl;
	if (aNameOut == "")
		aNameOut = aNameIm + "_corrected.tif";

	//Reading the image and creating the objects to be manipulated
	Tiff_Im aTF = Tiff_Im::StdConvGen(aDir + aNameIm, 1, false);

	Pt2di aSz = aTF.sz(); cout << "size of image = " << aSz << endl;
	Im2D_U_INT1  aIm(aSz.x, aSz.y);

	ELISE_COPY
		(
		aTF.all_pts(),
		aTF.in(),
		aIm.out()//Virgule(aImR.out(),aImG.out(),aImB.out())
		);

	U_INT1 ** aData = aIm.data();

	//Reading the parallax correction file
	Tiff_Im aTFPar = Tiff_Im::StdConvGen(aDir + aNameParallax, 1, false);
	Im2D_REAL8  aPar(aSz.x, aSz.y);
	ELISE_COPY
		(
		aTFPar.all_pts(),
		aTFPar.in(),
		aPar.out()//Virgule(aImR.out(),aImG.out(),aImB.out())
		);
	REAL8 ** aDatPar = aPar.data();
	

	//Output container
	Im2D_U_INT1  aImOut(aSz.x, aSz.y);
	U_INT1 ** aDataOut = aImOut.data();

	/*Things needed for RPC angle computation, not main goal of this function
	
	//Read RPCs
	RPC aRPC;
	string aNameRPC1 = "RPC_" + StdPrefix(aNameIm) + ".xml";
	aRPC.ReadDimap(aNameRPC1);
	cout << "Dimap File " << aNameRPC1 << " read" << endl;
	RPC aRPC2;
	string aNameRPC2 = "RPC_" + StdPrefix(aNameIm2) + ".xml";
	aRPC2.ReadDimap(aNameRPC2);
	cout << "Dimap File " << aNameRPC2 << " read" << endl;
	
	//Reading the DEM file
	Tiff_Im aTFDEM = Tiff_Im::StdConvGen(aDir + aNameDEM, 1, false);
	Im2D_REAL8  aDEM(aSz.x, aSz.y);
	ELISE_COPY
	(
	aTFDEM.all_pts(),
	aTFDEM.in(),
	aDEM.out()
	);
	REAL8 ** aDatDEM = aDEM.data();

	//Output angle container 1
	Im2D_REAL8  aAngleBOut(aSz.x, aSz.y);
	REAL8 ** aDataAngleBOut = aAngleBOut.data();
	string aNameAngleB = "AngleB.tif";

	//Output angle container 2
	Im2D_REAL8  aAngleNOut(aSz.x, aSz.y);
	REAL8 ** aDataAngleNOut = aAngleNOut.data();
	string aNameAngleN = "AngleN.tif";
	*/
	//Pt3dr PBTest(1500,3000, 0);
	//Pt3dr PWTest = aRPC.DirectRPC(PBTest);
	//Pt3dr PNTest = aRPC2.InverseRPC(PWTest);
	//cout << "PB0 = " << PBTest << endl;
	//cout << "PW0 = " << PWTest << endl;
	//cout << "PN0 = " << PNTest << endl;
	//cout << aRPC.height_scale << " " << aRPC.height_off << endl;
	//PBTest.z=1000;
	//PWTest = aRPC.DirectRPC(PBTest);
	//PNTest = aRPC2.InverseRPC(PWTest);
	//cout << "PB1 = " << PBTest << endl;
	//cout << "PW1 = " << PWTest << endl;
	//cout << "PN1 = " << PNTest << endl;


	cout << "size of image = " << aSz << endl;
	//Computing output data
	for (int aX = 0; aX < aSz.x; aX++)
	{
		for (int aY = 0; aY < aSz.y; aY++)
		{
			/*
			Pt3dr P0B(aX, aY, aDatDEM[aY][aX]);
			Pt3dr PW0 = aRPC.DirectRPC(P0B);
			Pt3dr PW1 = PW0, PW2 = PW0;
			PW1.z = PW1.z - 1;
			PW2.z = PW2.z + 1;
			Pt3dr P1B = aRPC.InverseRPC(PW1);
			Pt3dr P2B = aRPC.InverseRPC(PW2);
			Pt3dr P1N = aRPC2.InverseRPC(PW1);
			Pt3dr P2N = aRPC2.InverseRPC(PW2);
			//Pt3dr P1B(aX, aY, 0);
			//Pt3dr P2B(aX, aY, 10000);
			//Pt3dr P1N = aRPC2.InverseRPC(aRPC.DirectRPC(P1B));
			//Pt3dr P2N = aRPC2.InverseRPC(aRPC.DirectRPC(P2B));
			double aAngleB = atan((P2B.x - P1B.x) / (P2B.y - P1B.y));
			aDataAngleBOut[aY][aX] = aAngleB;
			double aAngleN = atan((P2N.x - P1N.x) / (P2N.y - P1N.y));
			aDataAngleNOut[aY][aX] = aAngleN;
			//cout << aX << " " << aY << " " << aAngle << endl;
			//cout << P1N << " " << P2N << " " << aAngle << endl;

			*/
			//THE THINGS COMPUTED ABOVE WILL BE USED IN A FURTHER UPDATE

			Pt2dr ptOut;
			ptOut.x = aX - aDatPar[aY][aX];// * cos(aAngleB);
			ptOut.y = aY - aDatPar[aY][aX];// * sin(aAngleB);
			aDataOut[aY][aX] = Reechantillonnage::biline(aData, aSz.x, aSz.y, ptOut);
		}
	}
	cout << "size of image = " << aSz << endl;
	Tiff_Im  aTOut
		(
		aNameOut.c_str(),
		aSz,
		GenIm::u_int1,
		Tiff_Im::No_Compr,
		Tiff_Im::BlackIsZero
		);


	ELISE_COPY
		(
		aTOut.all_pts(),
		aImOut.in(),
		aTOut.out()
		);
	/*
	Tiff_Im  aTAngleBOut
		(
		aNameAngleB.c_str(),
		aSz,
		GenIm::real8,
		Tiff_Im::No_Compr,
		Tiff_Im::BlackIsZero
		);


	ELISE_COPY
		(
		aTAngleBOut.all_pts(),
		aAngleBOut.in(),
		aTAngleBOut.out()
		);


	Tiff_Im  aTAngleNOut
		(
		aNameAngleN.c_str(),
		aSz,
		GenIm::real8,
		Tiff_Im::No_Compr,
		Tiff_Im::BlackIsZero
		);


	ELISE_COPY
		(
		aTAngleNOut.all_pts(),
		aAngleNOut.in(),
		aTAngleNOut.out()
		);
*/
	return 0;
}
Пример #20
0
int GrShade_main(int argc,char ** argv)
{
     std::string aNameIn;
     std::string aNameOut;
     std::string aNameCol="";
     Pt2di aP0Glob(0,0),aSzGlob(0,0);
     INT aNbDir = 20;
     REAL aFZ = 1.0;

     REAL aPdsAnis = 0.95;
     INT  aBrd = -1;
     std::string aTMNt = "real4";
     std::string aTShade = "real4";
     INT aDequant =0;
     INT aVisu = 0;
     REAL aHypsoDyn = -1.0;
     REAL aHypsoSat = 0.5;

     Pt2di aSzMaxDalles (3000,3000);
     INT aSzRecDalles = 300;
     std::string aModeOmbre="CielVu";
     std::string modeOmbre[] = {aModeOmbre,"IgnE","Local","Med","Mixte"};
     std::list<std::string> lModeOmbre(modeOmbre, modeOmbre + sizeof(modeOmbre) / sizeof(std::string) );
     std::string aFileMasq="";

     double  aDericheFact=2.0;
     int     aNbIterF = 4;
     double  aFactExp = 0.95;
     double aDyn = 1.0;
     int aNbMed = 100;
     int aNbIterMed = 1;

     Tiff_Im::SetDefTileFile(1<<15);

     std::vector<double> aVPdsFiltre;


     std::string aModeColor = "IntensShade";
     std::string modeColor[] = {aModeColor,"BackRGB","GrayBackRGB"};
     std::list<std::string> lModeColor(modeColor, modeColor + sizeof(modeColor) / sizeof(std::string) );

     double aTetaH = 25.0;
     double anAzimut = 0.0;
     double aDynMed = 1.0;

     ElInitArgMain
     (
           argc,argv,
           LArgMain() << EAMC(aNameIn, "File name", eSAM_IsExistFile) ,
           LArgMain() << EAM(aNameOut,"Out",true)
                      << EAM(aNameCol,"FileCol",true, "Color file", eSAM_IsExistFile)
                      << EAM(aVisu,"Visu",true)
                      << EAM(aP0Glob,"P0",true)
                      << EAM(aSzGlob,"Sz",true)
                      << EAM(aFZ,"FZ",true)
                      << EAM(aDynMed,"DynMed",true)
                      << EAM(aPdsAnis,"Anisotropie",true)
                      << EAM(aNbDir,"NbDir",true)
                      << EAM(aBrd,"Brd",true)
                      << EAM(aTMNt,"TypeMnt",true, "Type", eSAM_None, ListOfVal(GenIm::bits1_msbf, ""))
                      << EAM(aTShade,"TypeShade",true, "Type", eSAM_None, ListOfVal(GenIm::bits1_msbf, ""))
                      << EAM(aDequant,"Dequant",true)
                      << EAM(aHypsoDyn,"HypsoDyn",true)
                      << EAM(aHypsoSat,"HypsoSat",true)
              << EAM(aSzMaxDalles,"SzMaxDalles",true)
              << EAM(aSzRecDalles,"SzRecDalles",true)
              << EAM(aModeOmbre,"ModeOmbre",true,"in {CielVu,IgnE,Local,Med,Mixte}",eSAM_None,lModeOmbre)
              << EAM(aFileMasq,"Mask",true, "Mask file", eSAM_IsExistFile)
              << EAM(aDericheFact,"DericheFact",true)
              << EAM(aNbIterF,"NbIterF",true)
              << EAM(aFactExp,"FactExp",true)
              << EAM(aDyn,"Dyn",true)
                      << EAM(aVPdsFiltre,"PdsF",true,"[CielVu,Local,Grad,Med]", eSAM_NoInit)
                      << EAM(aModeColor,"ModeColor",true,"Color mode", eSAM_None, lModeColor)
                      << EAM(aNbMed,"NbMed",true)
                      << EAM(aNbIterMed,"NbIterMed",true)
                      << EAM(aTetaH,"TetaH",true)
                      << EAM(anAzimut,"Azimut",true)
    );

    if (!MMVisualMode)
    {

    double aPdsDef = aVPdsFiltre.size() ? 0 : 1;
    for (int aK=aVPdsFiltre.size() ; aK<4 ; aK++)
       aVPdsFiltre.push_back(aPdsDef);

    double aSPdsF = 0;
    for (int aK=0 ; aK<4 ; aK++)
       aSPdsF += aVPdsFiltre[aK];
    for (int aK=0 ; aK<4 ; aK++)
        aVPdsFiltre[aK] /= aSPdsF;


    std::string aDir,aNameFileIn;
    SplitDirAndFile(aDir,aNameFileIn,aNameIn);



     bool WithHypso = (aHypsoDyn>0) || (aNameCol != "");
     // bool WithCol =   (aNameCol != "");


    if (aNameOut=="")
       aNameOut = StdPrefix(aNameIn) +std::string("Shade.tif");

     Tiff_Im aFileIn = Tiff_Im::StdConvGen(aNameIn,1,true,false);
     if (aSzGlob== Pt2di(0,0))
        aSzGlob = aFileIn.sz() -aP0Glob;
     Fonc_Num aFIn = aFileIn.in_gen(Tiff_Im::eModeCoulGray,Tiff_Im::eModeNoProl);

    {
        Tiff_Im
        (
             aNameOut.c_str(),
             aSzGlob,
             GenIm::u_int1,
         Tiff_Im::No_Compr,
         WithHypso  ? Tiff_Im::RGB : Tiff_Im::BlackIsZero
        );
    }
    Tiff_Im aTifOut(aNameOut.c_str());

     if (aSzMaxDalles.x<0) aSzMaxDalles = aSzGlob;
     Pt2di aPRD(aSzRecDalles,aSzRecDalles);
     cDecoupageInterv2D aDecoup
                    (
                            Box2di(aP0Glob,aP0Glob+aSzGlob),
                aSzMaxDalles,
                Box2di(-aPRD,aPRD)
            );

     Im2DGen aMnt =    AllocImGen(aDecoup.SzMaxIn(),aTMNt);
     Im2DGen aShade =  AllocImGen(aDecoup.SzMaxIn(),aTShade);

     cout << "SZ Max In " << aDecoup.SzMaxIn() << endl;
     REAL aRatio = ElMin(800.0/aSzGlob.x,700.0/aSzGlob.y);
     Video_Win * pW  = aVisu                          ?
                       Video_Win::PtrWStd(Pt2di(Pt2dr(aSzGlob)*aRatio)) :
                       0                              ;

     aTetaH *= (2*PI)/360.0;
     anAzimut *= (2*PI)/360.0;

     for (int aKDec=0; aKDec<aDecoup.NbInterv() ; aKDec++)
     {

         Box2di aBoxIn = aDecoup.KthIntervIn(aKDec);
     Pt2di aSzIn = aBoxIn.sz();
     Pt2di aP0In = aBoxIn.P0();

     cout << "DEQ " << aDequant << "Sz In " << aSzIn <<endl;

         REAL aVMin;
         if (aDequant)
         {
             ElImplemDequantifier aDeq(aSzIn);
             aDeq.SetTraitSpecialCuv(true);
             aDeq.DoDequantif(aSzIn, trans(aFIn,aP0In),true);
         REAL aVMax;
             ELISE_COPY
             (
                  rectangle(Pt2di(0,0),aSzIn),
                  aDeq.ImDeqReelle() * aFZ,
                  aMnt.out() | VMax(aVMax) |VMin(aVMin)
             );

         }
         else
     {
             ELISE_COPY
             (
                  rectangle(Pt2di(0,0),aSzIn),
                  trans(aFIn,aP0In)*aFZ,
                  aMnt.out()|VMin(aVMin)
             );
     }
         Im2D_Bits<1> aIMasq(aSzIn.x,aSzIn.y,1);

     if (aFileMasq!="")
     {
             if (ELISE_fp::exist_file(aDir+aFileMasq))
                aFileMasq = aDir+aFileMasq;
         double aDif=100;
         Tiff_Im aFM = Tiff_Im::StdConvGen(aFileMasq,1,true,false);
             ELISE_COPY
             (
                  select(rectangle(Pt2di(0,0),aSzIn),trans(!aFM.in_proj(),aP0In)),
          aVMin-aDif,
                     aMnt.out()
                  |  (aIMasq.out() << 0)
             );
         aVMin-= aDif;
     }

         if (aBrd>0)
         {
            cout << "VMin = " << aVMin <<endl;
            ELISE_COPY(aMnt.border(aBrd),aVMin-1000,aMnt.out());
         }

     // Im2D_REAL4 aShade(aSzGlob.x,aSzGlob.y);
         ELISE_COPY(aShade.all_pts(),0,aShade.out());

         if (pW)
            pW = pW->PtrChc(Pt2dr(aP0Glob-aP0In),Pt2dr(aRatio,aRatio));

         REAL SPds = 0;
         REAL aSTot = 0;
         REAL Dyn = 1.0;
         if (aTShade != "u_int1")
            Dyn = 100;

         bool Done = false;
         if (   (aModeOmbre=="CielVu")
             || ((aModeOmbre=="Mixte") && (aVPdsFiltre[0] > 0.0))
            )
     {
            std::cout << "BEGIN CIEL" << endl;
            Done = true;
            for (int aK=0 ; aK< 2 ; aK++)
            {
               SPds = 0;
               for (int i=0; i<aNbDir; i++)
               {
                  REAL Teta  = (2*PI*i) / aNbDir ;
                  Pt2dr U(cos(Teta),sin(Teta));
                  Pt2di aDir = Pt2di(U * (aNbDir * 4));
                  REAL Pds = (1-aPdsAnis) + aPdsAnis *ElSquare(1.0 - euclid(U,Pt2dr(0,1))/2);
                  if (aK==1)
                     Pds = (Pds*Dyn) / (2*aSTot);
                  Symb_FNum Gr = (1-cos(PI/2-atan(gray_level_shading(aMnt.in()))))
                             *255.0;
                  cout << "Dir " << i << " Sur " << aNbDir <<  " P= " << Pds << endl;
                  SPds  += Pds;
                  if (aK==1)
                  {
                 ELISE_COPY
                 (
                     line_map_rect(aDir,Pt2di(0,0),aSzIn),
                     Min(255*Dyn,aShade.in()+Pds*Gr),
                       aShade.out()
                         // | (pW ? (pW->ogray()<<(aShade.in()/SPds)) : Output::onul())
                         | (pW ? (pW->ogray()<<(Gr)) : Output::onul())
                     );
                  }

               }
               aSTot  = SPds;
            }
            double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[0] : 1.0;
            ELISE_COPY(aShade.all_pts(),aShade.in()*(aMul/SPds),aShade.out());
            SPds = aMul;
            std::cout << "BEGIN CIEL" << endl;
     }
     if (
                      (aModeOmbre=="Local")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[1] > 0.0))
                 )
     {
               std::cout << "BEGIN LOCAL" << endl;
               Done = true;
               Fonc_Num aFonc = aMnt.in_proj();
               Fonc_Num aMoy = aFonc;
               for (int aK=0 ; aK<aNbIterF; aK++)
                   aMoy =    canny_exp_filt(aMoy*aIMasq.in_proj(),aFactExp,aFactExp)
                          /  Max(0.1,canny_exp_filt(aIMasq.in_proj(),aFactExp,aFactExp));

               double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[1] : 1.0;
               ELISE_COPY
               (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,Min(255, aShade.in() +(128+(aFonc-aMoy)*aDyn)* aMul)),
          aShade.out()
               );
               SPds += aMul;
               std::cout << "END LOCAL" << endl;
     }
     if (
                      (aModeOmbre=="Med")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[3] > 0.0))
                 )
     {
              std::cout << "BEGIN MED" << endl;

               Done = true;
               Fonc_Num aFonc = round_ni(aMnt.in_proj()*aDynMed);
               int aVMax,aVMin;

               ELISE_COPY
               (
                   rectangle(Pt2di(-1,-1),aSzIn+Pt2di(1,1)),
                   aFonc,
                   VMin(aVMin)|VMax(aVMax)
               );

               Fonc_Num aMoy = aFonc-aVMin;

               for (int aK=0 ; aK<aNbIterMed; aK++)
                   aMoy =    rect_median(aMoy,aNbMed,aVMax-aVMin+1);

               aMoy = aMoy + aVMin;

               double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[3] : 1.0;
               ELISE_COPY
               (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,Min(255, aShade.in() +(128+((aFonc-aMoy)*aDyn)/aDynMed)* aMul)),
          aShade.out()
               );
               SPds += aMul;
              std::cout << "END MED" << endl;
     }
     if (
                      (aModeOmbre=="IgnE")
                   || ((aModeOmbre=="Mixte") && (aVPdsFiltre[2] > 0.0))
                 )
     {
int aCpt=0; aCpt++;
std::cout << "IGN E " << aCpt << " " << aKDec << "\n";
             Done = true;
if (aCpt>0)
{
         Symb_FNum aGrad =  deriche(aMnt.in_proj(),aDericheFact);
             Symb_FNum aGx = (aGrad.v0());
             Symb_FNum aGy = (aGrad.v1());
         Symb_FNum aNG = sqrt(1+Square(aGx)+Square(aGy));

         Symb_FNum aNx (aGx/aNG);
         Symb_FNum aNy (aGy/aNG);
         Symb_FNum aNz (1/aNG);



         Pt2dr  aDirS = Pt2dr::FromPolar(1.0,anAzimut) * Pt2dr(1,0);

         double aSx = aDirS.x * sin(aTetaH);
         double aSy = aDirS.y * sin(aTetaH);
         double aSz = cos(aTetaH);

         Symb_FNum aScal(aNx*aSx+aNy*aSy+aNz*aSz);

std::cout << "AAAAAAAaa" << endl;
             double aMul = (aModeOmbre=="Mixte") ? aVPdsFiltre[2] : 1.0;
             ELISE_COPY
             (
              rectangle(Pt2di(0,0),aSzIn),
          Max(0,aShade.in() + 255*aScal * aMul),
          aShade.out()
             );
             SPds += aMul;
std::cout << "BBBBbbb" << endl;
}
     }
     if (! Done)
     {
         ELISE_ASSERT(false,"Unknown ModeOmbre");
     }



        Fonc_Num aFoncRes = Max(0,Min(255,aShade.in()/SPds));
        if (WithHypso)
        {
            Fonc_Num  aFIntens = aFoncRes;
            Fonc_Num  aFTeinte = trans(aFIn,aP0In)*aHypsoDyn;
            Fonc_Num  aFSat = 255*aHypsoSat;

            if (aNameCol!="")
            {
                Tiff_Im aFileCol = Tiff_Im::StdConvGen(aDir+aNameCol,-1,true,false);
            Symb_FNum aFNC(trans(rgb_to_its(aFileCol.in()),aP0In));

                if (aModeColor == "IntensShade")
                {
                    aFIntens = aFoncRes;
                    aFTeinte = aFNC.v1();
                    aFSat = aFNC.v2();
                }
                else if (aModeColor == "BackRGB")
                {
                   aFIntens = aIMasq.in()*aFoncRes + (1- aIMasq.in()) * aFNC.v0();
                   aFTeinte = aFNC.v1();
                   aFSat = aFNC.v2() * (1- aIMasq.in());
                }
                else if (aModeColor == "GrayBackRGB")
                {
                   aFIntens = aIMasq.in()*aFoncRes + (1- aIMasq.in()) * aFNC.v0();
                   aFTeinte = aFNC.v1();
                   aFSat = aFNC.v2()*(1-aIMasq.in());
                }
                else
                {
                    ELISE_ASSERT(false,"Unknown mode color");
                }
            }
            aFoncRes = its_to_rgb(Virgule(aFIntens,aFTeinte,aFSat));
            //aFoncRes = its_to_rgb(Virgule(aFoncRes,trans(aFIn,aP0In)*aHypsoDyn,255*aHypsoSat));
        }
/*
    if (WithCol)
    {
            Tiff_Im aFileCol(aNameCol.c_str());
        Symb_FNum aFNC(trans(rgb_to_its(aFileCol.in()),aP0In));
        aFoncRes = its_to_rgb(Virgule(aFoncRes,aFNC.v1(),aFNC.v2()*aHypsoSat));
        // aFoncRes = aFileCol.in();
    }
*/

     // Tiff_Im::Create8BFromFonc(aNameOut,aShade.sz(),aShade.in()/SPds);


    cout << "WithHypso " << WithHypso << " DIM " << aFoncRes.dimf_out() <<  endl;
        Box2di aBoxOut = aDecoup.KthIntervOut(aKDec);
        ELISE_COPY
        (
            rectangle(aBoxOut.P0()-aP0Glob,aBoxOut.P1()-aP0Glob),
        trans(aFoncRes,aP0Glob-aP0In),
        aTifOut.out()
        );
     }

     return EXIT_SUCCESS;

    }
    else return EXIT_SUCCESS;
}
Пример #21
0
int HomFilterMasq_main(int argc,char ** argv)
{
    // MemoArg(argc,argv);
    MMD_InitArgcArgv(argc,argv);
    std::string  aDir,aPat,aFullDir;
    bool ExpTxt=false;
    std::string PostPlan="_Masq";
    std::string KeyCalcMasq;
    std::string KeyEquivNoMasq;
    std::string MasqGlob;
    double  aResol=10;
    bool AcceptNoMask;
    std::string aPostIn= "";
    std::string aPostOut= "MasqFiltered";



    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir,"Full name (Dir+Pat)", eSAM_IsPatFile),
    LArgMain()
                    << EAM(PostPlan,"PostPlan",true,"Post to plan, Def : toto ->toto_Masq.tif like with SaisieMasq")
                    << EAM(MasqGlob,"GlobalMasq",true,"Global Masq to add to all image")
                    << EAM(KeyCalcMasq,"KeyCalculMasq",true,"For tuning masq per image")
                    << EAM(KeyEquivNoMasq,"KeyEquivNoMasq",true,"When given if KENM(i1)==KENM(i2), don't masq")
                    << EAM(aResol,"Resol",true,"Sub Resolution for masq storing, Def=10")
                    << EAM(AcceptNoMask,"ANM",true,"Accept no mask, def = true if MasqGlob and false else")
                    << EAM(ExpTxt,"ExpTxt",true,"Ascii format for in and out, def=false")
                    << EAM(aPostIn,"PostIn",true,"Post for Input dir Hom, Def=")
                    << EAM(aPostOut,"PostOut",true,"Post for Output dir Hom, Def=MasqFiltered")

    );

    #if (ELISE_windows)
        replace( aFullDir.begin(), aFullDir.end(), '\\', '/' );
     #endif
    SplitDirAndFile(aDir,aPat,aFullDir);
    if (EAMIsInit(&PostPlan))
    {
        CorrecNameMasq(aDir,aPat,PostPlan);
    }

    if (!EAMIsInit(&AcceptNoMask))
       AcceptNoMask = EAMIsInit(&MasqGlob);


    cInterfChantierNameManipulateur * anICNM = cInterfChantierNameManipulateur::BasicAlloc(aDir);


    Im2D_Bits<1>  aImMasqGlob(1,1);
    if (EAMIsInit(&MasqGlob))
       aImMasqGlob = GetMasqSubResol(aDir+MasqGlob,aResol);


    const std::vector<std::string> *  aVN = anICNM->Get(aPat);
    std::vector<Im2D_Bits<1> >  aVMasq;

    for (int aKN = 0 ; aKN<int(aVN->size()) ; aKN++)
    {
        std::string aNameIm = (*aVN)[aKN];
        Tiff_Im aTF = Tiff_Im::StdConvGen(aNameIm,1,false);
        Pt2di aSzG = aTF.sz();
        Pt2di aSzR (round_ni(Pt2dr(aSzG)/aResol));
        Im2D_Bits<1> aImMasq(aSzR.x,aSzR.y,1);


        std::string aNameMasq = StdPrefix(aNameIm)+PostPlan + ".tif";
        if (EAMIsInit(&KeyCalcMasq))
        {
            aNameMasq = anICNM->Assoc1To1(KeyCalcMasq,aNameIm,true);
        }

        if (ELISE_fp::exist_file(aNameMasq))
        {
            Im2D_Bits<1> aImMasqLoc = GetMasqSubResol(aDir+aNameMasq,aResol);
            ELISE_COPY(aImMasq.all_pts(),aImMasq.in() && aImMasqLoc.in(0),aImMasq.out());
        }
        else
        {
             if (!AcceptNoMask)
             {
                 std::cout << "For Im " << aNameIm << " file " << aNameMasq << " does not exist\n";
                 ELISE_ASSERT(false,"Masq not found");
             }
        }

        if (EAMIsInit(&MasqGlob))
        {

            ELISE_COPY(aImMasq.all_pts(),aImMasq.in() && aImMasqGlob.in(0),aImMasq.out());
        }

        aVMasq.push_back(aImMasq);
        // Tiff_Im::CreateFromIm(aImMasq,"SousRes"+aNameMasq);
    }

    std::string anExt = ExpTxt ? "txt" : "dat";


    std::string aKHIn =   std::string("NKS-Assoc-CplIm2Hom@")
                       +  std::string(aPostIn)
                       +  std::string("@")
                       +  std::string(anExt);
    std::string aKHOut =   std::string("NKS-Assoc-CplIm2Hom@")
                        +  std::string(aPostOut)
                        +  std::string("@")
                       +  std::string(anExt);




    for (int aKN1 = 0 ; aKN1<int(aVN->size()) ; aKN1++)
    {
        for (int aKN2 = 0 ; aKN2<int(aVN->size()) ; aKN2++)
        {
             std::string aNameIm1 = (*aVN)[aKN1];
             std::string aNameIm2 = (*aVN)[aKN2];

             std::string aNameIn = aDir + anICNM->Assoc1To2(aKHIn,aNameIm1,aNameIm2,true);

             if (ELISE_fp::exist_file(aNameIn))
             {
                  bool UseMasq = true;
                  if (EAMIsInit(&KeyEquivNoMasq))
                  {
                       UseMasq =  (anICNM->Assoc1To1(KeyEquivNoMasq,aNameIm1,true) != anICNM->Assoc1To1(KeyEquivNoMasq,aNameIm2,true) );
                  }


                  TIm2DBits<1>  aMasq1 ( aVMasq[aKN1]);
                  TIm2DBits<1>  aMasq2 ( aVMasq[aKN2]);

                  ElPackHomologue aPackIn =  ElPackHomologue::FromFile(aNameIn);
                  ElPackHomologue aPackOut;
                  for (ElPackHomologue::const_iterator itP=aPackIn.begin(); itP!=aPackIn.end() ; itP++)
                  {
                      Pt2dr aP1 = itP->P1();
                      Pt2dr aP2 = itP->P2();
                      Pt2di aQ1 = round_ni(aP1/aResol);
                      Pt2di aQ2 = round_ni(aP2/aResol);

                      if ((aMasq1.get(aQ1,0) && aMasq2.get(aQ2,0)) || (! UseMasq))
                      {
                          ElCplePtsHomologues aCple(aP1,aP2);
                          aPackOut.Cple_Add(aCple);
                      }
                  }
                  std::string aNameOut = aDir + anICNM->Assoc1To2(aKHOut,aNameIm1,aNameIm2,true);
                  aPackOut.StdPutInFile(aNameOut);
                  std::cout << "IN " << aNameIn << " " << aNameOut  << " UseM " << UseMasq << "\n";
             }
        }
    }
    // std::vector<cImFMasq *> mVIm;



   return 0;
}
Пример #22
0
cTmpReechEpip::cTmpReechEpip
(
        bool aConsChan,
        const std::string & aNameOri,
        Box2dr aBoxImIn,
        ElDistortion22_Gen * anEpi,
        Box2dr aBox,
        double aStep,
        const std::string & aNameOut,
        const std::string & aPostMasq,
        int aNumKer ,
        bool Debug
) :
    mBoxImIn(aBoxImIn),
    mEpi    (anEpi),
    mStep   (aStep),
    mP0     (aBox._p0),
    mSzEpi  (aBox.sz()),
    mSzRed  (round_up (aBox.sz() / aStep) + Pt2di(1,1)),
    mRedIMasq  (mSzRed.x,mSzRed.y,0),
    mRedTMasq  (mRedIMasq),
    mRedImX    (mSzRed.x,mSzRed.y),
    mRedTImX   (mRedImX),
    mRedImY    (mSzRed.x,mSzRed.y),
    mRedTImY   (mRedImY)
{



    cInterpolateurIm2D<REAL4> * aPtrSCI = 0;


    if (aNumKer==0)
    {
        aPtrSCI = new cInterpolBilineaire<REAL4>;
    }
    else 
    {
      
       cKernelInterpol1D * aKer = 0;
       if (aNumKer==1)
          aKer = new cCubicInterpKernel(-0.5);
       else
          aKer = new cSinCardApodInterpol1D(cSinCardApodInterpol1D::eTukeyApod,aNumKer,aNumKer/2,1e-4,false);

       aPtrSCI =  new  cTabIM2D_FromIm2D<REAL4>   (aKer,1000,false);
       // cTabIM2D_FromIm2D<REAL4>   aSSCI (&aKer,1000,false);
    }

    cInterpolateurIm2D<REAL4> & aSCI = *aPtrSCI;



    Pt2di aPInd;

    for (aPInd.x=0 ; aPInd.x<mSzRed.x ; aPInd.x++)
    {
       for (aPInd.y=0 ; aPInd.y<mSzRed.y ; aPInd.y++)
       {
          bool Ok= false;
          Pt2dr aPEpi = ToFullEpiCoord(aPInd);
          Pt2dr aPIm =  anEpi->Inverse(aPEpi);
          if ((aPIm.x>mBoxImIn._p0.x) && (aPIm.y>mBoxImIn._p0.y) && (aPIm.x<mBoxImIn._p1.x) && (aPIm.y<mBoxImIn._p1.y))
          {
               Pt2dr aPEpi2 = anEpi->Direct(aPIm);
               if (euclid(aPEpi-aPEpi2) < 1e-2)
               {
                    Ok= true;
                    mRedTMasq.oset(aPInd,Ok);
               }
          }
          mRedTImX.oset(aPInd,aPIm.x);
          mRedTImY.oset(aPInd,aPIm.y);
       }
    }
    ELISE_COPY(mRedIMasq.all_pts(),dilat_d8(mRedIMasq.in(0),4),mRedIMasq.out());


    Tiff_Im aTifOri = Tiff_Im::StdConvGen(aNameOri.c_str(),aConsChan ? -1 :1 ,true);
    Tiff_Im aTifEpi  = Debug                       ?
                       Tiff_Im(aNameOut.c_str())     :
                       Tiff_Im
                       (
                           aNameOut.c_str(),
                           mSzEpi,
                           aTifOri.type_el(),
                           Tiff_Im::No_Compr,
                           aTifOri.phot_interp()
                       )                            ;

    Tiff_Im aTifMasq = aTifEpi;
    bool ExportMasq = (aPostMasq!="NONE");

// std::cout << "POSTMAS " << aPostMasq << "\n";

    if (ExportMasq)
    {
        std::string aNameMasq = StdPrefix(aNameOut)+ aPostMasq  +".tif";
        aTifMasq =  Debug                         ?
                    Tiff_Im(aNameMasq.c_str())    :
                    Tiff_Im
                    (
                        aNameMasq.c_str(),
                        mSzEpi,
                        GenIm::bits1_msbf,
                        Tiff_Im::No_Compr,
                        Tiff_Im::BlackIsZero
                    )                             ;
    }





    int aNbBloc=2000;
    int aBrd = aNumKer+10;
    Pt2di aSzBrd(aBrd,aBrd);

    int aX00 = 0;
    int aY00 = 0;

    for (int aX0=aX00 ; aX0<mSzEpi.x ; aX0+=aNbBloc)
    {
         int aX1 = ElMin(aX0+aNbBloc,mSzEpi.x);
         for (int aY0=aY00 ; aY0<mSzEpi.y ; aY0+=aNbBloc)
         {
// std::cout << "X0Y0 " << aX0 << " " << aY0 << "\n";

             int aY1 = ElMin(aY0+aNbBloc,mSzEpi.y);

             Pt2di aP0Epi(aX0,aY0);
             Pt2di aSzBloc(aX1-aX0,aY1-aY0);

             TIm2D<REAL4,REAL8> aTImX(aSzBloc);
             TIm2D<REAL4,REAL8> aTImY(aSzBloc);
             TIm2DBits<1>       aTImMasq(aSzBloc,0);

             Pt2dr aInfIm(1e20,1e20);
             Pt2dr aSupIm(-1e20,-1e20);
             bool  NonVide= false;

             for (int anX =aX0 ; anX<aX1  ; anX++)
             {
                 for (int anY =aY0 ; anY<aY1  ; anY++)
                 {
                     Pt2dr aIndEpi (anX/mStep , anY/mStep);
                     Pt2di aPIndLoc (anX-aX0,anY-aY0);
                     if (mRedTMasq.get(round_down(aIndEpi)))
                     {
                        double aXIm = mRedTImX.getr(aIndEpi,-1,true);
                        double aYIm = mRedTImY.getr(aIndEpi,-1,true);

                        if ((aXIm>0) && (aYIm>0))
                        {
                            // aTImMasq.oset(aPIndLoc,1);
                            aTImX.oset(aPIndLoc,aXIm);
                            aTImY.oset(aPIndLoc,aYIm);

                            aInfIm  = Inf(aInfIm,Pt2dr(aXIm,aYIm));
                            aSupIm  = Sup(aSupIm,Pt2dr(aXIm,aYIm));
                            NonVide= true;
                        }
                     }
                 }
             }
             Pt2di aP0BoxIm = Sup(Pt2di(0,0),Pt2di(round_down(aInfIm) - aSzBrd));
             Pt2di aP1BoxIm = Inf(aTifOri.sz(),Pt2di(round_down(aSupIm) + aSzBrd));
             Pt2di aSzIm = aP1BoxIm - aP0BoxIm;
             NonVide = NonVide && (aSzIm.x>0) && (aSzIm.y>0);
             if (NonVide)
             {

                 // std::vector<Im2D_REAL4>  aVIm;

                 std::vector<Im2D_REAL4>  aVIm= aTifOri.VecOfImFloat(aSzIm);

                 ELISE_COPY
                 (
                     rectangle(Pt2di(0,0),aSzIm),
                     trans(aTifOri.in(),aP0BoxIm),
                     StdOut(aVIm)
                 );

                 std::vector<Im2D_REAL4>  aVImEpi = aTifEpi.VecOfImFloat(aSzBloc);
                 ELISE_ASSERT(aVImEpi.size()==aVIm.size(),"Incohe in nb chan, cTmpReechEpip::cTmpReechEpip");

                 for (int aKIm=0 ; aKIm <int(aVImEpi.size()) ; aKIm++)
                 {
                      TIm2D<REAL4,REAL8> aImEpi(aVImEpi[aKIm]);
                      REAL4 ** aDataOri = aVIm[aKIm].data();
                      for (int anX =0 ; anX<aSzBloc.x ; anX++)
                      {
                           for (int anY =0 ; anY<aSzBloc.y ; anY++)
                           {

                               Pt2di aIndEpi(anX,anY);
                               aImEpi.oset(aIndEpi,0);
                               Pt2di anIndEpiGlob  = aIndEpi + aP0Epi;

                               Pt2dr aIndEpiRed (anIndEpiGlob.x/mStep , anIndEpiGlob.y/mStep);
                               if (mRedTMasq.get(round_down(aIndEpiRed),0))
                               {
                                   double aXIm = mRedTImX.getr(aIndEpiRed,-1,true);
                                   double aYIm = mRedTImY.getr(aIndEpiRed,-1,true);
                                   Pt2dr aPImLoc = Pt2dr(aXIm,aYIm) - Pt2dr(aP0BoxIm);
                                   double aV= 128;
                                   if ((aPImLoc.x>aNumKer+2) && (aPImLoc.y>aNumKer+2) && (aPImLoc.x<aSzIm.x-aNumKer-3) && (aPImLoc.y<aSzIm.y-aNumKer-3))
                                   {
                                       aTImMasq.oset(aIndEpi,1);
                                       aV = aSCI.GetVal(aDataOri,aPImLoc);
                                       // aV= 255;
                                   }
                                   aImEpi.oset(aIndEpi,aV);
                               }
                           }
                      }
                 }
                 ELISE_COPY
                 (
                     rectangle(aP0Epi,aP0Epi+aSzBloc),
                     Tronque(aTifEpi.type_el(),trans(StdInput(aVImEpi),-aP0Epi)),
                     aTifEpi.out()
                 );
             }
             if (ExportMasq)
             {
                ELISE_COPY
                (
                    rectangle(aP0Epi,aP0Epi+aSzBloc),
                    trans(aTImMasq._the_im.in(0),-aP0Epi),
                    aTifMasq.out()
                );
             }
             // std::cout << "ReechDONE " <<  aX0 << " "<< aY0 << "\n";

         }
    }
}
Пример #23
0
int ConvertIm_main(int argc,char ** argv)
{
    MMD_InitArgcArgv(argc,argv);
    Tiff_Im::SetDefTileFile(1000000);


    std::string aNameIn ;

    INT aReducX=0;
    INT aReducY=0;
    INT aReducXY=0;
    INT aVisu=0;
    GenIm::type_el aTypeOut ;
    std::string aNameTypeOut ="";

    Tiff_Im::PH_INTER_TYPE aPhInterpOut ;
    std::string aNamePITOut ="";
    std::string PITOut[] = {"RGB","BW"};
    std::list<std::string> lOut(PITOut, PITOut + sizeof(PITOut) / sizeof(std::string) );

    std::string aNameOut;
    std::string anExt;

    Pt2di aP0(0,0);

    Pt2di aSzOut ;
    Pt2di aSzTF(-1,-1);

    REAL aDyn=1.0;

    Pt2di aSzTileInterne(-1,-1);
    int aKCh = -1;


    std::vector<int> aVPermut;
    int aNoTile = 0;
    std::string aF2 ="";


    ElInitArgMain
    (
    argc,argv,
                LArgMain()  << EAMC(aNameIn, "Image", eSAM_IsExistFile),
    LArgMain()  << EAM(aNameOut,"Out",true)
                << EAM(anExt,"Ext",true)
                    << EAM(aSzOut,"SzOut",true, "Size out", eSAM_NoInit)
                    << EAM(aP0,"P0",true)
                    << EAM(aNameTypeOut,"Type",true, "TypeMNT", eSAM_None, ListOfVal(GenIm::bits1_msbf, ""))
                    << EAM(aNamePITOut,"Col",true, "Col", eSAM_None,lOut)
                    << EAM(aReducXY,"ReducXY",true)
                    << EAM(aReducX,"ReducX",true)
                    << EAM(aReducY,"ReducY",true)
                    << EAM(aVisu,"Visu",true)
                    << EAM(aSzTF,"SzTifTile",true)
                    << EAM(aSzTileInterne,"SzTileInterne",true)
                    << EAM(aDyn,"Dyn",true)
                    << EAM(aKCh,"KCh",true)
                    << EAM(aNoTile,"NoTile",true)
                    << EAM(aVPermut,"Permut",true, "Permut", eSAM_NoInit)
                    << EAM(aF2,"F2",true)
    );

    if (!MMVisualMode)
    {
        // Tiff_Im aTifIn = Tiff_Im::BasicConvStd(aNameIn);
        Tiff_Im aTifIn = Tiff_Im::UnivConvStd(aNameIn);
        INT aNbChIn = aTifIn.nb_chan();

        if (! EAMIsInit(&aTypeOut)) aTypeOut =aTifIn.type_el();
        if (! EAMIsInit(&aPhInterpOut)) aPhInterpOut =  aTifIn.phot_interp();
        if (! EAMIsInit(&aSzOut)) aSzOut = aTifIn.sz();

        if (aReducXY)
        {
            aReducX = 1;
            aReducY = 1;
        }
        if (aNameOut=="")
        {
            if (anExt=="")
            {
                if (aReducX && aReducY)
                    anExt = "_RXY";
                else if (aReducX)
                    anExt = "_RX";
                else if (aReducY)
                    anExt = "_RY";
                else
                    anExt= "_Out";
            }
            if (IsPostfixed(aNameIn))
              aNameOut = StdPrefix(aNameIn) + anExt +"." + StdPostfix(aNameIn);
           else
              aNameOut = aNameIn + anExt + "tif";
        }

        Pt2di aCoefReduc(aReducX != 0 ? 2 : 1, aReducY != 0 ? 2 : 1);
        aSzOut = aSzOut.dcbyc(aCoefReduc);

        if (aNameTypeOut != "")
           aTypeOut = type_im(aNameTypeOut);

        if (aKCh != -1)
           aNamePITOut="BW";

        if ( aVPermut.size() !=0)
        {
             if ( aVPermut.size() ==1)
                 aPhInterpOut = Tiff_Im::BlackIsZero;
             else if ( aVPermut.size() ==3)
                 aPhInterpOut = Tiff_Im::RGB;
             else
            {
               ELISE_ASSERT(aNamePITOut=="","Nb Canaux incoherents");
            }
        }
        else
        {
            if (aNamePITOut=="RGB")
               aPhInterpOut = Tiff_Im::RGB;
            else if (aNamePITOut=="BW")
               aPhInterpOut = Tiff_Im::BlackIsZero;
            else
            {
               ELISE_ASSERT(aNamePITOut=="","Mode Couleur Inconnu");
            }
        }


        Tiff_Im::COMPR_TYPE aComprOut = Tiff_Im::No_Compr;


        L_Arg_Opt_Tiff aLArg = Tiff_Im::Empty_ARG;


        if (! aNoTile)
        {
           if (aSzTileInterne != Pt2di(-1,-1))
               aLArg = aLArg + Arg_Tiff(Tiff_Im::ATiles(aSzTileInterne));

           if (aSzTF != Pt2di(-1,-1))
               aLArg = aLArg + Arg_Tiff(Tiff_Im::AFileTiling(aSzTF));
        }
        else
        {
             aLArg = aLArg + Arg_Tiff(Tiff_Im::ANoStrip());
             aLArg = aLArg + Arg_Tiff(Tiff_Im::AFileTiling(Pt2di(-1,-1)));
        }


        Tiff_Im aTifOut
                (
                      aNameOut.c_str(),
                      aSzOut,
                      aTypeOut,
                      aComprOut,
                      aPhInterpOut,
                      aLArg
                );
        INT aNbChOut = aTifOut.nb_chan();

        Pt2di aSzROut = aSzOut;
        Output anOut = aTifOut.out();

        Fonc_Num aFin = aTifIn.in_proj();
        if (aF2!="")
        {
             Tiff_Im aT2 = Tiff_Im::BasicConvStd(DirOfFile(aNameIn)+aF2);
             aFin = Virgule(aFin,aT2.in(0));
        }

        if (aVPermut.size() != 0)
           aFin = aFin.permut(aVPermut);

        if (type_im_integral( aTypeOut))
        {
        }
        else
        {
            aFin = Rconv(aFin);
        }

        aFin = reduc_binaire_gen(aFin, aReducX != 0, aReducY != 0, 16, true, 0);
        anOut = Filtre_Out_RedBin_Gen(anOut, aReducX != 0, aReducY != 0);
        aSzROut = aSzOut.mcbyc(aCoefReduc);
        aFin = trans(aFin,aP0);

        if (aKCh!=-1)
           aFin = aFin.kth_proj(aKCh);
        else
        {

            if ((aNbChOut==1) && (aNbChIn==3))
                aFin = (aFin.v0() + aFin.v1() + aFin.v2()) / 3.0;

            if ((aNbChOut==3) && (aNbChIn==1))
               aFin = Virgule(aFin,aFin,aFin);
         }


        if (aVisu)
           anOut = anOut |  Video_Win::WiewAv(aSzROut);

        if (aDyn != 1.0)
           aFin = aFin * aDyn;

        if (type_im_integral(aTypeOut) && (aTypeOut!=GenIm::int4))
        {
            int aVMin,aVMax;
            min_max_type_num(aTypeOut,aVMin,aVMax);
            aFin = Max(aVMin,Min(aVMax-1,aFin));
        }

        ELISE_COPY(rectangle(Pt2di(0,0),aSzROut),aFin,anOut);

        return EXIT_SUCCESS;
    }
    else return EXIT_SUCCESS;
}
Пример #24
0
void cEtapeMecComp::OneBasculeMnt
(
    Pt2di aP0Sauv,
    Pt2di aP1Sauv,
    cBasculeRes & aBR,
    float ** aDataF,
    INT2 ** aDataI,
    Pt2di   aSzData
)
{
    ELISE_ASSERT
    (
        mIsOptimCont,
        "Basculement requiert une optimisation continue "
    );

    cFileOriMnt anOri;
    if (aBR.Explicite().IsInit())
    {
        anOri = aBR.Explicite().Val();
        std::string aNameXML =    mAppli.FullDirResult()
                                  + StdPrefixGen(anOri.NameFileMnt())
                                  + std::string(".xml");
        MakeFileXML(anOri,aNameXML);
    }
    else if (aBR.ByFileNomChantier().IsInit())
    {
        std::string aNameFile =
            mAppli.WorkDir()
            +   aBR.Prefixe()
            +   (aBR.NomChantier().Val() ? mAppli.NameChantier() :"")
            +   aBR.Postfixe();


        anOri = StdGetObjFromFile<cFileOriMnt>
                (
                    aNameFile,
                    mAppli.NameSpecXML(),
                    aBR.NameTag().Val(),
                    "FileOriMnt"

                );
    }
    else
    {
        ELISE_ASSERT(false,"Internal Error cEtapeMecComp::OneBasculeMnt");
    }
    // cFileOriMnt * aPtrOri=0;
    // cFileOriMnt * aPtrOri=0;

    // cFileOriMnt & anOri = aBR.Ori();

    // std::cout << "XML MADE \n"; getchar();

    const cGeomBasculement3D * aGeomB = 0;

    if (anOri.Geometrie() == eGeomMNTEuclid)
    {
        if (
            (mAppli.GeomMNT()==eGeomMNTFaisceauIm1ZTerrain_Px1D)
            || (mAppli.GeomMNT()==eGeomMNTFaisceauIm1ZTerrain_Px2D)
        )
        {
            aGeomB = (mAppli.PDV1()->Geom().GeoTerrainIntrinseque());
        }
        /*
         CE CAS PARTICULIER VIENT DE CE QUE cGeomImage_Faisceau redifinit la methode
        Bascule. A ete utilise avec Denis Feurer & Co pour basculer en terrain
        les reultat image.
        */
        else if (
            (mAppli.GeomMNT()==eGeomMNTFaisceauIm1PrCh_Px1D)
            || (mAppli.GeomMNT()==eGeomMNTFaisceauIm1PrCh_Px2D)
        )
        {
            aGeomB = &(mAppli.PDV2()->Geom());
        }
        else
        {
            ELISE_ASSERT(false,"Geometrie source non traitee dans le basculement");
        }
    }
    else
    {
        ELISE_ASSERT(false,"Geometrie destination non traitee dans le basculement");
    }

    Pt2dr  aP0 = mGeomTer.DiscToR2(Pt2di(0,0));
    Pt2dr  aP1 = mGeomTer.DiscToR2(Pt2di(1,1));


    cBasculeMNT   aBasc
    (
        mGeomTer,
        aP0,
        aP1-aP0,
        anOri.OriginePlani(),
        anOri.ResolutionPlani(),
        aGeomB,
        mIsOptimCont,
        aDataF,
        aDataI,
        aSzData
    );

    Pt2di anOffset;
    double aDef = -1e10;
    double aSousDef = -9e9;

    std::cout << "BEGIN BASCULE \n";
//Im2D_REAL4   aMnt=  aBasc.Basculer(anOffset,aP0Sauv,aP1Sauv,aDef);
    Im2D_REAL4   aMnt=  aBasc.BasculerAndInterpoleInverse(anOffset,aP0Sauv,aP1Sauv,(float)aDef);


    ELISE_COPY
    (
        select(aMnt.all_pts(),aMnt.in() > aSousDef),
        (aMnt.in()-anOri.OrigineAlti())/anOri.ResolutionAlti(),
        aMnt.out()
    );

    std::cout  << anOffset << " " << aMnt.sz();
    std::cout << "END  BASCULE \n";

    bool isNewFile;
    Tiff_Im aFileRes = Tiff_Im::CreateIfNeeded
                       (
                           isNewFile,
                           anOri.NameFileMnt(),
                           anOri.NombrePixels(),
                           GenIm::real4,
                           Tiff_Im::No_Compr,
                           Tiff_Im::BlackIsZero
                       );
    Tiff_Im * aFileMasq =0;
    if ( anOri.NameFileMasque().IsInit())
    {
        aFileMasq = new Tiff_Im(Tiff_Im::CreateIfNeeded
                                (
                                    isNewFile,
                                    anOri.NameFileMasque().Val(),
                                    anOri.NombrePixels(),
                                    GenIm::bits1_msbf,
                                    Tiff_Im::No_Compr,
                                    Tiff_Im::BlackIsZero
                                )
                               );
    }

    if (isNewFile)
    {
        ELISE_COPY
        (
            aFileRes.all_pts(),
            aBR.OutValue().Val(),
            aFileRes.out()
        );
        if (aFileMasq)
        {
            ELISE_COPY
            (
                aFileMasq->all_pts(),
                0,
                aFileMasq->out()
            );
        }
    }

    Im2D_REAL4 anOld(aMnt.sz().x,aMnt.sz().y);

    ELISE_COPY
    (
        anOld.all_pts(),
        trans(aFileRes.in(aBR.OutValue().Val()),anOffset),
        anOld.out()
    );
    ELISE_COPY
    (
        select(anOld.all_pts(),aMnt.in()>aSousDef),
        aMnt.in(),
        anOld.out()
    );
    ELISE_COPY
    (
        rectangle(anOffset,anOffset+aMnt.sz()),
        trans(anOld.in(),-anOffset),
        aFileRes.out()
    );

    if (aFileMasq)
    {
        ELISE_COPY
        (
            rectangle(anOffset,anOffset+aMnt.sz()),
            aFileMasq->in(0) || trans(aMnt.in()>aSousDef,-anOffset),
            aFileMasq->out()
        );
    }

    delete aFileMasq;
}
void cModeleAnalytiqueComp::MakeExport()
{
   if (!mModele.MakeExport().Val())
      return;

    cMatrCorresp * pMatr = GetMatr(mModele.PasCalcul(),mModele.PointUnique().Val());

    const ElPackHomologue *  aPackIn =0;
    ElPackHomologue  aPackRef;
    ElPackHomologue  aNewPack;
    if (mModele.UseHomologueReference().Val())
    {
        aPackRef =  mAppli.PDV1()->ReadPackHom(mAppli.PDV2());
        aPackIn = & aPackRef;
    }
    else
    {
        aPackIn = & pMatr->PackHomCorr();
    }
 

    /* 
     *      FILTRAGE EVENTUEL DES POINTS HOMOLOGUES 
    */

    double aTol = mAppli.TolerancePointHomInImage().Val();
    double aFiltre = mAppli.FiltragePointHomInImage().Val();

    bool GotOut = false;

   
    switch (mModele.TypeModele())
    {

         case eTMA_Homologues :
              SauvHomologues(pMatr->PackHomInit());
         break;
         
         case eTMA_DHomD :
	 // std::cout << "PKS = " << aPackIn->size() << "\n"; getchar();
              SolveHomographie(*aPackIn);
              SauvHomologues(pMatr->PackHomInit());
         break;

         case eTMA_Ori :
         {
              if ((aTol<1e10) || (aFiltre !=0))
              {
                  GotOut = FiltragePointHomologues(pMatr->PackHomInit(),aNewPack,aTol,aFiltre);
                  aPackIn = &  aNewPack;
              }
              SauvHomologues(pMatr->PackHomInit());
	      if (mModele.AffineOrient().Val())
	      {
                 cMA_AffineOrient  aMAAO
                                (
                                    mAppli,
                                    *this,
                                    mGeoTer,
                                    mModele.L1CalcOri().Val(),
                                    pMatr->Sz(),
                                    *aPackIn
                                 );
              // SauvHomologues(*aPackIn);
                 if (mModele.MakeImagePxRef().Val())
                 {
                    aMAAO.MakeImagePxRef();
                 }
	      }
         }
         break;


	 case eTMA_Nuage3D :
	 {
	     std::string aNameRes =   std::string("Nuage3D")
	                            + mAppli.NameChantier() 
				    + std::string(".tif");
	     if (mModele.KeyNuage3D().IsInit())
	     {
	        aNameRes = mAppli.ICNM()->Assoc1To1
		           (
                               mModele.KeyNuage3D().Val(),
                               mAppli.NameChantier(),
                               true
                           );
	     }
	     aNameRes = mAppli.FullDirResult() + aNameRes;
	     Tiff_Im aFile
	             (
		         aNameRes.c_str(),
			 pMatr->ImAppX().sz(),
			 GenIm::real4,
			 Tiff_Im::No_Compr,
			 Tiff_Im::PtDAppuisDense
		     );
             ELISE_COPY
	     (
	          aFile.all_pts(),
		  Virgule
		  (
                      pMatr->ImPds().in(),
                      pMatr->ImAppX().in(),
                      pMatr->ImAppY().in(),
                      pMatr->ImAppZ().in()
		  ),
		  aFile.out()
	     );

	 }

         break;


         default :
            ELISE_ASSERT(false,"TypeModeleAnalytique Non Traite");
         break;
    }
    delete pMatr;
    if (GotOut)
    {
         mAppli.MicMacErreur
         (
            eErrPtHomHorsImage,
            "Point Homologue Hors Image",
            "Specification Utilisateur sur la Tolerance : <TolerancePointHomInImage>"
         );
    }
}
Пример #26
0
void Drunk(string aFullPattern,string aOri,string DirOut, bool Talk)
{
    string aPattern,aNameDir;
    SplitDirAndFile(aNameDir,aPattern,aFullPattern);

    //Reading input files
    list<string> ListIm=RegexListFileMatch(aNameDir,aPattern,1,false);
    int nbIm=ListIm.size();
    if (Talk){cout<<"Images to process: "<<nbIm<<endl;}

    //Paralelizing (an instance of Drunk is called for each image)
    string cmdDRUNK;
    list<string> ListDrunk;
    if(nbIm!=1)
    {
        for(int i=1;i<=nbIm;i++)
        {
            string aFullName=ListIm.front();
            ListIm.pop_front();
            cmdDRUNK=MMDir() + "bin/Drunk " + aNameDir + aFullName + " " + aOri + " Out=" + DirOut + " Talk=0";
            ListDrunk.push_back(cmdDRUNK);
        }
        cEl_GPAO::DoComInParal(ListDrunk,aNameDir + "MkDrunk");

        //Calling the banner at the end
        if (Talk){Drunk_Banniere();}
    }else{

    //Bulding the output file system
    ELISE_fp::MkDirRec(aNameDir + DirOut);

    //Processing the image
    string aNameIm=ListIm.front();
    string aNameOut=aNameDir + DirOut + aNameIm + ".tif";

    //Loading the camera
    string aNameCam="Ori-"+aOri+"/Orientation-"+aNameIm+".xml";
    cInterfChantierNameManipulateur * anICNM = cInterfChantierNameManipulateur::BasicAlloc(aNameDir);
    CamStenope * aCam = CamOrientGenFromFile(aNameCam,anICNM);

    //Reading the image and creating the objects to be manipulated
    Tiff_Im aTF= Tiff_Im::StdConvGen(aNameDir + aNameIm,3,false);

    Pt2di aSz = aTF.sz();

    Im2D_U_INT1  aImR(aSz.x,aSz.y);
    Im2D_U_INT1  aImG(aSz.x,aSz.y);
    Im2D_U_INT1  aImB(aSz.x,aSz.y);
    Im2D_U_INT1  aImROut(aSz.x,aSz.y);
    Im2D_U_INT1  aImGOut(aSz.x,aSz.y);
    Im2D_U_INT1  aImBOut(aSz.x,aSz.y);

    ELISE_COPY
    (
       aTF.all_pts(),
       aTF.in(),
       Virgule(aImR.out(),aImG.out(),aImB.out())
    );

    U_INT1 ** aDataR = aImR.data();
    U_INT1 ** aDataG = aImG.data();
    U_INT1 ** aDataB = aImB.data();
    U_INT1 ** aDataROut = aImROut.data();
    U_INT1 ** aDataGOut = aImGOut.data();
    U_INT1 ** aDataBOut = aImBOut.data();

    //Parcours des points de l'image de sortie et remplissage des valeurs
    Pt2dr ptOut;
    for (int aY=0 ; aY<aSz.y  ; aY++)
    {
        for (int aX=0 ; aX<aSz.x  ; aX++)
        {
            ptOut=aCam->DistDirecte(Pt2dr(aX,aY));

            aDataROut[aY][aX] = Reechantillonnage::biline(aDataR, aSz.x, aSz.y, ptOut);
            aDataGOut[aY][aX] = Reechantillonnage::biline(aDataG, aSz.x, aSz.y, ptOut);
            aDataBOut[aY][aX] = Reechantillonnage::biline(aDataB, aSz.x, aSz.y, ptOut);

        }
    }

    Tiff_Im  aTOut
             (
                  aNameOut.c_str(),
                  aSz,
                  GenIm::u_int1,
                  Tiff_Im::No_Compr,
                  Tiff_Im::RGB
             );


     ELISE_COPY
     (
         aTOut.all_pts(),
         Virgule(aImROut.in(),aImGOut.in(),aImBOut.in()),
         aTOut.out()
     );
    }
}
cMA_AffineOrient::cMA_AffineOrient
(
    cAppliMICMAC &               anAppli,
    cModeleAnalytiqueComp & aModele,
    const cGeomDiscFPx &    aGeoTer,
    bool                    L1,
    const Pt2di &               aSzM,
    const ElPackHomologue &     aPackHom
)  :
   mAppli     (anAppli),
   mSzM       (aSzM),
   mImResidu  (mSzM.x,mSzM.y),
   mTImResidu (mImResidu),
   mImPds     (mSzM.x,mSzM.y),
   mTImPds    (mImPds),
   mGeoTer (aGeoTer),
   mPas    (aModele.Modele().PasCalcul()),
   mOri1   (aModele.mGeom1.GetOriNN()),
   mOri2   (aModele.mGeom2.GetOriNN()),
   mOC1    (new cOrientationConique(mOri1->StdExportCalibGlob())),
   mOC2    (new cOrientationConique(mOri2->StdExportCalibGlob())),
   // OO mOC1    (mOri1->OC() ? new cOrientationConique(*(mOri1->OC())) : 0),
   // OO mOC2    (mOri2->OC() ? new cOrientationConique(*(mOri2->OC())) : 0),
   mNbPtMin  (aModele.Modele().NbPtMinValideEqOriRel().Val()),
   mNewOri1 (*(mOri1->Dupl())),
   mNewOri2 (*(mOri2->Dupl())),
   mCam1   (*mOri1),
   mCam2   (*mOri2),
   mPack   (aPackHom),
   mSetEq  (
              (L1 ? cNameSpaceEqF::eSysL1Barrodale : cNameSpaceEqF::eSysPlein),
              mPack.size()
           ),
   mChR    (Pt3dr(0,0,0),0,0,0),
   // mSetEq (cNameSpaceEqF::eSysL1Barrodale,mPack.size()),

             // On va donner des points corriges de  la dist :
   // mPIF    (mSetEq.NewParamIntrNoDist(1.0,Pt2dr(0,0))),
   mPIF    (mSetEq.NewParamIntrNoDist(true,new CamStenopeIdeale(true,1.0,Pt2dr(0,0),aNoPAF))),

   
   mCamF1  (mPIF->NewCam
                 (
                      cNameSpaceEqF::eRotFigee,
                      mChR * mCam1.Orient().inv()
                 )
            ),
    mCamF2  (mPIF->NewCam
                 (
                      cNameSpaceEqF::eRotBaseU,
                      mChR * mCam2.Orient().inv(),
                      mCamF1
                 )
             ),
    mCpl12   (mSetEq.NewCpleCam(*mCamF1,*mCamF2)),
    mFocale  (mOri1->Focale())
{


   mSetEq.SetClosed();
   mPIF->SetFocFree(false);
   mPIF->SetPPFree(false);

   int aNbEtape = 9;
   int aFlag = 0;
   for 
   (
      std::list<int>::const_iterator itB = aModele.Modele().NumsAngleFiges().begin();
      itB != aModele.Modele().NumsAngleFiges().end();
      itB++
   )
      aFlag  |= 1 << *itB;


   for (int aK=0 ; aK<aNbEtape ; aK++)
   {
      mCamF2->RF().SetFlagAnglFige(aFlag);
/*
       mCamF2->RF().SetModeRot
       (
            (aK<3) ?
            cNameSpaceEqF::eRotCOptFige :
            cNameSpaceEqF::eRotBaseU
       );
*/
       OneItere(aK==(aNbEtape-1)); 
   }
   std::string  aName =    mAppli.FullDirResult() 
                         + std::string("Residus_Dz")
                         +  ToString(round_ni(mGeoTer.DeZoom()))
                         + std::string("_")
                         + mAppli.NameChantier() 
                         + std::string(".tif");
    Tiff_Im aFileResidu
            (
                aName.c_str(),
                mSzM,
                GenIm::u_int1,
                Tiff_Im::No_Compr,
                Tiff_Im::RGB
            );


   mNewOri2.SetOrientation(mCamF2->RF().CurRot());
   Pt3dr  aPMoy = CalcPtMoy(mNewOri1,mNewOri2);
   mNewOri1.SetAltiSol(aPMoy.z);
   mNewOri2.SetAltiSol(aPMoy.z);

   
   std::string aNAu = aModele.Modele().AutomSelExportOri().Val();
   std::string aNEx1 = aModele.Modele().AutomNamesExportOri1().Val();
   std::string aNEx2 = aModele.Modele().AutomNamesExportOri2().Val();
   std::string aNI1 = mAppli.PDV1()->Name();
   std::string aNI2 = mAppli.PDV2()->Name();
   std::string aNOri1 =   mAppli.FullDirGeom()
                        + StdNameFromCple(aModele.AutomExport(),aNAu,aNEx1,"@",aNI1,aNI2);
   std::string aNOri2 =   mAppli.FullDirGeom()
                        + StdNameFromCple(aModele.AutomExport(),aNAu,aNEx2,"@",aNI1,aNI2);

   bool aXmlRes = false;

   if (StdPostfix(aNOri1)== "xml")
   {
       aXmlRes = true;
       ELISE_ASSERT
       (
              (StdPostfix(aNOri2)=="xml")
	   && (mOC1!=0) && (mOC2!=0),
	   "Incoherence in  XML export for cMA_AffineOrient"
       );
       // Les points de verifs, si ils existent n'ont pas de raison d'etre transposables
       mOC1->Verif().SetNoInit();
       mOC2->Verif().SetNoInit();

       ElRotation3D aR1 = mCamF1->RF().CurRot();
       ElRotation3D aR2 = mCamF2->RF().CurRot();
       mOC2->Externe()  = From_Std_RAff_C2M(aR2,mOC2->Externe().ParamRotation().CodageMatr().IsInit());

       mOC1->Externe().AltiSol().SetVal(aPMoy.z);
       mOC2->Externe().AltiSol().SetVal(aPMoy.z);

       mOC1->Externe().Profondeur().SetVal(ProfFromCam(aR1.inv(),aPMoy));
       mOC2->Externe().Profondeur().SetVal(ProfFromCam(aR2.inv(),aPMoy));

   }

   TestOri1Ori2(true,*mOri1,*mOri2);
   TestOri1Ori2(true,mNewOri1,mNewOri2);
   std::cout << "ZMoyen = " << aPMoy.z  << "\n";

   Fonc_Num aFoK = (mImPds.in()>0);
   Fonc_Num aFRes = Max(0,Min(255,128.0 +mImResidu.in()*20));
   ELISE_COPY
   (
        aFileResidu.all_pts(),
          aFoK*its_to_rgb(Virgule(aFRes,3.14,32*Abs(mImResidu.in()>0.5)))
        + (1-aFoK)*Virgule(255,0,0),
        aFileResidu.out()
   );

   bool Exp1 =  aModele.Modele().AutomNamesExportOri1().IsInit();
   bool Exp2 =  aModele.Modele().AutomNamesExportOri2().IsInit();
   ELISE_ASSERT(Exp1 == Exp2,"Incoherence in AutomNamesExportOri");
   if (Exp1)
   {
      std::cout << "EXPORT   OOOOOOOOOOOOOOORI\n";
      AssertAutomSelExportOriIsInit(aModele.Modele());

      if(aXmlRes)
      {
          MakeFileXML(*mOC1,aNOri1,"MicMacForAPERO");
          MakeFileXML(*mOC2,aNOri2,"MicMacForAPERO");
      }
      else
      {
          ELISE_ASSERT(false,"Cannot write ori ");
          // OO mNewOri1.write_txt(aNOri1.c_str());
          // OO mNewOri2.write_txt(aNOri2.c_str());
      }
   }


   
   if (aModele.Modele().SigmaPixPdsExport().ValWithDef(-1) > 0)
   {
      double aPds = aModele.Modele().SigmaPixPdsExport().Val();
      for 
      (
         ElPackHomologue::iterator iT = mPack.begin();
         iT != mPack.end();
         iT++
      )
      {
          Pt2dr aQ1  = mCam1.F2toPtDirRayonL3(iT->P1());
          Pt2dr aQ2  = mCam2.F2toPtDirRayonL3(iT->P2());
          double aL =  ElAbs(mCpl12->ResiduSigneP1P2(aQ1,aQ2))*mFocale;
          double aP = ElSquare(aPds)/(ElSquare(aPds)+ElSquare(aL));
          iT->Pds() *= aP;
      }
   }
}
Пример #28
0
void Vignette_correct(string aDir, GrpVodka aGrpVodka,string aDirOut, string InCal){

    //Bulding the output file system
    ELISE_fp::MkDirRec(aDir + aDirOut);

    //Reading vignette files
        char foc[5],dia[4];
        sprintf(foc, "%04d", int(10*aGrpVodka.foc));
        sprintf(dia, "%03d", int(10*aGrpVodka.diaph));
        string aNameVignette="Foc" + (string)foc + "Diaph" + (string)dia + "-FlatField.tif";
        //string aNameVignette = "Foc"+ ToString(round_ni(aGrpVodka.foc)) + "Diaph" + ToString(round_ni(10*aGrpVodka.diaph)) + "-FlatField.tif";
        Tiff_Im aTFV= Tiff_Im::StdConvGen(aDir + InCal + aNameVignette,1,false);
        Pt2di aSz = aTFV.sz();

        Im2D_REAL4  aVignette(aSz.x,aSz.y);

        ELISE_COPY
        (
           aTFV.all_pts(),
           aTFV.in(),
           aVignette.out()
        );

        REAL4 ** aDataVignette = aVignette.data();

    //Correcting images
    int nbIm=aGrpVodka.size();

#ifdef USE_OPEN_MP
    #pragma omp parallel for
#endif
    for(int i=0;i<nbIm;i++)
    {
        string aNameIm=aGrpVodka.aListIm[i];
        cout<<"Correcting "<<aNameIm<<endl;
        string aNameOut=aDir + aDirOut + aNameIm +"_vodka.tif";

        //Reading the image and creating the objects to be manipulated
        Tiff_Im aTF= Tiff_Im::StdConvGen(aDir + aNameIm,3,false);
        Pt2di aSz = aTF.sz();

        Im2D_U_INT1  aImR(aSz.x,aSz.y);
        Im2D_U_INT1  aImG(aSz.x,aSz.y);
        Im2D_U_INT1  aImB(aSz.x,aSz.y);

        ELISE_COPY
        (
           aTF.all_pts(),
           aTF.in(),
           Virgule(aImR.out(),aImG.out(),aImB.out())
        );

        U_INT1 ** aDataR = aImR.data();
        U_INT1 ** aDataG = aImG.data();
        U_INT1 ** aDataB = aImB.data();

        for (int aY=0 ; aY<aSz.y  ; aY++)
            {
                for (int aX=0 ; aX<aSz.x  ; aX++)
                {
                    double aCor=aDataVignette[aY][aX];
                    double R = aDataR[aY][aX] * aCor;
                    double G = aDataG[aY][aX] * aCor;
                    double B = aDataB[aY][aX] * aCor;
                    if(R>255){aDataR[aY][aX]=255;}else if(aCor<1){continue;}else{aDataR[aY][aX]=R;}
                    if(G>255){aDataG[aY][aX]=255;}else if(aCor<1){continue;}else{aDataG[aY][aX]=G;}
                    if(B>255){aDataB[aY][aX]=255;}else if(aCor<1){continue;}else{aDataB[aY][aX]=B;}
                }
        }

         Tiff_Im  aTOut
            (
                aNameOut.c_str(),
                aSz,
                GenIm::u_int1,
                Tiff_Im::No_Compr,
                Tiff_Im::RGB
            );


         ELISE_COPY
             (
                 aTOut.all_pts(),
                 Virgule(aImR.in(),aImG.in(),aImB.in()),
                 aTOut.out()
             );


    }


}
Пример #29
0
int EstimFlatField_main(int argc,char ** argv)
{
    std::string aFullDir,aDir,aPat;
    std::string aNameOut;
    double aResol=1.0;
    double aDilate=1.0;
    int aNbMed = 1;
    int aNbMedSsRes = 3;
    bool ByMoy = false;
    double TolMed = 0.25;

    ElInitArgMain
    (
    argc,argv,
    LArgMain()  << EAMC(aFullDir,"Images = Dir + Pat", eSAM_IsPatFile)
                    << EAMC(aResol,"Resolution "),
    LArgMain()  << EAM(aNbMed,"NbMed",true)
                    << EAM(aNameOut,"Out",true,"Name of result")
                    << EAM(aDilate,"SousResAdd",true)
                    << EAM(aNbMedSsRes,"NbMedSsRes",true)
                    << EAM(TolMed,"TolMed",true)
                    << EAM(ByMoy,"ByMoy",true,"Average or median (def=false")
    );

    if (!MMVisualMode)
    {
    SplitDirAndFile(aDir,aPat,aFullDir);

    if (aNameOut=="")
       aNameOut = "FlatField.tif";
    aNameOut = aDir + aNameOut;

    cTplValGesInit<std::string> aTplN;
    cInterfChantierNameManipulateur * aICNM = cInterfChantierNameManipulateur::StdAlloc(0,0,aDir,aTplN);

    MakeXmlXifInfo(aFullDir,aICNM);


    std::list<std::string> aLName = aICNM->StdGetListOfFile(aPat);
    Paral_Tiff_Dev(aDir,std::vector<std::string> (aLName.begin(),aLName.end()),1,false);



    Pt2di aSzIm(-1,-1);
    double aNbPix=-1;
    Im2D_REAL4  aImIn(1,1);
    Im2D_REAL8  aFFRes1(1,1);
    Pt2di aSzF(-1,-1);


    int aNbIm = (int)aLName.size();
    int aCpt = aNbIm;

    std::vector<Im2D_REAL4> aVImRed;

    // for (std::list<std::string>::const_iterator itN=aLName.begin(); itN!=aLName.end() ; itN++)
    // for (std::list<std::string>::reverse_iterator itN=aLName.rbegin(); itN!=aLName.rend() ; itN++)
     for (std::list<std::string>::const_iterator itN=aLName.begin(); itN!=aLName.end() ; itN++)
     {
         std::cout << "To Do " << aCpt << *itN << "\n";
         Tiff_Im  aTIn = Tiff_Im::StdConvGen(aDir+*itN,1,true);
         std::string aImRefSz;
         if (aSzIm.x<0)
         {
            aImRefSz = *itN;
            aSzIm = aTIn.sz();
            aImIn = Im2D_REAL4(aSzIm.x,aSzIm.y,0.0);
            if (ByMoy)
               aFFRes1 = Im2D_REAL8(aSzIm.x,aSzIm.y,0.0);
            aNbPix = aSzIm.x*aSzIm.y;
            aSzF = round_up(Pt2dr(aSzIm)/aResol);
         }
         else
         {
             if (aSzIm!=aTIn.sz())
             {
                 std::cout << "For Image " << *itN <<  " sz=" << aTIn.sz()  << " Ref=" << aImRefSz << " Sz=" << aSzIm << "\n";
                 ELISE_ASSERT(false,"Different size");
             }
         }
         double aSom = 0;
         // ELISE_COPY(aImIn.all_pts(),aTIn.in(),aImIn.out()|sigma(aSom));

         Fonc_Num aFIN = aTIn.in();
         ELISE_COPY(aImIn.all_pts(),Rconv(aFIN),aImIn.out()|sigma(aSom));
         double aMoy = aSom/aNbPix;

         if (ByMoy)
         {
            ELISE_COPY
            (
                 aImIn.all_pts(),
                 aFFRes1.in()+(aImIn.in()/aMoy),
                 aFFRes1.out()
            );
         }
         else
         {
             Im2D_REAL4 aIRed(aSzF.x,aSzF.y);
             ELISE_COPY
             (
                   aIRed.all_pts(),
                   StdFoncChScale
                   (
                       aImIn.in_proj() / aMoy,
                       Pt2dr(0.0,0.0),
                       Pt2dr(aResol,aResol),
                       Pt2dr(aDilate,aDilate)
                   ),
                   aIRed.out()
             );
             aVImRed.push_back(aIRed);
         }

         aCpt--;
    }


    Fonc_Num aF;

    if (ByMoy)
    {

       std::cout << "Filtrage Median "<< aNbMed << "\n";
       ELISE_COPY
       (
             aFFRes1.all_pts(),
             MedianBySort(aFFRes1.in_proj()/aNbIm,aNbMed),
             aFFRes1.out()
       );


       aF =  StdFoncChScale
                   (
                       aFFRes1.in_proj() / aNbIm,
                       Pt2dr(0.0,0.0),
                       Pt2dr(aResol,aResol),
                       Pt2dr(aDilate,aDilate)
                   );
       if (aNbMedSsRes)
         aF = MedianBySort(aF,aNbMedSsRes);
    }
    else
    {
         int aMoyMed = 2;
         Im2D_REAL4 aRes = ImMediane<float,double>(aVImRed,-1e30,0.0,TolMed);
         aF = aRes.in_proj();

         for (int aK=0 ; aK<3 ; aK++)
             aF = MedianBySort(aF,4);

         for (int aK=0 ; aK<3 ; aK++)
             aF = rect_som(aF,aMoyMed)/ElSquare(1+2*aMoyMed);
    }


    Tiff_Im aTOut
            (
                 aNameOut.c_str(),
                 aSzF ,
                 GenIm::real8,
                 Tiff_Im::No_Compr,
                 Tiff_Im::BlackIsZero
             );
    ELISE_COPY
    (
         aTOut.all_pts(),
         aF,
         aTOut.out()
    );

    }

    return EXIT_SUCCESS;
}
cElNuage3DMaille * cElNuage3DMaille::FromParam
                   (
                       const cXML_ParamNuage3DMaille & aParamOri,
                       const std::string & aDir,
                       const std::string & aMasqSpec,
                       double ExagZ,
                       const cParamModifGeomMTDNuage * aPMG,
                       bool  WithEmptyData
                   )
{
  cXML_ParamNuage3DMaille aParam = aParamOri;
  Box2di aBox(Pt2di(0,0),aParam.NbPixel());
  bool Dequant = false;

  if (aPMG)
  {
       double aScale = aPMG->mScale;
       if (aScale != 1.0)
       {
           std::string aMes = "Scale=" + ToString(aScale);
           cElWarning::ScaleInNuageFromP.AddWarn(aMes,__LINE__,__FILE__);
       }
       Pt2di  aP0 = round_down(aPMG->mBox._p0/aScale);
       Pt2di  aP1 = round_up(aPMG->mBox._p1/aScale);

       aBox = Inf(aBox,Box2di(aP0,aP1));

       aParam.NbPixel() = aBox.sz();

       ElAffin2D aAfM2C = Xml2EL(aParam.Orientation().OrIntImaM2C());
       
        aAfM2C   =   ElAffin2D::trans(-Pt2dr(aBox._p0)) * aAfM2C;
       aParam.Orientation().OrIntImaM2C().SetVal(El2Xml(aAfM2C));
       Dequant = aPMG->mDequant;
  }


  std::string aMasq =  aDir+aParam.Image_Profondeur().Val().Masq();
  if (aMasqSpec!="")
         aMasq = aMasqSpec;

  GenIm::type_el aTypeEl = GenIm::real4;
  Fonc_Num aFMasq = 0;
  Fonc_Num aFProf = 1;
  if (! WithEmptyData)
  {
     aFMasq =   trans(Tiff_Im::BasicConvStd(aMasq).in(0),aBox._p0);
     Tiff_Im aTP = Tiff_Im::BasicConvStd(aDir+aParam.Image_Profondeur().Val().Image());
     aFProf =  trans(aTP.in_proj()*ExagZ,aBox._p0);
     aTypeEl = aTP.type_el();
  }


   if (aParam.Image_Profondeur().IsInit())
   {
      bool aFaiscClassik =  (   (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauIm1PrCh_Px1D)
                             || (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauIm1PrCh_Px2D)
                             || (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTEuclid)
                             || (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauPrChSpherik)
                            );

      bool aProfIsZ =  (      (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauIm1ZTerrain_Px1D)
                             || (aParam.Image_Profondeur().Val().GeomRestit()==eGeomMNTFaisceauIm1ZTerrain_Px2D)
                         );


       if (aFaiscClassik || aProfIsZ)
       {
           switch (aTypeEl)
           {
               case GenIm::int2 :
                    if (Dequant) 
                        return new cElN3D_EpipGen<float,double>(aDir,aParam,aFMasq,aFProf,aProfIsZ,WithEmptyData,true);
                    else
                        return new cElN3D_EpipGen<INT2,INT>(aDir,aParam,aFMasq,aFProf,aProfIsZ,WithEmptyData,false);
               break;
               case GenIm::real4 :
                    return new cElN3D_EpipGen<float,double>(aDir,aParam,aFMasq,aFProf,aProfIsZ,WithEmptyData,false);
               break;

               default :
                   std::cout << "NAME " << aDir+aParam.Image_Profondeur().Val().Image() << "\n";
                   ELISE_ASSERT(false,"Type Image non gere dans cElNuage3DMaille::FromParam");
               break;
           }
       }
   }

   ELISE_ASSERT(false,"cElNuage3DMaille::FromParam");
   return 0;
}