/** * Computes the derivative of 'orig' along the x and y axes */ public static void process( GrayI orig, GrayI derivX, GrayI derivY) { final int width = orig.getWidth(); final int height = orig.getHeight(); for (int y = 1; y < height - 1; y++) { for (int x = 1; x < width - 1; x++) { int dy = -(orig.get(x - 1, y - 1) + 2 * orig.get(x, y - 1) + orig.get(x + 1, y - 1)); dy += (orig.get(x - 1, y + 1) + 2 * orig.get(x, y + 1) + orig.get(x + 1, y + 1)); int dx = -(orig.get(x - 1, y - 1) + 2 * orig.get(x - 1, y) + orig.get(x - 1, y + 1)); dx += (orig.get(x + 1, y - 1) + 2 * orig.get(x + 1, y) + orig.get(x + 1, y + 1)); derivX.set(x, y, dx); derivY.set(x, y, dy); } } }
private static BufferedImage grayMagnitude(GrayI src, BufferedImage dst, int maxValue) { for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = Math.abs(src.get(x, y)); int rgb = 255 * v / maxValue; dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }
public static BufferedImage grayUnsigned(GrayI src, BufferedImage dst, int normalize) { dst = checkInputs(src, dst); if (src.getDataType().isSigned()) throw new IllegalArgumentException("Can only convert unsigned images."); for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = src.get(x, y); int rgb = 255 * v / normalize; dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }
public static Kernel2D_S32 convertToKernel(GrayI image ) { int w = image.getWidth(); Kernel2D_S32 ret = new Kernel2D_S32(w); for( int i = 0; i < w; i++ ) { for( int j = 0; j < w; j++ ) { ret.set(j,i,image.get(j,i)); } } return ret; }
public void printBinary() { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { System.out.printf("%1d",get(x,y)); } System.out.println(); } } public void printNotZero() {
public static BufferedImage grayUnsigned(GrayI src, BufferedImage dst, int normalize) { dst = checkInputs(src, dst); if (src.getDataType().isSigned()) throw new IllegalArgumentException("Can only convert unsigned images."); for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = src.get(x, y); int rgb = 255 * v / normalize; dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }
for( int i = 0; i < vertM; i++ ) { for( int j = 0; j < horizM; j++ ) { horiz[j] = image.get(j+x0,i+y0);
public void print() { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { System.out.printf("%3d ",get(x,y)); } System.out.println(); } }
public static void print(GrayI a) { for (int y = 0; y < a.height; y++) { for (int x = 0; x < a.width; x++) { System.out.printf("%4d ", a.get(x, y)); } System.out.println(); } System.out.println(); }
private static BufferedImage grayMagnitude(GrayI src, BufferedImage dst, int maxValue) { for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = Math.abs(src.get(x, y)); int rgb = 255 * v / maxValue; dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }
private static BufferedImage grayMagnitudeTemp(GrayI src, BufferedImage dst, int maxValue) { int halfValue = maxValue / 2 + maxValue % 2; for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = Math.abs(src.get(x, y)); int r, b; if (v >= halfValue) { r = 255 * (v - halfValue) / halfValue; b = 0; } else { r = 0; b = 255 * v / halfValue; } if (v == 0) { r = b = 0; } else { r = 255 * v / maxValue; b = 255 * (maxValue - v) / maxValue; } dst.setRGB(x, y, r << 16 | b); } } return dst; }
private static BufferedImage grayMagnitudeTemp(GrayI src, BufferedImage dst, int maxValue) { int halfValue = maxValue / 2 + maxValue % 2; for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = Math.abs(src.get(x, y)); int r, b; if (v >= halfValue) { r = 255 * (v - halfValue) / halfValue; b = 0; } else { r = 0; b = 255 * v / halfValue; } if (v == 0) { r = b = 0; } else { r = 255 * v / maxValue; b = 255 * (maxValue - v) / maxValue; } dst.setRGB(x, y, r << 16 | b); } } return dst; }
private static BufferedImage colorizeSign(GrayI src, BufferedImage dst, int normalize) { dst = checkInputs(src, dst); for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = src.get(x, y); int rgb; if (v > 0) { rgb = ((255 * v / normalize) << 16); } else { rgb = -((255 * v / normalize) << 8); } dst.setRGB(x, y, rgb); } } return dst; }
private static BufferedImage colorizeSign(GrayI src, BufferedImage dst, int normalize) { dst = checkInputs(src, dst); for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = src.get(x, y); int rgb; if (v > 0) { rgb = ((255 * v / normalize) << 16); } else { rgb = -((255 * v / normalize) << 8); } dst.setRGB(x, y, rgb); } } return dst; }
public int get( int x , int y ) { if( image.isInBounds(x,y) ) return image.get(x,y); return getOutside( x , y ); }
@Override public int getOutside(int x, int y) { return image.get( colWrap.getIndex(x) , rowWrap.getIndex(y) ); }
storage[index++] = input.get(j,i);
@Override public float get_fast(float x, float y) { int xt = (int) x; int yt = (int) y; int x0 = xt - M/2 + offM; int y0 = yt - M/2 + offM; interp1D.setInput(horiz,horiz.length); for( int i = 0; i < M; i++ ) { for( int j = 0; j < M; j++ ) { horiz[j] = image.get(j+x0,i+y0); } vert[i]=interp1D.process(x-x0,0,M-1); } interp1D.setInput(vert,vert.length); float ret = interp1D.process(y-y0,0,M-1); // because it is fitting polynomials it can go above or below max or min values. if( ret > max ) { ret = max; } else if( ret < min ) { ret = min; } return ret; }