예제 #1
0
void cMMTP::MaskProgDyn(const cParamFiltreDepthByPrgDyn & aParam)
{
    std::cout << "BEGIN MASK PRGD\n";
    mImMasqFinal = FiltrageDepthByProgDyn(mContBT,mImLabel,aParam);
    std::cout << "END MASK PRGD\n";
    
#ifdef ELISE_X11
    if(TheWTiePCor)
    {
           ELISE_COPY(mImLabel.all_pts(),mImLabel.in(),TheWTiePCor->odisc());
           ELISE_COPY
           (
                 select(mImLabel.all_pts(),mImMasqFinal.in() && (mImLabel.in()==1)),
                 P8COL::green,
                 TheWTiePCor->odisc()
           );
           ELISE_COPY
           (
                 select(mImLabel.all_pts(),mImMasqFinal.in() && (mImLabel.in()==2)),
                 P8COL::blue,
                 TheWTiePCor->odisc()
           );
           TheWTiePCor->clik_in();
    }
#endif
}
예제 #2
0
Im2D_U_INT1 Icone(const std::string & aName,const Pt2di & aSzCase,bool Floutage,bool Negatif)
{
   cElBitmFont & aFont = cElBitmFont::BasicFont_10x8() ;

   Im2D_Bits<1> aImBin = aFont.MultiLineImageString(aName,Pt2di(0,5),-aSzCase,0);
   ELISE_COPY(aImBin.border(3),1,aImBin.out());
   ELISE_COPY(aImBin.border(1),0,aImBin.out());

   Pt2di  aSz = aImBin.sz();
   Im2D_U_INT1 aRes(aSz.x,aSz.y);

   if (Negatif)
   {
      ELISE_COPY(line(Pt2di(0,0),aSz),1,aImBin.oclip());
      ELISE_COPY(line(Pt2di(aSz.x,0),Pt2di(0,aSz.y)),1,aImBin.oclip());
      ELISE_COPY(aImBin.all_pts(),!aImBin.in(),aImBin.out());
   }

   ELISE_COPY
   (
      aRes.all_pts(),
      (!aImBin.in(0)) *255,
      aRes.out()
   );


   if (Floutage)
   {
       ELISE_COPY
       (
            aRes.all_pts(),
            (  Negatif                                   ?
               Max(aRes.in(),rect_som(aRes.in(0),1)/9.0) :
               Min(aRes.in(),rect_som(aRes.in(0),1)/9.0)
            ),
            aRes.out()
       );

   }

   return aRes;
}
예제 #3
0
void  ShowMasq(Im2D_Bits<1> aMasq)
{
#ifdef ELISE_X11
   if (TheWTiePCor)
   {
       ELISE_COPY
       (
           select(aMasq.all_pts(),aMasq.in()==0),
           P8COL::green,
           TheWTiePCor->odisc()
       );
   }
#endif 
}
예제 #4
0
void cMMTP::MaskRegulMaj(const cParamFiltreDetecRegulProf & aParam)
{
   double aPasPx =  mAppli.CurEtape()->GeomTer().PasPxRel0();
   Im2D_REAL4 anIm(mSzTiep.x,mSzTiep.y);
   ELISE_COPY(anIm.all_pts(),mImProf.in()*aPasPx,anIm.out());
    
   Im2D_Bits<1>   aNewMasq = FiltreDetecRegulProf(anIm,mImMasqInit,aParam);

#ifdef ELISE_X11
    if(TheWTiePCor)
    {
           std::cout << "SHOW FiltreDetecRegulProf\n";
           ELISE_COPY(mImLabel.all_pts(),mImMasqInit.in(),TheWTiePCor->odisc());
           ELISE_COPY
           (
                 select(mImLabel.all_pts(),aNewMasq.in()),
                 P8COL::green,
                 TheWTiePCor->odisc()
           );
           TheWTiePCor->clik_in();
    }
#endif
   mImMasqInit = aNewMasq;
}
예제 #5
0
Fonc_Num  cImage_LumRas::MoyGlobImage(Fonc_Num aF)
{
   Im2D_Bits<1> aIM = mAppli.mImMasq;
   Fonc_Num aFMasq = aIM.in(0);
   double aVS[2];

   ELISE_COPY
   (
        aIM.all_pts(),
        Virgule(aF*aFMasq,aFMasq),
        sigma(aVS,2)
   );

   return aVS[0] / aVS[1];
}
예제 #6
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());
    }
}
예제 #7
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;
}
예제 #8
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;
}
예제 #9
0
void cMMTP::ContAndBoucheTrou()
{
   int aDist32Close = 6;
   int aNbErod = 6;

   // 1- Quelques fitre morpho de base, pour calculer les points eligibles au bouche-trou
   int aLabelOut = 0;
   //int aLabelIn = 1;
   int aLabelClose = 2;
   int aLabelFront = 3;

   ELISE_COPY(mImMasqInit.all_pts(),mImMasqInit.in(),mImLabel.out());
   ELISE_COPY(mImLabel.border(2),aLabelOut,mImLabel.out());

      // 1.1 calcul des point dans le fermeture
   ELISE_COPY
   (
          select
          (
             mImLabel.all_pts(),
             close_32(mImLabel.in(0),aDist32Close) && (mImLabel.in()==aLabelOut)
          ),
          aLabelClose,
          mImLabel.out()
   );
   ELISE_COPY(mImLabel.border(2),aLabelOut,mImLabel.out());


      // 1.2 erosion de ces points
   Neighbourhood V4 = Neighbourhood::v4();
   Neighbourhood V8 = Neighbourhood::v8();
   Neigh_Rel aRelV4(V4);

   Liste_Pts_U_INT2 aLFront(2);
   ELISE_COPY
   (
          select
          (
             mImLabel.all_pts(),
             (mImLabel.in(0)==aLabelClose) &&  (aRelV4.red_max(mImLabel.in(0)==aLabelOut))
          ),
          aLabelFront,
          mImLabel.out() | aLFront
    );
    for (int aK=0 ; aK<aNbErod ; aK++)
    {
        Liste_Pts_U_INT2 aLNew(2);
        ELISE_COPY
        (
               dilate
               (
                  aLFront.all_pts(),
                  mImLabel.neigh_test_and_set(Neighbourhood::v4(),2,3,20)
               ),
               aLabelFront,
               aLNew
         );
         aLFront = aLNew;
    }
    ELISE_COPY(select(mImLabel.all_pts(),mImLabel.in()==aLabelFront),0,mImLabel.out());

    // Au cas ou on ferait un export premature
    ELISE_COPY(mImMasqFinal.all_pts(),mImLabel.in()!=0,mImMasqFinal.out());

    int aSomMaskF;
    ELISE_COPY(mImMasqFinal.all_pts(),mImLabel.in()==1,sigma(aSomMaskF));
    if (aSomMaskF < 100) return;
    // std::cout << "aSomMaskFaSomMaskF " << aSomMaskF << "\n";
   // 2- Dequantifiication, adaptee au image a trou

       Im2D_REAL4 aProfCont(mSzTiep.x,mSzTiep.y,0.0);
       {
           Im2D_INT2 aPPV = BouchePPV(mImProf,mImLabel.in()==1);

           ElImplemDequantifier aDeq(mSzTiep);
           aDeq.DoDequantif(mSzTiep,aPPV.in());
           ELISE_COPY(aProfCont.all_pts(),aDeq.ImDeqReelle(),aProfCont.out());

           ELISE_COPY(select(aProfCont.all_pts(),mImLabel.in()!=1),0,aProfCont.out());
       }

       
    //Im2D_REAL4 aImInterp(mSzTiep.x,mSzTiep.y);
    TIm2D<REAL4,REAL8> aTInterp(mContBT);

   // 3- Bouchage "fin" des trour par moinde L2
          // 3.1 Valeur initial

                 // Filtrage gaussien
    Fonc_Num aFMasq = (mImLabel.in(0)==1);
    Fonc_Num aFProf = (aProfCont.in(0) * aFMasq);
    for (int aK=0 ; aK<3 ; aK++)
    {
          aFMasq = rect_som(aFMasq,1) /9.0;
          aFProf = rect_som(aFProf,1) /9.0;
    }

    ELISE_COPY
    (
         mContBT.all_pts(),
         aFProf / Max(aFMasq,1e-9),
         mContBT.out()
    );
                 // On remet la valeur init au point ayant un valeur propre
    ELISE_COPY
    (
         select(mContBT.all_pts(),mImLabel.in()==1),
         aProfCont.in(),
         mContBT.out()
    );
             // Et rien en dehors de l'image
    ELISE_COPY
    (
         select(mContBT.all_pts(),mImLabel.in()==0),
         0,
         mContBT.out()
    );
  
  
  
  
       // 3.2 Iteration pour regulariser les points interpoles
    {
         std::vector<Pt2di> aVInterp;
         {
            Pt2di aP;
            for (aP.x=0 ; aP.x<mSzTiep.x ; aP.x++)
            {
                for (aP.y=0 ; aP.y<mSzTiep.y ; aP.y++)
                {
                   if (mTLab.get(aP)==aLabelClose)
                     aVInterp.push_back(aP);
                }
            }
         }

         for (int aKIter=0 ; aKIter<20 ; aKIter++)
         {
              std::vector<double> aVVals;
              for (int aKP=0 ; aKP<int(aVInterp.size()) ; aKP++)
              {
                   double aSom=0;
                   double aSomPds = 0;
                   Pt2di aPK = aVInterp[aKP];
                   for (int aKV=0 ; aKV<9 ; aKV++)
                   {
                         Pt2di aVois = aPK+TAB_9_NEIGH[aKV];
                         if (mTLab.get(aVois)!=0)
                         {
                             int aPds = PdsGaussl9NEIGH[aKV];
                             aSom +=  aTInterp.get(aVois) * aPds;
                             aSomPds += aPds;
                         }
                   }
                   ELISE_ASSERT(aSomPds!=0,"Assert P!=0");
                   aVVals.push_back(aSom/aSomPds);
              }
              for (int aKP=0 ; aKP<int(aVInterp.size()) ; aKP++)
              {
                 aTInterp.oset(aVInterp[aKP],aVVals[aKP]);
              }
         }
    }
    
/*
*/

#ifdef ELISE_X11
           if(0 && TheWTiePCor)
           {

              ELISE_COPY
              (
                   mImLabel.all_pts(),
                   mContBT.in()*7,
                   TheWTiePCor->ocirc()
              );
              TheWTiePCor->clik_in();
              
              ELISE_COPY
              (
                  mImLabel.all_pts(),
                  nflag_close_sym(flag_front4(mImLabel.in(0)==1)),
                  TheWTiePCor->out_graph(Line_St(TheWTiePCor->pdisc()(P8COL::black)))
              );
              TheWTiePCor->clik_in();

              ELISE_COPY
              (
                  mImLabel.all_pts(),
                  mImLabel.in(0),
                  TheWTiePCor->odisc()
              );
              TheWTiePCor->clik_in();
              ELISE_COPY
              (
                  mImLabel.all_pts(),
                  mImMasqFinal.in(0),
                  TheWTiePCor->odisc()
              );
              TheWTiePCor->clik_in();
           }
#endif
}
예제 #10
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
}
예제 #11
0
void FiltreRemoveBorderHeter(Im2D_REAL4 anIm,Im2D_U_INT1 aImMasq,double aCostRegul,double aCostTrans)
{
    Pt2di aSz = anIm.sz();
    double aVMax,aVMin;

    ELISE_COPY(aImMasq.border(1),0,aImMasq.out());
    ELISE_COPY(aImMasq.all_pts(),aImMasq.in()!=0,aImMasq.out());
    ELISE_COPY(anIm.all_pts(),anIm.in(),VMax(aVMax)|VMin(aVMin));
    Video_Win * aW = Video_Win::PtrWStd(aSz);
    ELISE_COPY(anIm.all_pts(),(anIm.in()-aVMin) * (255.0/(aVMax-aVMin)),aW->ogray());
    std::cout << "VMAX " << aVMax << "\n";

    //ELISE_COPY(aW->all_pts(),aImMasq.in(),aW->odisc());
    //aW->clik_in();

    ELISE_COPY
    (
          aW->all_pts(),
          nflag_close_sym(flag_front8(aImMasq.in_proj()!=0)),
          aW->out_graph(Line_St(aW->pdisc()(P8COL::red)))
    );

    cParamFiltreDepthByPrgDyn aParam =  StdGetFromSI(Basic_XML_MM_File("DefFiltrPrgDyn.xml"),ParamFiltreDepthByPrgDyn);
    aParam.CostTrans() = aCostTrans;
    aParam.CostRegul() = aCostRegul;

    Im2D_Bits<1>  aNewMasq =  FiltrageDepthByProgDyn(anIm,aImMasq,aParam);
  
    ELISE_COPY
    (
         select(aNewMasq.all_pts(),aNewMasq.in()),
         2,
         aImMasq.out()
    );
    TIm2D<U_INT1,INT> aTMasq(aImMasq);
    FiltrageCardCC(false,aTMasq,2,0,100);

    Neighbourhood aNV4=Neighbourhood::v4();
    Neigh_Rel     aNrV4 (aNV4);

    ELISE_COPY
    (
           conc
           (
               select(select(aImMasq.all_pts(),aImMasq.in()==1),aNrV4.red_sum(aImMasq.in()==0)),
               aImMasq.neigh_test_and_set(aNV4,1,0,256)
           ),
           3,
           Output::onul()
    );



    ELISE_COPY
    (
         aNewMasq.all_pts(),
         aImMasq.in(),
         aW->odisc()
    );

/*
    ELISE_COPY
    (
          aW->all_pts(),
          nflag_close_sym(flag_front8(aNewMasq.in_proj())),
          aW->out_graph(Line_St(aW->pdisc()(P8COL::green)))
    );
*/


    aW->clik_in();

}