/** * 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); }
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]++; } } }
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(); } } }
private void update( GrayI image ) { int max = (int)maxValue; if( image.width*image.height < 200*200 ) { 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); bins[index]++; } } } else { int periodX = (int)Math.ceil(image.width/250.0); int periodY = (int)Math.ceil(image.width/250.0); for (int y = 0; y < image.height; y += periodY) { for (int x = 0; x < image.width; x += periodX ) { int index = totalBins * (image.unsafe_get(x, y) / max); bins[index]++; } } } }
private static BufferedImage disparity(GrayI src, BufferedImage dst, int minValue, int maxValue, int invalidColor) { int range = maxValue - minValue; for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = src.unsafe_get(x, y); if (v > range) { dst.setRGB(x, y, invalidColor); } else { int r, b; 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 disparity(GrayI src, BufferedImage dst, int minValue, int maxValue, int invalidColor) { int range = maxValue - minValue; for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { int v = src.unsafe_get(x, y); if (v > range) { dst.setRGB(x, y, invalidColor); } else { int r, b; 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; }
/** * 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); }
int v = disparity.unsafe_get(x, y); int r,g,b;
int v = disparity.unsafe_get(x, y); int r,g,b;