void applyToBorder ( GrayU8 input , GrayU8 output , int y0 , int y1 , int x0 , int x1 , ApplyHelper h ) { // top-left corner h . computeHistogram ( 0 , 0 , input ) ; h . applyToBlock ( 0 , 0 , x0 + 1 , y0 + 1 , input , output ) ; // top-middle for ( int x = x0 + 1 ; x < x1 ; x ++ ) { h . updateHistogramX ( x - x0 , 0 , input ) ; h . applyToBlock ( x , 0 , x + 1 , y0 , input , output ) ; } // top-right h . updateHistogramX ( x1 - x0 , 0 , input ) ; h . applyToBlock ( x1 , 0 , input . width , y0 + 1 , input , output ) ; // middle-right for ( int y = y0 + 1 ; y < y1 ; y ++ ) { h . updateHistogramY ( x1 - x0 , y - y0 , input ) ; h . applyToBlock ( x1 , y , input . width , y + 1 , input , output ) ; } // bottom-right h . updateHistogramY ( x1 - x0 , y1 - y0 , input ) ; h . applyToBlock ( x1 , y1 , input . width , input . height , input , output ) ; //Start over in the top-left. Yes this step could be avoided... // middle-left h . computeHistogram ( 0 , 0 , input ) ; for ( int y = y0 + 1 ; y < y1 ; y ++ ) { h . updateHistogramY ( 0 , y - y0 , input ) ; h . applyToBlock ( 0 , y , x0 , y + 1 , input , output ) ; } // bottom-left h . updateHistogramY ( 0 , y1 - y0 , input ) ; h . applyToBlock ( 0 , y1 , x0 + 1 , input . height , input , output ) ; // bottom-middle for ( int x = x0 + 1 ; x < x1 ; x ++ ) { h . updateHistogramX ( x - x0 , y1 - y0 , input ) ; h . applyToBlock ( x , y1 , x + 1 , input . height , input , output ) ; } }
Apply around the image border . Use a region that s the full size but apply to all pixels that the region would go outside of it was centered on them .