/** * Rotates the image 90 degrees in the clockwise direction. */ public static void rotateCW( GrayF32 input , GrayF32 output ) { if( input.width != output.height || input.height != output.width ) throw new IllegalArgumentException("Incompatible shapes"); int h = input.height-1; for( int y = 0; y < input.height; y++ ) { int indexIn = input.startIndex + y*input.stride; for (int x = 0; x < input.width; x++) { output.unsafe_set(h-y,x,input.data[indexIn++]); } } }
/** * Rotates the image 90 degrees in the counter-clockwise direction. */ public static void rotateCCW( GrayF32 input , GrayF32 output ) { if( input.width != output.height || input.height != output.width ) throw new IllegalArgumentException("Incompatible shapes"); int w = input.width-1; for( int y = 0; y < input.height; y++ ) { int indexIn = input.startIndex + y*input.stride; for (int x = 0; x < input.width; x++) { output.unsafe_set(y,w-x,input.data[indexIn++]); } } }
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); } } } }
public void classify( GrayF32 band0 , GrayF32 band1 , GrayF32 output ) { System.out.println("total road = "+road.size()+" other "+other.size()); for( int y = 0; y < band0.height; y++ ) { for( int x = 0; x < band0.width; x++ ) { double v0 = band0.unsafe_get(x,y); double v1 = band1.unsafe_get(x,y); double scoreRoad = selectBest(road,v0,v1); // System.out.println("score "+scoreRoad); if( scoreRoad > maxChiSquare ) { output.unsafe_set(x,y,0); } else { double scoreOther = selectBest(other,v0,v1); if( scoreRoad < scoreOther ) { output.unsafe_set(x,y,1); } else { output.unsafe_set(x,y,0); } } } } }
/** * Sets the value of the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @param value The pixel's new value. */ public void set(int x, int y, float value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds: "+x+" "+y); unsafe_set(x,y,value); }
@Override protected void computeDerivX(GrayF32 image1, GrayF32 image2, GrayF32 derivX) { int w = image1.width-1; int h = image1.height-1; for( int y = 0; y < h; y++ ) { int index1 = image1.startIndex + y*image1.stride; int index2 = image2.startIndex + y*image2.stride; int indexX = derivX.startIndex + y*derivX.stride; for( int x = 0; x < w; x++ , index1++ , index2++ , indexX++ ) { float d0 = image1.data[index1+1] - image1.data[index1]; float d2 = image2.data[index2+1] - image2.data[index2]; float d1 = image1.data[index1+1+image1.stride] - image1.data[index1+image1.stride]; float d3 = image2.data[index2+1+image2.stride] - image2.data[index2+image2.stride]; derivX.data[indexX] = 0.25f*(d0 + d1 + d2 + d3); } } for( int y = 0; y < image1.height; y++ ) { derivX.unsafe_set(w,y, 0); } for( int x = 0; x < w; x++ ) { float d0 = image1.unsafe_get(x+1,h) - image1.unsafe_get(x,h); float d1 = image2.unsafe_get(x+1,h) - image2.unsafe_get(x,h); derivX.unsafe_set(x,h, 0.5f*(d0+d1)); } }
@Override protected void computeDerivY(GrayF32 image1, GrayF32 image2, GrayF32 derivY) { int w = image1.width-1; int h = image1.height-1; for( int y = 0; y < h; y++ ) { int index1 = image1.startIndex + y*image1.stride; int index2 = image2.startIndex + y*image2.stride; int indexY = derivY.startIndex + y*derivY.stride; for( int x = 0; x < w; x++ , index1++ , index2++ , indexY++ ) { float d0 = image1.data[index1+image1.stride] - image1.data[index1]; float d2 = image2.data[index2+image2.stride] - image2.data[index2]; float d1 = image1.data[index1+1+image1.stride] - image1.data[index1+1]; float d3 = image2.data[index2+1+image2.stride] - image2.data[index2+1]; derivY.data[indexY] = 0.25f*(d0 + d1 + d2 + d3); } } for( int y = 0; y < h; y++ ) { float d0 = image1.unsafe_get(w, y + 1) - image1.unsafe_get(w,y); float d1 = image2.unsafe_get(w, y + 1) - image2.unsafe_get(w,y); derivY.unsafe_set(w,y, 0.5f*(d0+d1)); } for( int x = 0; x < w; x++ ) { derivY.unsafe_set(x, h, 0); } }
public static void magnitudeAbs(ImageFlow flowImage, float maxValue, BufferedImage out) { GrayF32 magnitude = new GrayF32(flowImage.width,flowImage.height); for( int y = 0; y < flowImage.height; y++ ) { for( int x = 0; x < flowImage.width; x++ ) { ImageFlow.D f = flowImage.unsafe_get(x,y); if( !f.isValid() ) { out.setRGB(x,y,0xFF); } else { float m = Math.max(Math.abs(f.x),Math.abs(f.y)); magnitude.unsafe_set(x, y, m); } } } PixelMath.multiply(magnitude, 255 / maxValue, magnitude); PixelMath.boundImage(magnitude,0,255); ConvertBufferedImage.convertTo(magnitude,out); }
public static void magnitudeAbs(ImageFlow flowImage, BufferedImage out) { GrayF32 magnitude = new GrayF32(flowImage.width,flowImage.height); float max = 0; for( int y = 0; y < flowImage.height; y++ ) { for( int x = 0; x < flowImage.width; x++ ) { ImageFlow.D f = flowImage.unsafe_get(x,y); if( !f.isValid() ) { out.setRGB(x,y,0xFF); } else { float m = Math.max(Math.abs(f.x),Math.abs(f.y)); if( m > max ) max = m; magnitude.unsafe_set(x, y, m); } } } PixelMath.multiply(magnitude, 255 / max, magnitude); ConvertBufferedImage.convertTo(magnitude,out); }
public static void magnitudeAbs(ImageFlow flowImage, BufferedImage out) { GrayF32 magnitude = new GrayF32(flowImage.width,flowImage.height); float max = 0; for( int y = 0; y < flowImage.height; y++ ) { for( int x = 0; x < flowImage.width; x++ ) { ImageFlow.D f = flowImage.unsafe_get(x,y); if( !f.isValid() ) { out.setRGB(x,y,0xFF); } else { float m = Math.max(Math.abs(f.x),Math.abs(f.y)); if( m > max ) max = m; magnitude.unsafe_set(x, y, m); } } } PixelMath.multiply(magnitude, 255 / max, magnitude); ConvertBufferedImage.convertTo(magnitude,out); }
public static void magnitudeAbs(ImageFlow flowImage, float maxValue, BufferedImage out) { GrayF32 magnitude = new GrayF32(flowImage.width,flowImage.height); for( int y = 0; y < flowImage.height; y++ ) { for( int x = 0; x < flowImage.width; x++ ) { ImageFlow.D f = flowImage.unsafe_get(x,y); if( !f.isValid() ) { out.setRGB(x,y,0xFF); } else { float m = Math.max(Math.abs(f.x),Math.abs(f.y)); magnitude.unsafe_set(x, y, m); } } } PixelMath.multiply(magnitude, 255 / maxValue, magnitude); PixelMath.boundImage(magnitude,0,255); ConvertBufferedImage.convertTo(magnitude,out); }
protected static void borderDerivT(GrayF32 imageA , GrayF32 imageB , GrayF32 difference, int x, int y) { float d0 = getBorderT(imageA, imageB, x, y); float d1 = getBorderT(imageA, imageB, x+1, y); float d2 = getBorderT(imageA, imageB, x, y+1); float d3 = getBorderT(imageA, imageB, x+1, y + 1); difference.unsafe_set(x,y, 0.25f*(d0+d1+d2+d3)); }
for (int x = 0; x < mask.width; x++) { if( mask.unsafe_get(x,y) == 0 ) { normalizedTemplate.unsafe_set(x,y,0); if( xx < 0 ) xx = enlargedTemplate.width+xx; enlargedTemplate.unsafe_set(xx,yy, normalizedTemplate.unsafe_get(x,y));