protected int s( int x , int y ) { if( x < 0 ) x = 0; else if( x >= warpImage2.width ) x = warpImage2.width-1; if( y < 0 ) y = 0; else if( y >= warpImage2.height ) y = warpImage2.height-1; return warpImage2.getIndex(x,y); }
@Override public float unsafe_getF(int x, int y) { return image.data[image.getIndex(x,y)]; }
public float unsafe_get(int x, int y) { return data[getIndex(x, y)]; }
public void unsafe_set(int x, int y, float value) { data[getIndex(x, y)] = value; }
/** * See equation 25. Fast unsafe version */ protected static float A( int x , int y , GrayF32 flow ) { int index = flow.getIndex(x,y); float u0 = flow.data[index-1]; float u1 = flow.data[index+1]; float u2 = flow.data[index-flow.stride]; float u3 = flow.data[index+flow.stride]; float u4 = flow.data[index-1-flow.stride]; float u5 = flow.data[index+1-flow.stride]; float u6 = flow.data[index-1+flow.stride]; float u7 = flow.data[index+1+flow.stride]; return (1.0f/6.0f)*(u0 + u1 + u2 + u3) + (1.0f/12.0f)*(u4 + u5 + u6 + u7); }
/** * Renders a dot as a square sprite with the specified color */ private void renderDot( int cx , int cy , float Z , int rgb ) { for (int i = -dotRadius; i <= dotRadius; i++) { int y = cy+i; if( y < 0 || y >= imageRgb.height ) continue; for (int j = -dotRadius; j <= dotRadius; j++) { int x = cx+j; if( x < 0 || x >= imageRgb.width ) continue; int pixelIndex = imageDepth.getIndex(x,y); float depth = imageDepth.data[pixelIndex]; if( depth > Z ) { imageDepth.data[pixelIndex] = Z; imageRgb.data[pixelIndex] = rgb; } } } }
public static void convert( GrayU8 from, GrayF32 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] & 0xFF); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] & 0xFF); } } }
public static void convert( GrayS8 from, GrayF32 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] ); } } }
public static void convert( GrayF32 from, GrayS64 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( long )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( long )( from.data[i] ); } } }
public static void convert( GrayU16 from, GrayF32 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] & 0xFFFF); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] & 0xFFFF); } } }
public static void convert( GrayS16 from, GrayF32 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] ); } } }
public static void convert( GrayS64 from, GrayF32 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] ); } } }
public static void convert( GrayF32 from, GrayI16 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( short )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( short )( from.data[i] ); } } }
public static void convert( GrayF32 from, GrayS32 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( int )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( int )( from.data[i] ); } } }
public static void convert( GrayF64 from, GrayF32 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] ); } } }
public static void convert( GrayS32 from, GrayF32 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] ); } } }
public static void convert( GrayF32 from, GrayI8 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( byte )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( byte )( from.data[i] ); } } }
public static void convert( GrayF32 from, GrayF64 to ) { if (from.isSubimage() || to.isSubimage()) { for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < from.width; x++) { to.data[indexTo++] = ( double )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height; for (int i = 0; i < N; i++) { to.data[i] = ( double )( from.data[i] ); } } }
/** * Scales an image up using interpolation */ public static void scaleImageUp(GrayF32 input , GrayF32 output , int scale , InterpolatePixelS<GrayF32> interp ) { output.reshape(input.width*scale,input.height*scale); float fdiv = 1/(float)scale; interp.setImage(input); for (int y = 0; y < output.height; y++) { float inputY = y*fdiv; int indexOutput = output.getIndex(0,y); for (int x = 0; x < output.width; x++) { float inputX = x*fdiv; output.data[indexOutput++] = interp.get(inputX,inputY); } } }
protected void computeDivUVD_safe(int x , int y , GrayF32 u , GrayF32 v , GrayF32 psi , GrayF32 divU , GrayF32 divV , GrayF32 divD ) { int index = u.getIndex(x, y); int index_px = s(x + 1, y); int index_mx = s(x - 1, y); int index_py = s(x, y + 1); int index_my = s(x, y - 1); float psi_index = psi.data[index]; float coef0 = 0.5f*(psi.data[index_px] + psi_index); float coef1 = 0.5f*(psi.data[index_mx] + psi_index); float coef2 = 0.5f*(psi.data[index_py] + psi_index); float coef3 = 0.5f*(psi.data[index_my] + psi_index); float u_index = u.data[index]; divU.data[index] = coef0*(u.data[index_px] - u_index) + coef1*(u.data[index_mx] - u_index) + coef2*(u.data[index_py] - u_index) + coef3*(u.data[index_my] - u_index); float v_index = v.data[index]; divV.data[index] = coef0*(v.data[index_px] - v_index) + coef1*(v.data[index_mx] - v_index) + coef2*(v.data[index_py] - v_index) + coef3*(v.data[index_my] - v_index); divD.data[index] = coef0 + coef1 + coef2 + coef3; }