@Override protected void computeDerivX(GrayU8 image1, GrayU8 image2, GrayS16 derivX) { int w = image1.width-1; int h = image1.height-1; for( int y = 0; y < h; y++ ) { int index1 = image1.startIndex + y*image1.stride; int index2 = image2.startIndex + y*image2.stride; int indexX = derivX.startIndex + y*derivX.stride; for( int x = 0; x < w; x++ , index1++ , index2++ , indexX++ ) { int d0 = (image1.data[index1+1]&0xFF) - (image1.data[index1]&0xFF); int d2 = (image2.data[index2+1]&0xFF) - (image2.data[index2]&0xFF); int d1 = (image1.data[index1+1+image1.stride]&0xFF) - (image1.data[index1+image1.stride]&0xFF); int d3 = (image2.data[index2+1+image2.stride]&0xFF) - (image2.data[index2+image2.stride]&0xFF); derivX.data[indexX] = (short)((d0 + d1 + d2 + d3)/4); } } for( int y = 0; y < image1.height; y++ ) { derivX.unsafe_set(w,y, 0); } for( int x = 0; x < w; x++ ) { int d0 = image1.unsafe_get(x+1,h) - image1.unsafe_get(x,h); int d1 = image2.unsafe_get(x+1,h) - image2.unsafe_get(x,h); derivX.unsafe_set(x,h, (d0+d1)/2); } }
@Override protected void computeDerivY(GrayU8 image1, GrayU8 image2, GrayS16 derivY) { int w = image1.width-1; int h = image1.height-1; for( int y = 0; y < h; y++ ) { int index1 = image1.startIndex + y*image1.stride; int index2 = image2.startIndex + y*image2.stride; int indexY = derivY.startIndex + y*derivY.stride; for( int x = 0; x < w; x++ , index1++ , index2++ , indexY++ ) { int d0 = (image1.data[index1+image1.stride]&0xFF) - (image1.data[index1]&0xFF); int d2 = (image2.data[index2+image2.stride]&0xFF) - (image2.data[index2]&0xFF); int d1 = (image1.data[index1+1+image1.stride]&0xFF) - (image1.data[index1+1]&0xFF); int d3 = (image2.data[index2+1+image2.stride]&0xFF) - (image2.data[index2+1]&0xFF); derivY.data[indexY] = (short)((d0 + d1 + d2 + d3)/4); } } for( int y = 0; y < h; y++ ) { int d0 = image1.unsafe_get(w, y + 1) - image1.unsafe_get(w,y); int d1 = image2.unsafe_get(w, y + 1) - image2.unsafe_get(w,y); derivY.unsafe_set(w,y, (d0+d1)/2); } for( int x = 0; x < w; x++ ) { derivY.unsafe_set(x, h, 0); } }
protected static void borderDerivT(GrayU8 imageA , GrayU8 imageB , GrayS16 difference, int x, int y) { float d0 = getBorderT(imageA, imageB, x , y ); float d1 = getBorderT(imageA, imageB, x + 1, y ); float d2 = getBorderT(imageA, imageB, x , y + 1); float d3 = getBorderT(imageA, imageB, x + 1, y + 1); difference.unsafe_set(x,y, (short)((d0+d1+d2+d3)/4)); }