@Override public double unsafe_getD(int x, int y) { return image.unsafe_get(x,y); }
protected static float getBorderT(GrayF32 imageA, GrayF32 imageB, int x, int y) { if( x < 0 ) x = 0; else if( x >= imageA.width ) x = imageA.width-1; if( y < 0 ) y = 0; else if( y >= imageA.height ) y = imageA.height-1; return imageB.unsafe_get(x,y) - imageA.unsafe_get(x,y); }
/** * Ensures pixel values are inside the image. If output it is assigned to the nearest pixel inside the image */ protected static float safe( int x , int y , GrayF32 image ) { if( x < 0 ) x = 0; else if( x >= image.width ) x = image.width-1; if( y < 0 ) y = 0; else if( y >= image.height ) y = image.height-1; return image.unsafe_get(x,y); }
/** * Handle outside image pixels by extending the image. */ public static float safeGet(GrayF32 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); }
@Override public void setColor(float[] color, int x, int y) { color[0] = input.unsafe_get(x,y); }
@Override protected void computeBlockStatistics(int x0 , int y0 , int width , int height , int indexMinMax , GrayF32 input) { float min,max; min = max = input.unsafe_get(x0,y0); for (int y = 0; y < height; y++) { int indexInput = input.startIndex + (y0+y)*input.stride + x0; for (int x = 0; x < width; x++) { float value = input.data[indexInput++]; if( value < min ) min = value; else if( value > max ) max = value; } } stats.data[indexMinMax] = min; stats.data[indexMinMax+1] = max; } }
public void print( String format ) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { System.out.printf(format+" ",unsafe_get(x, y)); } System.out.println(); } }
public void print() { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { System.out.printf("%4.1f ",unsafe_get(x, y)); } System.out.println(); } }
public void printInt() { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { System.out.printf("%3d ",(int)unsafe_get(x,y)); } System.out.println(); } }
private void _transform(GrayF32 derivX , GrayF32 derivY , GrayU8 binary ) { // apply the transform to the entire image for( int y = 0; y < binary.height; y++ ) { int start = binary.startIndex + y*binary.stride; int end = start + binary.width; for( int index = start; index < end; index++ ) { if( binary.data[index] != 0 ) { int x = index-start; parameterize(x,y,derivX.unsafe_get(x,y),derivY.unsafe_get(x,y)); } } } }
private void update( GrayF32 image ) { 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 = (int) (totalBins * (image.unsafe_get(x, y) / maxValue)); 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 = (int) (totalBins * (image.unsafe_get(x, y) / maxValue)); bins[index]++; } } } }
private static BufferedImage disparity(GrayF32 src, BufferedImage dst, int minValue, int maxValue, int invalidColor) { float range = maxValue - minValue; for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float 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 = (int) (255 * v / maxValue); b = (int) (255 * (maxValue - v) / maxValue); } dst.setRGB(x, y, r << 16 | b); } } } return dst; }
private static BufferedImage disparity(GrayF32 src, BufferedImage dst, int minValue, int maxValue, int invalidColor) { float range = maxValue - minValue; for (int y = 0; y < src.height; y++) { for (int x = 0; x < src.width; x++) { float 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 = (int) (255 * v / maxValue); b = (int) (255 * (maxValue - v) / maxValue); } dst.setRGB(x, y, r << 16 | b); } } } return dst; }
private void setNaN( GrayF32 image ) { for( int y = 0; y < image.height; y++ ) { for( int x = 0; x < image.width; x++ ) { float v = image.unsafe_get(x,y); if( Float.isNaN(v) || Float.isInfinite(v) ) { image.unsafe_set(x,y,0); } } } }
private void saveLabels() throws IOException { String label = textLabel.getText(); List<double[]> colors = new ArrayList<double[]>(); GrayF32 H = hsv.getBand(0); GrayF32 S = hsv.getBand(1); GrayF32 V = hsv.getBand(2); for( int y = 0; y < selected.height; y++ ) { int index = selected.startIndex + y*selected.stride; for( int x = 0; x < selected.width; x++ ) { if( selected.data[index++] == 1 ) { float h = H.unsafe_get(x,y); float s = S.unsafe_get(x,y); float v = V.unsafe_get(x,y); colors.add( new double[]{h,s,v}); } } } FileOutputStream out = new FileOutputStream(label+".txt"); LabeledPixelCodec.write(out,label,colorModel,colors); }
private void checkPixelOutside( int x , int y ) { if( !binary.isInBounds(x,y)) return; binary.get(x, y, data); if( data[0] == 0 ) { float v0 = band0.unsafe_get(x,y); float v1 = band1.unsafe_get(x,y); float v2 = band2.unsafe_get(x,y); for( Gaussian3D_F64 model : models ) { double chisq = GaussianColorClassifier.chisq(model.mean,model.covarianceInv,v0,v1,v2); if( chisq <= thresholdChiSq ) { changeValue(x, y, 1); break; } } } }
/** * Returns the value of the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @return Pixel intensity value. */ public float 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 setColor(float[] color, int x, int y) { final int numBands = input.getNumBands(); for( int i = 0; i < numBands; i++ ) { color[i] = input.getBand(i).unsafe_get(x,y); } }
protected void detectEdgels(int index0 , int x0 , int y0 , GrayF32 derivX , GrayF32 derivY , GrayU8 binaryEdges) { edgels.reset(); for( int y = 0; y < regionSize; y++ ) { int index = index0 + y*binaryEdges.stride; for( int x = 0; x < regionSize; x++ ) { if( binaryEdges.data[index++] != 0 ) { Edgel e = edgels.grow(); int xx = x0+x; int yy = y0+y; e.set(xx,yy); float dx = derivX.unsafe_get(xx,yy); float dy = derivY.unsafe_get(xx,yy); e.theta = UtilAngle.atanSafe(dy, dx); } } } } }
public static void classify(Planar<GrayF32> input , Gaussian3D_F64 model , double thresholdChiSq, InterleavedU8 output ) { GrayF32 A = input.getBand(0); GrayF32 B = input.getBand(1); GrayF32 C = input.getBand(2); model.computeInverse(); for( int y = 0; y < input.height; y++ ) { for( int x = 0; x < input.width; x++ ) { float a = A.unsafe_get(x,y); float b = B.unsafe_get(x,y); float c = C.unsafe_get(x,y); double dist = chisq(model.mean,model.covarianceInv,a,b,c); if( dist <= thresholdChiSq ) output.set(x, y, 1); else output.set(x,y,0); } } }