public static void maxf ( Planar < GrayF32 > inX , Planar < GrayF32 > inY , GrayF32 outX , GrayF32 outY ) { // input and output should be the same shape InputSanityCheck . checkSameShape ( inX , inY ) ; InputSanityCheck . reshapeOneIn ( inX , outX , outY ) ; // make sure that the pixel index is the same InputSanityCheck . checkIndexing ( inX , inY ) ; InputSanityCheck . checkIndexing ( outX , outY ) ; for ( int y = 0 ; y < inX . height ; y ++ ) { int indexIn = inX . startIndex + inX . stride * y ; int indexOut = outX . startIndex + outX . stride * y ; for ( int x = 0 ; x < inX . width ; x ++ , indexIn ++ , indexOut ++ ) { float maxValueX = inX . bands [ 0 ] . data [ indexIn ] ; float maxValueY = inY . bands [ 0 ] . data [ indexIn ] ; float maxNorm = maxValueX * maxValueX + maxValueY * maxValueY ; for ( int band = 1 ; band < inX . bands . length ; band ++ ) { float valueX = inX . bands [ band ] . data [ indexIn ] ; float valueY = inY . bands [ band ] . data [ indexIn ] ; float n = valueX * valueX + valueY * valueY ; if ( n > maxNorm ) { maxNorm = n ; maxValueX = valueX ; maxValueY = valueY ; } } outX . data [ indexOut ] = maxValueX ; outY . data [ indexOut ] = maxValueY ; } } }
Reduces the number of bands by selecting the band with the largest Frobenius norm and using its gradient to be the output gradient on a pixel - by - pixel basis