Fonc_Num FoncHomog(Im2D_REAL4 anIm, int aSzKernelH, double aPertPerPix) { Fonc_Num aFMax = rect_max(anIm.in_proj(),aSzKernelH); Fonc_Num aFMin = rect_min(anIm.in_proj(),aSzKernelH); Fonc_Num aFHom = aFMin > (1- aPertPerPix * aSzKernelH) * aFMax; return rect_max(aFHom,aSzKernelH); }
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; }