/** * Rotates the image 90 degrees in the clockwise direction. */ public static void rotateCW( GrayS32 input , GrayS32 output ) { if( input.width != output.height || input.height != output.width ) throw new IllegalArgumentException("Incompatible shapes"); int h = input.height-1; for( int y = 0; y < input.height; y++ ) { int indexIn = input.startIndex + y*input.stride; for (int x = 0; x < input.width; x++) { output.unsafe_set(h-y,x,input.data[indexIn++]); } } }
/** * Rotates the image 90 degrees in the counter-clockwise direction. */ public static void rotateCCW( GrayS32 input , GrayS32 output ) { if( input.width != output.height || input.height != output.width ) throw new IllegalArgumentException("Incompatible shapes"); int w = input.width-1; for( int y = 0; y < input.height; y++ ) { int indexIn = input.startIndex + y*input.stride; for (int x = 0; x < input.width; x++) { output.unsafe_set(y,w-x,input.data[indexIn++]); } } }
/** * Examines pixels along the bottom border */ protected void connectBottom(GrayS32 input, GrayS32 output) { for( int x = 0; x < input.width-1; x++ ) { int y = input.height-1; int inputLabel = input.unsafe_get(x,y); int outputLabel = output.unsafe_get(x,y); if( outputLabel == -1 ) { // see if it needs to create a new output segment outputLabel = regionMemberCount.size; output.unsafe_set(x,y,outputLabel); regionMemberCount.add(1); mergeList.add(outputLabel); } // for 4 and 8 connect the check is only +1 x and 0 y if( inputLabel == input.unsafe_get(x+1,y) ) { int outputAdj = output.unsafe_get(x+1,y); if( outputAdj == -1 ) { // see if not assigned regionMemberCount.data[outputLabel]++; output.unsafe_set(x+1,y, outputLabel); } else if( outputLabel != outputAdj ) { // see if assigned to different regions markMerge(outputLabel,outputAdj); } // do nothing, same input and output labels } } } }
output.unsafe_set(x,y,outputLabel); regionMemberCount.add(1); mergeList.add(outputLabel); if( outputAdj == -1 ) { // see if not assigned regionMemberCount.data[outputLabel]++; output.unsafe_set(x+offset.x,y+offset.y, outputLabel); } else if( outputLabel != outputAdj ) { // see if assigned to different regions markMerge(outputLabel,outputAdj); output.unsafe_set(x,y,outputLabel); regionMemberCount.add(1); mergeList.add(outputLabel); if( outputAdj == -1 ) { // see if not assigned regionMemberCount.data[outputLabel]++; output.unsafe_set(x+offset.x,y+offset.y, outputLabel); } else if( outputLabel != outputAdj ) { // see if assigned to different regions markMerge(outputLabel,outputAdj);