/** * Handle outside image pixels by extending the image. */ public static int safeGet(GrayI input , int x , int y ) { if( x < 0 ) x = 0; else if( x >= input.width ) x = input.width-1; if( y < 0 ) y = 0; else if( y >= input.height ) y = input.height-1; return input.unsafe_get(x,y); }
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; }
/** * 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); } } }
public int get( int x , int y ) { if( image.isInBounds(x,y) ) return image.get(x,y); return getOutside( x , y ); }
/** * Returns the value of the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @return an intensity value. */ public int get(int x, int y) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds: "+x+" "+y); return unsafe_get(x,y); }
@Override public void invert(GrayS32 transformed, T original) { copyInput.reshape(transformed.width,transformed.height); temp.reshape(transformed.width,transformed.height); copyInput.setTo(transformed); if( original.getDataType().getDataType() == int.class ) { WaveletTransformOps. inverseN(desc, copyInput, (GrayS32) original, temp, numLevels, minPixelValue, maxPixelValue); } else { copyOutput.reshape(original.width,original.height); WaveletTransformOps.inverseN(desc, copyInput, copyOutput,temp,numLevels,minPixelValue,maxPixelValue); GConvertImage.convert(copyOutput,original); } }
public void set( int x , int y , int value ) { if( image.isInBounds(x,y) ) image.set(x,y,value); setOutside( x , y , value); }
@Override public GrayS32 transform(T original, GrayS32 transformed) { if( transformed == null ) { ImageDimension d = UtilWavelet.transformDimension(original,numLevels); transformed = new GrayS32(d.width,d.height); } temp.reshape(transformed.width,transformed.height); copyInput.reshape(original.width,original.height); if( original.getDataType().getDataType() == int.class ) { copyInput.setTo((GrayS32)original); } else { GConvertImage.convert(original, copyInput); } WaveletTransformOps.transformN(desc, copyInput,transformed,temp,numLevels); return transformed; }
private void update( GrayI image ) { int max = (int)maxValue; for( int y = 0; y < image.height; y++ ) { for( int x = 0; x < image.width; x++ ) { int index = totalBins*image.unsafe_get(x,y)/max; if( index >= totalBins || index < 0 ) System.err.println("Bad index in ImageHistogramPanel"); else bins[index]++; } } }
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 void printNotZero() { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if( unsafe_get(x, y) == 0 ) System.out.print("0"); else System.out.print("1"); } System.out.println(); } } }
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(); } }