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() ); }
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() ); }
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() ); }
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; } } }
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); } }
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() ); } }
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; } } }
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>" ); } }
void RotateImage(double alpha, Pt2di aSzOut, vector<Pt2dr> Pts , string aNameDir, string aNameIm) { cout<<"Rotating "<<aNameIm<<endl; string aNameOut=aNameDir + "Croped_images/" + aNameIm + ".tif"; //Reading the image and creating the objects to be manipulated Tiff_Im aTF= Tiff_Im::StdConvGen(aNameDir + aNameIm,1,false); Pt2di aSz = aTF.sz(); Pt2dr P1Cor=Rot2D(alpha, Pts[0], Pts[1]); //P1Cor.x=cos(alpha)*(Pts[0].x-Pts[1].x)+sin(alpha)*(Pts[0].y-Pts[1].y)+Pts[1].x; P1Cor.y=-sin(alpha)*(Pts[0].x-Pts[1].x)+cos(alpha)*(Pts[0].y-Pts[1].y)+Pts[1].y; Pt2dr P3Cor=Rot2D(alpha, Pts[2], Pts[1]); //P3Cor.x=cos(alpha)*(Pts[2].x-Pts[1].x)+sin(alpha)*(Pts[2].y-Pts[1].y)+Pts[1].x; P3Cor.y=-sin(alpha)*(Pts[2].x-Pts[1].x)+cos(alpha)*(Pts[2].y-Pts[1].y)+Pts[1].y; 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(aSzOut.x,aSzOut.y); Im2D_U_INT1 aImGOut(aSzOut.x,aSzOut.y); Im2D_U_INT1 aImBOut(aSzOut.x,aSzOut.y); ELISE_COPY ( aTF.all_pts(), aTF.in(), aImR.out()//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; Pt2di imageTopCorner, imageBottomCorner; imageTopCorner.x = (int)(P1Cor.x + 0.5) + (int)(max(abs(P1Cor.x - Pts[1].x), abs(P1Cor.x - P3Cor.x)) - aSzOut.x) / 2; imageTopCorner.y = (int)(P1Cor.y + 0.5) + (int)(max(abs(P3Cor.y - Pts[1].y), abs(P1Cor.y - P3Cor.y)) - aSzOut.y) / 2; imageBottomCorner.x = imageTopCorner.x + aSzOut.x; imageBottomCorner.y = imageTopCorner.y + aSzOut.y; for (int aY=imageTopCorner.y ; aY<imageBottomCorner.y ; aY++) { for (int aX=imageTopCorner.x ; aX<imageBottomCorner.x ; aX++) { ptOut.x=cos(-alpha)*(aX-Pts[1].x)+sin(-alpha)*(aY-Pts[1].y)+Pts[1].x; ptOut.y=-sin(-alpha)*(aX-Pts[1].x)+cos(-alpha)*(aY-Pts[1].y)+Pts[1].y; aDataROut[aY-imageTopCorner.y][aX-imageTopCorner.x] = Reechantillonnage::biline(aDataR, aSz.x, aSz.y, ptOut); aDataGOut[aY-imageTopCorner.y][aX-imageTopCorner.x] = Reechantillonnage::biline(aDataR, aSz.x, aSz.y, ptOut); aDataBOut[aY-imageTopCorner.y][aX-imageTopCorner.x] = Reechantillonnage::biline(aDataR, aSz.x, aSz.y, ptOut); } } Tiff_Im aTOut ( aNameOut.c_str(), aSzOut, GenIm::u_int1, Tiff_Im::No_Compr, Tiff_Im::RGB ); ELISE_COPY ( aTOut.all_pts(), Virgule(aImROut.in(),aImGOut.in(),aImBOut.in()), aTOut.out() ); #if (ELISE_unix || ELISE_Cygwin || ELISE_MacOs) string aCom="convert ephemeral:" + aNameDir + "Croped_images/" + aNameIm + ".tif " + aNameDir + "Croped_images/" + aNameIm; system_call(aCom.c_str()); #endif #if (ELISE_windows) string aCom=MMDir() + "binaire-aux/convert ephemeral:" + aNameDir + "Croped_images/" + aNameIm + ".tif " + aNameDir + "Croped_images/" + aNameIm; system_call(aCom.c_str()); #endif }
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"; } } }
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 }
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; }
void cAppliMICMAC::DoCorrelLeastQuare(const Box2di & aBoxOut,const Box2di & aBoxIn,const cCorrel2DLeastSquare & aClsq) { int aPer = aClsq.PeriodEch(); cOneTestLSQ aTest ( TheNbIterLine, PDV1()->LoadedIm().DataFloatIm()[0],PDV1()->LoadedIm().SzIm(), PDV2()->LoadedIm().DataFloatIm()[0],PDV2()->LoadedIm().SzIm(), CurEtape()->InterpFloat(), aClsq ); Pt2di aP0Red = round_up(Pt2dr(aBoxOut._p0) / double(aPer)); Pt2di aP1Red = round_up(Pt2dr(aBoxOut._p1) / double(aPer)); Pt2di aSzRed = aP1Red - aP0Red; Im2D_REAL8 aImDepX(aSzRed.x,aSzRed.y); Im2D_REAL8 aImDepY(aSzRed.x,aSzRed.y); Pt2di aPRed; const cOneNappePx & aPx1 = mLTer->KthNap(0); const cOneNappePx & aPx2 = mLTer->KthNap(1); for (aPRed.x=aP0Red.x ; aPRed.x<aP1Red.x ; aPRed.x++) { for (aPRed.y=aP0Red.y ; aPRed.y<aP1Red.y ; aPRed.y++) { // std::cout <<"REST " << aP1Red - aPRed << "\n"; Pt2di aP = aPRed * aPer; Pt2di aPLoc = aP-aBoxIn._p0; double aPx[2]; aPx[0] = aPx1.mTPxInit.get(aPLoc); aPx[1] = aPx2.mTPxInit.get(aPLoc); mCurEtape->GeomTer().PxDisc2PxReel(aPx,aPx); //aTest.SetPIm1(PDV1()->Geom().CurObj2Im(Pt2dr(aP),aPx)); //aTest.SetPIm2(PDV2()->Geom().CurObj2Im(Pt2dr(aP),aPx)); aTest.MinimByLSQandGolden ( PDV1()->Geom().CurObj2Im(Pt2dr(aP),aPx), PDV2()->Geom().CurObj2Im(Pt2dr(aP),aPx) ); double aPx0[2]={0,0}; Pt2dr aP20 = PDV2()->Geom().CurObj2Im(Pt2dr(aP),aPx0); Pt2dr aP2 = aTest.Im2().PImCur(); aImDepX.SetR(aPRed-aP0Red,aP2.x-aP20.x); aImDepY.SetR(aPRed-aP0Red,aP2.y-aP20.y); } } Tiff_Im aFileRX = mCurEtape->KPx(0).FileIm(); Tiff_Im aFileRY = mCurEtape->KPx(1).FileIm(); ELISE_COPY ( rectangle(aP0Red,aP1Red), trans(aImDepX.in(),-aP0Red), aFileRX.out() ); ELISE_COPY ( rectangle(aP0Red,aP1Red), trans(aImDepY.in(),-aP0Red), aFileRY.out() ); /* */ }
int Luc_main_truc(int argc, char ** argv) { /* std::string aFullPattern, aOri, aNameOut="PointsCordinates.txt"; //Reading the arguments ElInitArgMain ( argc, argv, LArgMain() << EAMC(aFullPattern, "Images Pattern 1", eSAM_IsPatFile) << EAMC(aOri, "Orientation", eSAM_IsPatFile), LArgMain() << EAM(aNameOut, "Out", true, "Output file (txt)") ); string aPattern, aNameDir; SplitDirAndFile(aNameDir, aPattern, aFullPattern); //Reading input files list<string> ListIm = RegexListFileMatch(aNameDir, aPattern, 1, false); int nbIm = ListIm.size(); string oriFileName = aNameDir + aNameOut; FILE *f = fopen(oriFileName.c_str(), "w"); for (int i = 1; i <= nbIm; i++) { //Processing the image string aNameIm = ListIm.front(); ListIm.pop_front(); string aNameOut = aNameDir + aNameIm + ".tif"; //Loading the camera string aNameCam = "Ori-" + aOri + "/Orientation-" + aNameIm + ".xml"; cInterfChantierNameManipulateur * anICNM = cInterfChantierNameManipulateur::BasicAlloc(aNameDir); CamStenope * aCam = CamOrientGenFromFile(aNameCam, anICNM); cout << aNameIm << " [ " << aCam->VraiOpticalCenter().x << " , " << aCam->VraiOpticalCenter().y << " , " << aCam->VraiOpticalCenter().z << " ]" << endl; fprintf(f, "%s %0.6f %0.6f %0.6f\n", aNameIm, aCam->VraiOpticalCenter().x, aCam->VraiOpticalCenter().y, aCam->VraiOpticalCenter().z); } fclose(f); */ std::string aFullPattern1, aFullPattern2, aFile3D1, aFile3D2, aOri, aDirOut = "Visualisation/"; int aSzW = 1; double aSzMovArea = 5; //Reading the arguments ElInitArgMain ( argc, argv, LArgMain() << EAMC(aFullPattern1, "Images Pattern 1", eSAM_IsPatFile) << EAMC(aFullPattern2, "Images Pattern 2", eSAM_IsPatFile) << EAMC(aFile3D1, "File 3D 1", eSAM_IsPatFile) << EAMC(aFile3D2, "File 3D 2", eSAM_IsPatFile) << EAMC(aOri, "Orientation", eSAM_IsPatFile), LArgMain() << EAM(aDirOut, "Out", true, "Output folder (end with /) and/or prefix (end with another char)") << EAM(aSzMovArea, "SzMovArea", true, "Max magnitude of movement in meters (def=5)") ); //Creating vector of images std::string aDir, aPatIm1, aPatIm2; SplitDirAndFile(aDir, aPatIm1, aFullPattern1); SplitDirAndFile(aDir, aPatIm2, aFullPattern2); cInterfChantierNameManipulateur * aICNM = cInterfChantierNameManipulateur::BasicAlloc(aDir); const std::vector<std::string> * aSetIm1 = aICNM->Get(aPatIm1); const std::vector<std::string> * aSetIm2 = aICNM->Get(aPatIm2); std::vector<std::string> aVectIm1 = *aSetIm1; std::vector<std::string> aVectIm2 = *aSetIm2; cout << "Set 1 size : " << aVectIm1.size() << endl; cout << "Set 1 : " << aVectIm1 << endl; cout << "Set 2 size : " << aVectIm2.size() << endl; cout << "Set 2 : " << aVectIm2 << endl; //loading 3D models cElNuage3DMaille * info3D1 = cElNuage3DMaille::FromFileIm(aFile3D1); cElNuage3DMaille * info3D2 = cElNuage3DMaille::FromFileIm(aFile3D2); cout << "Sz geom 1: " << info3D1->SzGeom() << endl; cout << "Sz geom 2: " << info3D2->SzGeom() << endl; cout << "Resol geom 1: " << info3D1->ResolSolGlob() << endl; cout << "Resol geom 2: " << info3D2->ResolSolGlob() << endl; //Loading images vector<SpatioTempImage> aGrIm1 = LoadGrpImages(aDir, aPatIm1, aOri); vector<SpatioTempImage> aGrIm2 = LoadGrpImages(aDir, aPatIm2, aOri); cout << "Loaded " << aGrIm1.size() << " images for group 1 and " << aGrIm2.size() << " for group 2" << endl; //Bulding the output file system ELISE_fp::MkDirRec(aDir + aDirOut); std::string aNameOut = "banane.tif"; //Reading the image and creating the objects to be manipulated aNameOut = aDir + aDirOut + aNameOut; Pt2di aSz( info3D1->SzGeom().x , info3D1->SzGeom().y ); 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 = aSzW; aY < aSz.y - aSzW; aY++) { for (int aX = aSzW; aX < aSz.x - aSzW; aX++) { /******************************* HOW TO //transform XY pixel coordinates to terrain coordinates Pt2dr pos2DPtIm1; pos2DPtIm1.x = 10050 + aX*0.14999999999999999*2; pos2DPtIm1.y = 10350 - aY*0.14999999999999999*2; //Go back to pix coordinates pos2DPtIm1 = info3D->Plani2Index(pos2DPtIm1); ********************************/ Pt2dr pos2DMNT( aX , aY ); //Test if there is data if (info3D1->CaptHasData(pos2DMNT)){ //Get 3D info at XY Pt3d<double> pos3DMNT = info3D1->PreciseCapteur2Terrain(pos2DMNT); //cout << "pos3DMNT1 = " << pos3DMNT << endl; //Get Im1(i,j) Pt2di pos2DIm1( int(aGrIm1[0].aCamera->Ter2Capteur(pos3DMNT).x) , int(aGrIm1[0].aCamera->Ter2Capteur(pos3DMNT).y) ); cout << "pos2DIm1 = " << pos2DIm1 << endl; //Extracting window from Im1 Im2D_U_INT1 aWindow1 = Window_Maker(aGrIm1[0], pos2DIm1, 1); Fonc_Num aScoreMin = 100; /* for (int bX = pos3DMNT.x - aSzMovArea; bX <= pos3DMNT.x + aSzMovArea; bX++) { for (int bY = pos3DMNT.y - aSzMovArea; bY <= pos3DMNT.y + aSzMovArea; bY++) { Pt2di aPos(int(aGrIm2[0].aCamera->Ter2Capteur(pos3DMNT).x), int(aGrIm2[0].aCamera->Ter2Capteur(pos3DMNT).y)); //Extracting window from Im2 Im2D_U_INT1 aWindow2 = Window_Maker(aGrIm2[0], aPos, 1); double aScore = Correlator(&aWindow1, &aWindow2); if (aScore < aScoreMin) { //CACACACACACACACCACACACACA TESTER SI PT EXIST DANS INFO3D2===================================================================================== aScoreMin = aScore; Pt2dr aPos2D(bX, bY); Pt3dr aPos3D = info3D2->PreciseCapteur2Terrain(info3D2->Plani2Index(aPos2D)); cout << "pos set 1 = " << pos3DMNT << endl; cout << "pos set 2 = " << aPos3D << endl; aData[aY][aX] = square_euclid(pos3DMNT, aPos3D); cout << aData[aY][aX] << endl; } } } //Get Im2(i,j) Pt2di pos2DIm2( int(aGrIm2[0].aCamera->Ter2Capteur(pos3DMNT).x) , int(aGrIm2[0].aCamera->Ter2Capteur(pos3DMNT).y) ); cout << "pos2DIm2 = " << pos2DIm2 << endl; //Define researsh area in pixels from input info in meters int aSzMovAreaPix = aSzMovArea / aGrIm2[0].aCamera->ResolutionSol(); cout <<"Pouet"<<endl; double aScoreMin = 100; for (int bX = pos2DIm2.x - aSzMovAreaPix; bX <= pos2DIm2.x + aSzMovAreaPix; bX++) { for (int bY = pos2DIm2.y - aSzMovAreaPix; bY <= pos2DIm2.y + aSzMovAreaPix; bY++) { Pt2di aPos( bX, bY ); //Extracting window from Im2 vector<vector<float> > aWindow2 = Window_Maker(aGrIm2[0], aPos, 1); cout << aWindow2 << endl; double aScore = Correlator(aWindow1, aWindow2); cout << aScore << endl; if (aScore < aScoreMin) { aScoreMin = aScore; Pt2dr aPosR(aPos.x, aPos.y); cout << "aPos " << aPos << endl; cout << "aPosR " << aPosR << endl; Pt3dr aPosPt3D = aGrIm2[0].aCamera->PreciseCapteur2Terrain(aPosR); cout << aPosPt3D << endl; Pt2dr aPos2DPtIm2 = info3D2->Plani2Index(aPosR); cout << aPos2DPtIm2 << endl; aData[aY][aX] = square_euclid(pos3DMNT, info3D2->PreciseCapteur2Terrain(aPos2DPtIm2)); cout << aData[aY][aX] << endl; } } } */ } else { aData[aY][aX] = 1; //cout << "not in Masq" << endl; } } } 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() ); return 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() ); } }
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()); } }
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; }
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; }
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; }
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; }
void Egal_field_correct_ite(string aDir,std::vector<std::string> * aSetIm, cl_MatPtsHom aMatPtsHomol , string aDirOut, string InVig, int ResolModel, int nbIm, int nbIte, double aThresh) { //truc à iterer-------------------------------------------------------------------------------------------------------------------------------------- for(int iter=0;iter<nbIte;iter++){ cout<<"Pass "<<iter+1<<" out of "<< nbIte<<endl; //Filtering the tie points aMatPtsHomol = TiePtsFilter(aMatPtsHomol, aThresh); //Correcting the tie points //#pragma omp parallel for for(int numImage1=0;numImage1<nbIm;numImage1++) { vector<int> cpt(nbIm,0); cout<<"Computing factors for Im "<<numImage1<<endl; //For each tie point point, compute correction value (distance-ponderated mean value of all the tie points) for(int k = 0; k<int(aMatPtsHomol.aMat[numImage1].size()) ; k++){//go through each tie point double aCorR=0.0,aCorG=0.0,aCorB=0.0; double aSumDist=0; Pt2dr aPt(aMatPtsHomol.aMat[numImage1].Pts[k].x/ResolModel,aMatPtsHomol.aMat[numImage1].Pts[k].x/ResolModel); for(int numPt = 0; numPt<int(aMatPtsHomol.aMat[numImage1].size()) ; numPt++){//go through each tie point Pt2dr aPtIn(aMatPtsHomol.aMat[numImage1].Pts[numPt].x/ResolModel,aMatPtsHomol.aMat[numImage1].Pts[numPt].y/ResolModel); double aDist=euclid(aPtIn, aPt); if(aDist<1){aDist=1;} aSumDist=aSumDist+1/(aDist); aCorR = aCorR + aMatPtsHomol.aMat[numImage1].kR[numPt]/(aDist); aCorG = aCorG + aMatPtsHomol.aMat[numImage1].kG[numPt]/(aDist); aCorB = aCorB + aMatPtsHomol.aMat[numImage1].kB[numPt]/(aDist); } //Normalize aCorR = aCorR/aSumDist; aCorG = aCorG/aSumDist; aCorB = aCorB/aSumDist; //correcting Tie points color with computed surface //int numImage2=aMatPtsHomol.aMat[numImage1].OtherIm[k]; //int pos=cpt[numImage2];cpt[numImage2]++; //if(aMatPtsHomol.aMat[numImage1][numImage2].R1[pos]*aCorR>255) //{ // aCorR=255/aMatPtsHomol.aMat[numImage1][numImage2].R1[pos]; //} //if(aMatPtsHomol.aMat[numImage1][numImage2].G1[pos]*aCorB>255) //{ // aCorG=255/aMatPtsHomol.aMat[numImage1][numImage2].G1[pos]; //} //if(aMatPtsHomol.aMat[numImage1][numImage2].B1[pos]*aCorG>255) //{ // aCorB=255/aMatPtsHomol.aMat[numImage1][numImage2].B1[pos]; //} aMatPtsHomol.aMat[numImage1].kR[k]=aCorR; aMatPtsHomol.aMat[numImage1].kG[k]=aCorG; aMatPtsHomol.aMat[numImage1].kB[k]=aCorB; } //cout<<cpt<<endl; } } //Filtering the tie points aMatPtsHomol = TiePtsFilter(aMatPtsHomol, aThresh); cout<<"Factors were computed"<<endl; //end truc à iterer-------------------------------------------------------------------------------------------------------------------------------------- //Applying the correction to the images //Bulding the output file system ELISE_fp::MkDirRec(aDir + aDirOut); //Reading input files string suffix="";if(InVig!=""){suffix="_Vodka.tif";} #ifdef USE_OPEN_MP #pragma omp parallel for #endif for(int i=0;i<nbIm;i++) { string aNameIm=InVig + (*aSetIm)[i] + suffix;//if vignette is used, change the name of input file to read cout<<"Correcting "<<aNameIm<<" (with "<<aMatPtsHomol.aMat[i].size()<<" data points)"<<endl; string aNameOut=aDir + aDirOut + (*aSetIm)[i] +"_egal.tif"; Pt2di aSzMod=aMatPtsHomol.aMat[i].SZ;//Size of the correction surface, taken from the size of the scaled image //cout<<"aSzMod"<<aSzMod<<endl; Im2D_REAL4 aImCorR(aSzMod.x,aSzMod.y,0.0); Im2D_REAL4 aImCorG(aSzMod.x,aSzMod.y,0.0); Im2D_REAL4 aImCorB(aSzMod.x,aSzMod.y,0.0); REAL4 ** aCorR = aImCorR.data(); REAL4 ** aCorG = aImCorG.data(); REAL4 ** aCorB = aImCorB.data(); //cout<<vectPtsRadioTie[i].size()<<endl; //For each point of the surface, compute correction value (distance-ponderated mean value of all the tie points) long start=time(NULL); for (int aY=0 ; aY<aSzMod.y ; aY++) { for (int aX=0 ; aX<aSzMod.x ; aX++) { float aCorPtR=0,aCorPtG=0,aCorPtB=0; double aSumDist=0; Pt2dr aPt(aX,aY); for(int j = 0; j<int(aMatPtsHomol.aMat[i].size()) ; j++){//go through each tie point Pt2dr aPtIn(aMatPtsHomol.aMat[i].Pts[j].x/ResolModel,aMatPtsHomol.aMat[i].Pts[j].y/ResolModel); double aDist=euclid(aPtIn, aPt); if(aDist<1){aDist=1;} aSumDist=aSumDist+1/(aDist); aCorPtR = aCorPtR + aMatPtsHomol.aMat[i].kR[j]/(aDist); aCorPtG = aCorPtG + aMatPtsHomol.aMat[i].kG[j]/(aDist); aCorPtB = aCorPtB + aMatPtsHomol.aMat[i].kB[j]/(aDist); } //Normalize aCorR[aY][aX] = aCorPtR/aSumDist; aCorG[aY][aX] = aCorPtG/aSumDist; aCorB[aY][aX] = aCorPtB/aSumDist; } } long end = time(NULL); cout<<"Correction field computed in "<<end-start<<" sec, applying..."<<endl; //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++) { Pt2dr aPt(double(aX/ResolModel),double(aY/ResolModel)); //To be able to correct the edges if(aPt.x>aSzMod.x-2){aPt.x=aSzMod.x-2;} if(aPt.y>aSzMod.y-2){aPt.y=aSzMod.y-2;} //Bilinear interpolation from the scaled surface to the full scale image double R = aDataR[aY][aX]*Reechantillonnage::biline(aCorR, aSzMod.x, aSzMod.y, aPt); double G = aDataG[aY][aX]*Reechantillonnage::biline(aCorG, aSzMod.x, aSzMod.y, aPt); double B = aDataB[aY][aX]*Reechantillonnage::biline(aCorB, aSzMod.x, aSzMod.y, aPt); //Overrun management: if(R>255){aDataR[aY][aX]=255;}else if(R<0){aDataR[aY][aX]=0;}else{aDataR[aY][aX]=R;} if(G>255){aDataG[aY][aX]=255;}else if(G<0){aDataG[aY][aX]=0;}else{aDataG[aY][aX]=G;} if(B>255){aDataB[aY][aX]=255;}else if(B<0){aDataB[aY][aX]=0;}else{aDataB[aY][aX]=B;} } } //Writing ouput image 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() ); } }