double_xyz rimginterface::MaximumInArea( tImgPlanar const& im, tAoi area ) { assert( im.is_mono8() ); int iy = area.sy(); const int x = area.px(); const int y = area.py(); int max = 0; while( iy-- ) { int ix = area.sx(); while( ix-- ) { int val = im[0][ y + iy ][ x + ix]; if( val > max ) { max = val; } } } vector<int32_xy> newxy( area.sx()*area.sy() + 1 ); // tixy *xy = newxy(); uint32_t maxcount = 0; iy = area.sy(); while( iy-- ) { int ix = area.sx(); while( ix-- ) { int val = im.pixel( uint32_xy( x + ix, y + iy ) ); if( val == max ) { newxy[ maxcount ].setx( x + ix ); newxy[ maxcount ].sety( y + iy ); maxcount++; } } } if( maxcount == 0 ) { assert( false ); } double dx = 0.0; double dy = 0.0; uint32_t count = maxcount; while( count ) { count--; dx += static_cast<double>(newxy[ count ].x()); dy += static_cast<double>(newxy[ count ].y()); } dx /= static_cast<double>(maxcount); dy /= static_cast<double>(maxcount); return double_xyz( dx, dy, max ); }
bool rimginterface::ExtractAoi( tImgViewPlanar const& source, tImgPlanar& target, tAoi& aoi ) { if( target.equals_size_mask( source ) ) { //target = source.to_ImgViewPlanar(); return true; } // test if aoi is in img if( aoi.px() >= static_cast<int>(source.sx()) || aoi.py() >= static_cast<int>(source.sy()) ) { return false; } // -- calculate the true size of copied image if( aoi.px() + aoi.sx() > source.sx() ) { aoi.sx( source.sx() - aoi.px() ); } if( aoi.py() + aoi.sy() > source.sy() ) { aoi.sy( source.sy() - aoi.py() ); } if( aoi.sx() <= 1 || aoi.sy() <= 1 ) { return false; } tSize size = tSize( aoi.sx(), aoi.sy() ); // img.size(); target.realloc( size, source.mask() ); auto mbegin = source.begin(); auto mend = source.end(); auto maoibegin = target.begin(); while( mbegin < mend ) { vector< vector<uint8_t> >::const_iterator ybegin = mbegin->begin() + aoi.py(); vector< vector<uint8_t> >::iterator yaoibegin = maoibegin->begin(); vector< vector<uint8_t> >::const_iterator yaoiend = maoibegin->end(); int c = 0; while( yaoibegin != yaoiend ) { yaoibegin->assign( ybegin->begin() + aoi.px(), ybegin->begin() + aoi.px() + aoi.sx() ); ++yaoibegin; ++ybegin; c++; } ++mbegin; ++maoibegin; } return true; }
bool tAoi::overlap( tAoi const& area_ )const { int s0 = area(); int s1 = area_.area(); if( s0 > s1 ) { int xend = area_.px() + area_.sx(); int yend = area_.py() + area_.sy(); for( int y = area_.py(); y < yend; y++ ) { for( int x = area_.px(); x < xend; x++ ) { if( inside( int32_xy( x, y ) ) != false ) { return true; } } } } else { int xend = px() + sx(); int yend = py() + sy(); for( int y = py(); y < yend; y++ ) { for( int x = px(); x < xend; x++ ) { if( area_.inside( int32_xy( x, y ) ) != false ) { return true; } } } } return false; }