public static void vertical ( GrayF32 src , GrayF32 dst ) { if ( src . height < dst . height ) throw new IllegalArgumentException ( "src height must be >= dst height" ) ; if ( src . width != dst . width ) throw new IllegalArgumentException ( "src width must equal dst width" ) ; float scale = src . height / ( float ) dst . height ; //CONCURRENT_BELOW BoofConcurrency.loopFor(0, dst.width, x -> { for ( int x = 0 ; x < dst . width ; x ++ ) { int indexDst = dst . startIndex + x ; for ( int y = 0 ; y < dst . height - 1 ; y ++ ) { float srcY0 = y * scale ; float srcY1 = ( y + 1 ) * scale ; int isrcY0 = ( int ) srcY0 ; int isrcY1 = ( int ) srcY1 ; int index = src . getIndex ( x , isrcY0 ) ; // compute value of overlapped region float startWeight = ( 1.0f - ( srcY0 - isrcY0 ) ) ; float start = src . data [ index ] ; index += src . stride ; float middle = 0 ; for ( int i = isrcY0 + 1 ; i < isrcY1 ; i ++ ) { middle += src . data [ index ] ; index += src . stride ; } float endWeight = ( srcY1 % 1 ) ; float end = src . data [ index ] ; dst . data [ indexDst ] = ( float ) ( ( start * startWeight + middle + end * endWeight ) / scale ) ; indexDst += dst . stride ; } // handle the last area as a special case int y = dst . height - 1 ; float srcY0 = y * scale ; int isrcY0 = ( int ) srcY0 ; int isrcY1 = src . height - 1 ; int index = src . getIndex ( x , isrcY0 ) ; // compute value of overlapped region float startWeight = ( 1.0f - ( srcY0 - isrcY0 ) ) ; float start = src . data [ index ] ; index += src . stride ; float middle = 0 ; for ( int i = isrcY0 + 1 ; i < isrcY1 ; i ++ ) { middle += src . data [ index ] ; index += src . stride ; } float end = isrcY1 != isrcY0 ? src . data [ index ] : 0 ; dst . data [ indexDst ] = ( float ) ( ( start * startWeight + middle + end ) / scale ) ; } //CONCURRENT_ABOVE }); }
Down samples the image along the y - axis only . Image width s must be the same .