protected void sortPixels(GrayU8 input) {
		// initialize histogram
		for( int i = 0; i < histogram.length; i++ ) {
			histogram[i].reset();
		}
		// sort by creating a histogram
		for( int y = 0; y < input.height; y++ ) {
			int index = input.startIndex + y*input.stride;
			int indexOut = (y+1)*output.stride + 1;
			for (int x = 0; x < input.width; x++ , index++ , indexOut++) {
				int value = input.data[index] & 0xFF;
				histogram[value].add(indexOut);
			}
		}
	}
protected void sortPixels ( GrayU8 input ) { for ( int i = 0 ; i < histogram . length ; i ++ ) { histogram [ i ] . reset ( ) ; } for ( int y = 0 ; y < input . height ; y ++ ) { int index = input . startIndex + y * input . stride ; int indexOut = ( y + 1 ) * output . stride + 1 ; for ( int x = 0 ; x < input . width ; x ++ , index ++ , indexOut ++ ) { int value = input . data [ index ] & 0xFF ; histogram [ value ] . add ( indexOut ) ; } } }
Very fast histogram based sorting.  Index of each pixel is placed inside a list for its intensity level.