void CalcMaxLoc<Type,TypeBase,Compare>::FiltrMaxLoc_BCVS ( ElSTDNS vector<Pt2di> & Pts, Im2D<Type,TypeBase> Im, REAL FactInf, REAL TolGeom, Pt2di SzVois, Im2D_U_INT1 Marq ) { Pt2di SzIm = Inf(Im.sz(),Marq.sz()); Box2di BoxIm(Pt2di(0,0),SzIm); Marq.raz(); mBufFiltr.clear(); INT4 ** dIm = Im.data(); for (INT kp1=0; kp1<(INT)Pts.size() ; kp1++) { ELISE_ASSERT ( BoxIm.contains(Pts[kp1]), "GenMaxLoc::FiltrMaxLoc_BCVS" ); } { for (INT kp1=0; kp1<(INT)Pts.size() ; kp1++) { Pt2di p1 = Pts[kp1]; Box2di BoxP1(p1-SzVois,p1+SzVois); INT v1 = dIm[p1.y][p1.x]; INT Vinf = round_up(v1*FactInf); bool Refut = false; for (INT kp2=0 ; (kp2<(INT)Pts.size())&&(!Refut) ; kp2++) { Pt2di p2 = Pts[kp2]; if ( (kp1!= kp2) && CmpTot(v1,dIm[p2.y][p2.x],p1,p2) && BoxP1.contains(p2) && BandeConnectedVsup(p1,p2,Im,Vinf,TolGeom,Marq) ) Refut = true; } if (! Refut) mBufFiltr.push_back(p1); } } Pts = mBufFiltr; }
bool CalcMaxLoc<Type,TypeBase,Compare>::BandeConnectedVsup ( Pt2di p1, Pt2di p2, Im2D<Type,TypeBase> Im, Type VInf, REAL Tol, Im2D_U_INT1 Marq ) { if (p1==p2) return true; Pt2di Sz = Inf(Im.sz(),Marq.sz()); Box2di Box(Pt2di(0,0), Sz); if (!(Box.contains(p1) && Box.contains(p2))) return false; U_INT1 ** dMarq = Marq.data(); Type ** dIm = Im.data(); mBufCC.clear(); mBufCC.push_back(p1); dMarq[p1.y][p1.x] = 1; Pt2dr aPR1(p1.x,p1.y); Pt2dr aPR2(p2.x,p2.y); SegComp seg12(aPR1,aPR2); bool got = false; for (INT kBuf=0 ; (kBuf!=(INT)mBufCC.size()) && (! got) ; kBuf++) { Pt2di pBuf = mBufCC[ kBuf]; for (INT kV=0 ; kV< 8; kV++) { Pt2di pVois = pBuf + TAB_8_NEIGH[kV]; if ( Box.contains(pVois) && (dMarq[pVois.y][pVois.x] == 0) && (! mCmp(dIm[pVois.y][pVois.x],VInf)) && (seg12.BoxContains(Pt2dr(pVois),1.0,Tol)) ) { if (pVois==p2) got = true; dMarq[pVois.y][pVois.x] = 1; mBufCC.push_back(pVois); } } } { for (INT kBuf=0 ; kBuf<(INT)mBufCC.size() ; kBuf++) { Pt2di pBuf = mBufCC[ kBuf]; dMarq[pBuf.y][pBuf.x] = 0; } } return got; }
template <class TypeIm,class TypeBase> Im2D_Bits<1> CreateGr(tGRGraf & mGr,Im2D<TypeIm,TypeBase> anIm,int aLabelOut,const cParamGrReg & aPGR) { bool V8=true; //int aNbV = V8 ? 8 : 4; //Pt2di * TabV = V8 ? TAB_8_NEIGH : TAB_4_NEIGH; TIm2D<TypeIm,TypeBase> aTIm(anIm); Pt2di aSz = anIm.sz(); Im2D_INT4 aImLabel(aSz.x,aSz.y,-1); TIm2D<INT4,INT4> aTL(aImLabel); ELISE_COPY(aImLabel.border(1),-2,aImLabel.out()); Pt2di aP0; int aCpt=0; ElGrowingSetInd aSV(1000); std::vector<tGRSom *> aVSom; for (aP0.y=0 ; aP0.y<aSz.y ; aP0.y++) { for (aP0.x=0 ; aP0.x<aSz.x ; aP0.x++) { int aLabel = aTIm.get(aP0); if ((aTL.get(aP0)==-1) && (aLabel != aLabelOut)) { std::vector<Pt2di> aVPts; CompCnx(aVPts,V8,aP0,anIm,aImLabel,INT4(aCpt),&aSV); int aNbPts = aVPts.size(); if (aNbPts >= aPGR.mSzMinInit) { cGR_AttrSom anAttr(aP0,aLabel,aCpt,aNbPts); tGRSom & aSom = mGr.new_som(anAttr); aVSom.push_back(&aSom); for (ElGrowingSetInd::const_iterator itV=aSV.begin(); itV!=aSV.end() ; itV++) { tGRSom * aS2 = aVSom[*itV]; if (aS2) { cGR_AttrArc anAA; mGr.add_arc(aSom,*aS2,anAA); } } } else { aVSom.push_back(0); } aCpt++; } } } //std::cout << "BGIN FLAG MONT-DESC\n"; getchar(); // Calcul des flag montant et descandant int aFlagArcMont = mGr.alloc_flag_arc(); int aFlagArcDesc = mGr.alloc_flag_arc(); ElSubGraphe<cGR_AttrSom,cGR_AttrArc> aSubAll; for (int aKS=0 ; aKS<int(aVSom.size()) ; aKS++) { tGRSom * aSom = aVSom[aKS]; if (aSom) { tGRSom * aSMax = aSom; tGRSom * aSMin = aSom; for (tGRSom::TArcIter itA=aSom->begin(aSubAll); itA.go_on(); itA++) { tGRSom * aS2 = &(itA->s2()); if ( (aS2->attr().ValR() > aSMax->attr().ValR()) || ((aS2->attr().ValR()==aSMax->attr().ValR()) && (aS2->attr().Sz() > aSMax->attr().Sz())) ) { aSMax = aS2; } if ( (aS2->attr().ValR() < aSMin->attr().ValR()) || ((aS2->attr().ValR()==aSMin->attr().ValR()) && (aS2->attr().Sz() > aSMin->attr().Sz())) ) { aSMin = aS2; } } if (aSMax != aSom) mGr.arc_s1s2(*aSom,*aSMax)->sym_flag_set_kth_true(aFlagArcMont); if (aSMin != aSom) mGr.arc_s1s2(*aSom,*aSMin)->sym_flag_set_kth_true(aFlagArcDesc); } } // std::cout << "EeenDD FLAG MONT-DESC\n"; // Analyse zone water shade for (int aKMD=0 ; aKMD<2 ; aKMD++) { bool isMont = (aKMD==0); int aFlagArc = (isMont) ? aFlagArcMont : aFlagArcDesc; ElPartition<tGRSom * > aPart; ElSubGraphe<cGR_AttrSom,cGR_AttrArc> aSubAll; cSubGrFlagArc< ElSubGraphe<cGR_AttrSom,cGR_AttrArc> > aSub(aSubAll,aFlagArc); PartitionCC(aPart,mGr,aSub); std::vector<tGRSom *> aVBarbs; cSubGrSzSup aGrCons(aPGR.mSzBarb); Ebarbule(mGr,aSub,aGrCons,aVBarbs); std::set<tGRSom *> aSetB(aVBarbs.begin(),aVBarbs.end()); for (int aKC=0 ; aKC< aPart.nb() ; aKC++) { ElSubFilo<tGRSom *> aCC = aPart[aKC]; int aSzTot = SomSz(aCC); bool Ok = aSzTot >= aPGR.mSeuilZonWS ; if (Ok) { for (int aKS=0 ; aKS<aCC.size() ; aKS++) { if (aSetB.find(aCC[aKS])==aSetB.end()) { aCC[aKS]->attr().Valid() = true; } else { } } } } } // std::cout << "EeenDD PARTITION\n"; getchar(); double aSomT=0; double aMaxT=0; int aDelta = 1; // 1 for (int aKS=0 ; aKS<int(aVSom.size()) ; aKS++) { tGRSom * aSom = aVSom[aKS]; if (aSom && (! aSom->attr().DoneValR())) { ElTimer aChrono; cSubGrInterv aSG(aSom->attr().ValR()-aDelta,aSom->attr().ValR()+aDelta); ElFifo<tGRSom *> aCC; comp_connexe_som(aCC,aSom,aSG); int aSzCC = SomSz(aCC); bool Ok = aSzCC >= aPGR.mSeuilValRDelta; for (int aKC=0 ; aKC<int(aCC.size()) ; aKC++) { tGRSom * aSom2 = aCC[aKC]; if (aSom2->attr().ValR() == aSom->attr().ValR()) aSom2->attr().DoneValR() = true; if (Ok) aSom2->attr().Valid() = true; } // ShowComp(aCC,V8,(Ok?255:0), anIm,aImLabel); double aT = aChrono.uval(); aSomT += aT; if (aT > aMaxT) { aMaxT = aT; } } } /* */ // EXPORT DES RESULTATS FINALS Im2D_Bits<1> aImRes(aSz.x,aSz.y,0); TIm2DBits<1> aTImRes(aImRes); for (int aKS=0 ; aKS<int(aVSom.size()) ; aKS++) { tGRSom * aSom = aVSom[aKS]; if (aSom && aSom->attr().Valid()) { std::vector<Pt2di> aVPts; CompCnxCste(aVPts,V8,aSom->attr().P0(),anIm,aImLabel); for (int aKP=0 ; aKP<int(aVPts.size()) ; aKP++) { aTImRes.oset(aVPts[aKP],1); } } } return aImRes; }