WHcoord fileManager::meanCoordFromMask() const { if (m_maskMatrix.empty()) { std::cerr<< "ERROR @ fileManager::storeFullTract(): Mask hast not been loaded, returning 0 coordinate"<<std::endl; return WHcoord(); } size_t sumX( 0 ), sumY( 0 ), sumZ( 0 ), sumElements( 0 ); for( int i=0 ; i<m_maskMatrix.size() ; ++i ) { for( int j=0 ; j< m_maskMatrix[i].size() ; ++j ) { for( int k=0 ; k<m_maskMatrix[i][j].size() ; ++k ) { if (m_maskMatrix[i][j][k]) { sumX += i; sumY += j; sumZ += k; ++sumElements; } } } } size_t meanX( sumX/sumElements ); size_t meanY( sumY/sumElements ); size_t meanZ( sumZ/sumElements ); WHcoord meanCoord(meanX,meanY,meanZ); return meanCoord; } // end "meanCoordFromMask()" -----------------------------------------------------------------
bool iAIDA::AIDA_Histogram_native::AIDA_Histogram2D::setRms( double rmsX, double rmsY ) { const double sw = sumBinHeights(); const double mnX = meanX(); const double mnY = meanY(); m_sumWeightTimesSquaredX = ( mnX*mnX + rmsX*rmsX) * sw; m_sumWeightTimesSquaredY = ( mnY*mnY + rmsY*rmsY) * sw; m_validStatistics = false; return true; }
void iAIDA::AIDA_Histogram_native::AIDA_Histogram2D::updateAnnotation() const { iAIDA::AIDA_Histogram_native::AIDA_BaseHistogram::updateAnnotation(); const AIDA::IAnnotation& anno = annotationNoUpdate(); AIDA::IAnnotation& annotation = const_cast< AIDA::IAnnotation& >( anno ); annotation.setValue( meanXKey, iAIDA_annotationNumberFormater.formatDouble( meanX() ) ); annotation.setValue( rmsXKey, iAIDA_annotationNumberFormater.formatDouble( rmsX() ) ); annotation.setValue( meanYKey, iAIDA_annotationNumberFormater.formatDouble( meanY() ) ); annotation.setValue( rmsYKey, iAIDA_annotationNumberFormater.formatDouble( rmsY() ) ); annotation.setValue( extra_entriesKey, iAIDA_annotationNumberFormater.formatInteger( extraEntries() ) ); }
void EdgeBoxGenerator::clusterEdges( arrayf &E, arrayf &O, arrayf &V ) { int c, r, cd, rd, i, j; h=E._h; w=E._w; // greedily merge connected edge pixels into clusters (create _segIds) _segIds.init(h,w); _segCnt=1; for( c=0; c<w; c++ ) for( r=0; r<h; r++ ) { if( c==0 || r==0 || c==w-1 || r==h-1 || E.val(c,r)<=_edgeMinMag ) _segIds.val(c,r)=-1; else _segIds.val(c,r)=0; } for( c=1; c<w-1; c++ ) for( r=1; r<h-1; r++ ) { if(_segIds.val(c,r)!=0) continue; float sumv=0; int c0=c, r0=r; vectorf vs; vectori cs, rs; while( sumv < _edgeMergeThr ) { _segIds.val(c0,r0)=_segCnt; float o0 = O.val(c0,r0), o1, v; bool found; for( cd=-1; cd<=1; cd++ ) for( rd=-1; rd<=1; rd++ ) { if( _segIds.val(c0+cd,r0+rd)!=0 ) continue; found=false; for( i=0; i<cs.size(); i++ ) if( cs[i]==c0+cd && rs[i]==r0+rd ) { found=true; break; } if( found ) continue; o1=O.val(c0+cd,r0+rd); v=fabs(o1-o0)/PI; if(v>.5) v=1-v; vs.push_back(v); cs.push_back(c0+cd); rs.push_back(r0+rd); } float minv=1000; j=0; for( i=0; i<vs.size(); i++ ) if( vs[i]<minv ) { minv=vs[i]; c0=cs[i]; r0=rs[i]; j=i; } sumv+=minv; if(minv<1000) vs[j]=1000; } _segCnt++; } // merge or remove small segments _segMag.resize(_segCnt,0); for( c=1; c<w-1; c++ ) for( r=1; r<h-1; r++ ) if( (j=_segIds.val(c,r))>0 ) _segMag[j]+=E.val(c,r); for( c=1; c<w-1; c++ ) for( r=1; r<h-1; r++ ) if( (j=_segIds.val(c,r))>0 && _segMag[j]<=_clusterMinMag) _segIds.val(c,r)=0; i=1; while(i>0) { i=0; for( c=1; c<w-1; c++ ) for( r=1; r<h-1; r++ ) { if( _segIds.val(c,r)!=0 ) continue; float o0=O.val(c,r), o1, v, minv=1000; j=0; for( cd=-1; cd<=1; cd++ ) for( rd=-1; rd<=1; rd++ ) { if( _segIds.val(c+cd,r+rd)<=0 ) continue; o1=O.val(c+cd,r+rd); v=fabs(o1-o0)/PI; if(v>.5) v=1-v; if( v<minv ) { minv=v; j=_segIds.val(c+cd,r+rd); } } _segIds.val(c,r)=j; if(j>0) i++; } } // compactify representation _segMag.assign(_segCnt,0); vectori map(_segCnt,0); _segCnt=1; for( c=1; c<w-1; c++ ) for( r=1; r<h-1; r++ ) if( (j=_segIds.val(c,r))>0 ) _segMag[j]+=E.val(c,r); for( i=0; i<_segMag.size(); i++ ) if( _segMag[i]>0 ) map[i]=_segCnt++; for( c=1; c<w-1; c++ ) for( r=1; r<h-1; r++ ) if( (j=_segIds.val(c,r))>0 ) _segIds.val(c,r)=map[j]; // compute positional means and recompute _segMag _segMag.assign(_segCnt,0); vectorf meanX(_segCnt,0), meanY(_segCnt,0); vectorf meanOx(_segCnt,0), meanOy(_segCnt,0), meanO(_segCnt,0); for( c=1; c<w-1; c++ ) for( r=1; r<h-1; r++ ) { j=_segIds.val(c,r); if(j<=0) continue; float m=E.val(c,r), o=O.val(c,r); _segMag[j]+=m; meanOx[j]+=m*cos(2*o); meanOy[j]+=m*sin(2*o); meanX[j]+=m*c; meanY[j]+=m*r; } for( i=0; i<_segCnt; i++ ) if( _segMag[i]>0 ) { float m=_segMag[i]; meanX[i]/=m; meanY[i]/=m; meanO[i]=atan2(meanOy[i]/m,meanOx[i]/m)/2; } // compute segment affinities _segAff.resize(_segCnt); _segAffIdx.resize(_segCnt); for(i=0; i<_segCnt; i++) _segAff[i].resize(0); for(i=0; i<_segCnt; i++) _segAffIdx[i].resize(0); const int rad = 2; for( c=rad; c<w-rad; c++ ) for( r=rad; r<h-rad; r++ ) { int s0=_segIds.val(c,r); if( s0<=0 ) continue; for( cd=-rad; cd<=rad; cd++ ) for( rd=-rad; rd<=rad; rd++ ) { int s1=_segIds.val(c+cd,r+rd); if(s1<=s0) continue; bool found = false; for(i=0;i<_segAffIdx[s0].size();i++) if(_segAffIdx[s0][i] == s1) { found=true; break; } if( found ) continue; float o=atan2(meanY[s0]-meanY[s1],meanX[s0]-meanX[s1])+PI/2; float a=fabs(cos(meanO[s0]-o)*cos(meanO[s1]-o)); a=pow(a,_gamma); _segAff[s0].push_back(a); _segAffIdx[s0].push_back(s1); _segAff[s1].push_back(a); _segAffIdx[s1].push_back(s0); } } // compute _segC and _segR _segC.resize(_segCnt); _segR.resize(_segCnt); for( c=1; c<w-1; c++ ) for( r=1; r<h-1; r++ ) if( (j=_segIds.val(c,r))>0 ) { _segC[j]=c; _segR[j]=r; } // optionally create visualization (assume memory initialized is 3*w*h) if( V._x ) for( c=0; c<w; c++ ) for( r=0; r<h; r++ ) { i=_segIds.val(c,r); V.val(c+w*0,r) = i<=0 ? 1 : ((123*i + 128)%255)/255.0f; V.val(c+w*1,r) = i<=0 ? 1 : ((7*i + 3)%255)/255.0f; V.val(c+w*2,r) = i<=0 ? 1 : ((174*i + 80)%255)/255.0f; } }