@Override public float getIntensity(int x, int y) { return input.get(x,y); } }
public static double computeError(GrayF32 imgA, GrayF32 imgB ) { final int h = imgA.getHeight(); final int w = imgA.getWidth(); double total = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { double difference = Math.abs(imgA.get(x,y)-imgB.get(x,y)); total += difference; } } return total / (w*h); }
public static Kernel2D_F32 convertToKernel( GrayF32 image ) { int w = image.getWidth(); Kernel2D_F32 ret = new Kernel2D_F32(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 static double computeWeightedError(GrayF32 imgA, GrayF32 imgB , GrayF32 imgWeight ) { final int h = imgA.getHeight(); final int w = imgA.getWidth(); double total = 0; double totalWeight = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { float weight = imgWeight.get(x,y); double difference = Math.abs(imgA.get(x,y)-imgB.get(x,y)); total += difference*weight; totalWeight += weight; } } return total / totalWeight; }
@Override public Number get(int x, int y) { return image.get(x,y); }
public static void horizontal(Kernel1D_F32 kernel, GrayF32 input, GrayF32 output ) { final int offset = kernel.getOffset(); final int width = input.getWidth(); final int height = input.getHeight(); for (int y = 0; y < height; y++) { for( int x = 0; x < width; x++ ) { float total = 0; float weight = 0; int startX = x - offset; int endX = startX+kernel.getWidth(); if( startX < 0 ) startX = 0; if( endX > width ) endX = width; for( int j = startX; j < endX; j++ ) { float v = kernel.get(j-x+offset); total += input.get(j,y)*v; weight += v; } output.set(x,y, total/weight ); } } }
private void update( GrayF32 image ) { for( int y = 0; y < image.height; y++ ) { for( int x = 0; x < image.width; x++ ) { int index = (int)(totalBins*(image.get(x,y)/maxValue)); if( index >= totalBins || index < 0 ) System.err.println("Bad index in ImageHistogramPanel"); else bins[index]++; } } }
public static void vertical(Kernel1D_F32 kernel, GrayF32 input, GrayF32 output ) { final int offset = kernel.getOffset(); final int width = input.getWidth(); final int height = input.getHeight(); for (int y = 0; y < height; y++) { for( int x = 0; x < width; x++ ) { float total = 0; float weight = 0; int startY = y - offset; int endY = startY + kernel.getWidth(); if( startY < 0 ) startY = 0; if( endY > height ) endY = height; for( int i = startY; i < endY; i++ ) { float v = kernel.get(i-y+offset); total += input.get(x,i)*v; weight += v; } output.set(x,y, total/weight ); } } }
private static BufferedImage grayMagnitude(GrayF32 src, BufferedImage dst, float maxAbsValue) { for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float v = Math.abs(src.get(x, y)); int rgb = (int) (255 * v / maxAbsValue); dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }
private static BufferedImage colorizeSign(GrayF32 src, BufferedImage dst, float maxAbsValue) { for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float v = src.get(x, y); int rgb; if (v > 0) { rgb = (int) (255 * v / maxAbsValue) << 16; } else { rgb = (int) (-255 * v / maxAbsValue) << 8; } dst.setRGB(x, y, rgb); } } return dst; }
private static BufferedImage colorizeSign(GrayF32 src, BufferedImage dst, float maxAbsValue) { for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float v = src.get(x, y); int rgb; if (v > 0) { rgb = (int) (255 * v / maxAbsValue) << 16; } else { rgb = (int) (-255 * v / maxAbsValue) << 8; } dst.setRGB(x, y, rgb); } } return dst; }
public static void print(GrayF32 a) { for (int y = 0; y < a.height; y++) { for (int x = 0; x < a.width; x++) { System.out.printf("%6.2f ", a.get(x, y)); } System.out.println(); } System.out.println(); }
private static BufferedImage grayMagnitude(GrayF32 src, BufferedImage dst, float maxAbsValue) { for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float v = Math.abs(src.get(x, y)); int rgb = (int) (255 * v / maxAbsValue); dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }
public static BufferedImage graySign(GrayF32 src, BufferedImage dst, float maxAbsValue) { dst = checkInputs(src, dst); if (maxAbsValue < 0) maxAbsValue = ImageStatistics.maxAbs(src); for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float v = src.get(x, y); int rgb = 127 + (int) (127 * v / maxAbsValue); dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }
public static BufferedImage graySign(GrayF32 src, BufferedImage dst, float maxAbsValue) { dst = checkInputs(src, dst); if (maxAbsValue < 0) maxAbsValue = ImageStatistics.maxAbs(src); for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float v = src.get(x, y); int rgb = 127 + (int) (127 * v / maxAbsValue); dst.setRGB(x, y, rgb << 16 | rgb << 8 | rgb); } } return dst; }
public float get( int x , int y ) { if( image.isInBounds(x,y) ) return image.get(x,y); return getOutside( x , y ); }
@Override public float getOutside(int x, int y) { return image.get( colWrap.getIndex(x) , rowWrap.getIndex(y) ); }
private double computeEdgeMSE(GrayF32 imageInv) { GrayF32 edge = new GrayF32(imageInv.width,imageInv.height); LaplacianEdge.process(image,edge); PixelMath.abs(edge,edge); float max = ImageStatistics.maxAbs(edge); PixelMath.divide(edge,max,edge); float total = ImageStatistics.sum(edge); double error = 0; for( int y = 0; y < image.height; y++ ) { for( int x = 0; x < image.width; x++ ) { double w = edge.get(x,y)/total; double e = (image.get(x,y)-imageInv.get(x,y)); error += (e*e)*w; } } return error; }
public static double get(ImageGray img, int x, int y) { if (img instanceof GrayI8) { return ((GrayI8) img).get(x, y); } else if (img instanceof GrayI16) { return ((GrayI16) img).get(x, y); } else if (img instanceof GrayS32) { return ((GrayS32) img).get(x, y); } else if (img instanceof GrayF32) { return ((GrayF32) img).get(x, y); } else if (img instanceof GrayF64) { return ((GrayF64) img).get(x, y); } else if (img instanceof GrayS64) { return ((GrayS64) img).get(x, y); } else { throw new IllegalArgumentException("Unknown or incompatible image type: " + img.getClass().getSimpleName()); } }
public static void vertical(Kernel1D_F32 kernel, GrayF32 input, GrayF32 output , int skip ) { final int radius = kernel.getRadius(); final int width = input.width; final int height = input.height - input.height % skip; for (int y = 0; y < height; y += skip) { for( int x = 0; x < width; x++ ) { float total = 0; float div = 0; int startY = y - radius; int endY = y + radius; if( startY < 0 ) startY = 0; if( endY >= input.height ) endY = input.height-1; for( int i = startY; i <= endY; i++ ) { float v = kernel.get(i-y+radius); total += input.get(x,i)*v; div += v; } output.set(x,y/skip, total/div ); } } }