@Override public void setColor(float[] color, int x, int y) { color[0] = input.unsafe_get(x,y); }
@Override public double unsafe_getD(int x, int y) { return image.unsafe_get(x,y); }
protected static float getBorderT(GrayU8 imageA, GrayU8 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); }
@Override public float unsafe_getF(int x, int y) { return image.unsafe_get(x,y); }
@Override protected void computeBlockStatistics(int x0 , int y0 , int width , int height , int indexMinMax , GrayU8 input) { int 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++) { int value = input.data[indexInput++] & 0xFF; if( value < min ) min = value; else if( value > max ) max = value; } } stats.data[indexMinMax] = (byte)min; stats.data[indexMinMax+1] = (byte)max; } }
@Override protected void computeDerivX(GrayU8 image1, GrayU8 image2, GrayS16 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++ ) { int d0 = (image1.data[index1+1]&0xFF) - (image1.data[index1]&0xFF); int d2 = (image2.data[index2+1]&0xFF) - (image2.data[index2]&0xFF); int d1 = (image1.data[index1+1+image1.stride]&0xFF) - (image1.data[index1+image1.stride]&0xFF); int d3 = (image2.data[index2+1+image2.stride]&0xFF) - (image2.data[index2+image2.stride]&0xFF); derivX.data[indexX] = (short)((d0 + d1 + d2 + d3)/4); } } for( int y = 0; y < image1.height; y++ ) { derivX.unsafe_set(w,y, 0); } for( int x = 0; x < w; x++ ) { int d0 = image1.unsafe_get(x+1,h) - image1.unsafe_get(x,h); int d1 = image2.unsafe_get(x+1,h) - image2.unsafe_get(x,h); derivX.unsafe_set(x,h, (d0+d1)/2); } }
@Override protected void computeDerivY(GrayU8 image1, GrayU8 image2, GrayS16 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++ ) { int d0 = (image1.data[index1+image1.stride]&0xFF) - (image1.data[index1]&0xFF); int d2 = (image2.data[index2+image2.stride]&0xFF) - (image2.data[index2]&0xFF); int d1 = (image1.data[index1+1+image1.stride]&0xFF) - (image1.data[index1+1]&0xFF); int d3 = (image2.data[index2+1+image2.stride]&0xFF) - (image2.data[index2+1]&0xFF); derivY.data[indexY] = (short)((d0 + d1 + d2 + d3)/4); } } for( int y = 0; y < h; y++ ) { int d0 = image1.unsafe_get(w, y + 1) - image1.unsafe_get(w,y); int d1 = image2.unsafe_get(w, y + 1) - image2.unsafe_get(w,y); derivY.unsafe_set(w,y, (d0+d1)/2); } for( int x = 0; x < w; x++ ) { derivY.unsafe_set(x, h, 0); } }
public static void printDiffBinary(GrayU8 imgA, GrayU8 imgB) { System.out.println("------- Difference -----------"); for (int y = 0; y < imgA.getHeight(); y++) { for (int x = 0; x < imgA.getWidth(); x++) { if( imgA.unsafe_get(x,y) != imgB.unsafe_get(x,y)) System.out.print(" x"); else System.out.print(" ."); } System.out.println(); } } }
private void saveImage(GrayU8 image, int id ) { try { File directory = owner.getApplicationContext().getDir(DIRECTORY_NAME,Context.MODE_PRIVATE); PrintStream out = new PrintStream(new File(directory,id+"")); char column[] = new char[image.width]; out.println(image.width+" "+image.height); for (int y = 0; y < image.height; y++) { for (int x = 0; x < image.width; x++) { column[x] = (char) image.unsafe_get(x,y); } out.print(column); out.println(); } out.close(); } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
mean += stats.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); } }
/** * Draws border pixels of each region using the specified color. * * @param pixelToRegion Conversion from pixel to region * @param borderColor RGB value of border pixel * @param output Storage for output image. Can be null. * @return Output image. */ public static BufferedImage regionBorders( GrayS32 pixelToRegion , int borderColor , BufferedImage output ) { if( output == null ) output = new BufferedImage(pixelToRegion.width,pixelToRegion.height,BufferedImage.TYPE_INT_RGB); GrayU8 binary = new GrayU8(pixelToRegion.width,pixelToRegion.height); ImageSegmentationOps.markRegionBorders(pixelToRegion, binary); for( int y = 0; y < binary.height; y++ ) { for( int x = 0; x < binary.width; x++ ) { if( binary.unsafe_get(x,y) == 1 ) { output.setRGB(x,y,borderColor); } } } return output; } }
/** * Draws border pixels of each region using the specified color. * * @param pixelToRegion Conversion from pixel to region * @param borderColor RGB value of border pixel * @param output Storage for output image. Can be null. * @return Output image. */ public static BufferedImage regionBorders( GrayS32 pixelToRegion , int borderColor , BufferedImage output ) { if( output == null ) output = new BufferedImage(pixelToRegion.width,pixelToRegion.height,BufferedImage.TYPE_INT_RGB); GrayU8 binary = new GrayU8(pixelToRegion.width,pixelToRegion.height); ImageSegmentationOps.markRegionBorders(pixelToRegion, binary); for( int y = 0; y < binary.height; y++ ) { for( int x = 0; x < binary.width; x++ ) { if( binary.unsafe_get(x,y) == 1 ) { output.setRGB(x,y,borderColor); } } } return output; } }
int inputValue = input.unsafe_get(radius, y); int sum = 0; for( int i = 0; i <= inputValue; i++ ) {
/** * Draws border pixels of each region using the specified color. * * @param pixelToRegion Conversion from pixel to region * @param borderColor RGB value of border pixel * @param output Where the output is written to * @param storage Optional working buffer for Bitmap image. Can be null. */ public static void regionBorders( GrayS32 pixelToRegion , int borderColor , Bitmap output , byte[] storage) { if( storage == null ) storage = declareStorage(output,null); GrayU8 binary = new GrayU8(pixelToRegion.width,pixelToRegion.height); ImageSegmentationOps.markRegionBorders(pixelToRegion, binary); int indexOut = 0; for( int y = 0; y < binary.height; y++ ) { for( int x = 0; x < binary.width; x++ ) { if( binary.unsafe_get(x,y) != 0 ) { storage[indexOut++] = (byte)(borderColor & 0xFF); storage[indexOut++] = (byte)((borderColor >> 8) & 0xFF); storage[indexOut++] = (byte)((borderColor >> 16) & 0xFF); storage[indexOut++] = (byte)0xFF; } else { indexOut += 4; } } } output.copyPixelsFromBuffer(ByteBuffer.wrap(storage)); }
/** * Draws border pixels of each region using the specified color. * * @param pixelToRegion Conversion from pixel to region * @param borderColor RGB value of border pixel * @param output Where the output is written to * @param storage Optional working buffer for Bitmap image. Can be null. */ public static void regionBorders( GrayS32 pixelToRegion , int borderColor , Bitmap output , byte[] storage) { if( storage == null ) storage = declareStorage(output,null); GrayU8 binary = new GrayU8(pixelToRegion.width,pixelToRegion.height); ImageSegmentationOps.markRegionBorders(pixelToRegion, binary); int indexOut = 0; for( int y = 0; y < binary.height; y++ ) { for( int x = 0; x < binary.width; x++ ) { if( binary.unsafe_get(x,y) == 1 ) { storage[indexOut++] = (byte)(borderColor & 0xFF); storage[indexOut++] = (byte)((borderColor >> 8) & 0xFF); storage[indexOut++] = (byte)((borderColor >> 16) & 0xFF); storage[indexOut++] = (byte)0xFF; } else { indexOut += 4; } } } output.copyPixelsFromBuffer(ByteBuffer.wrap(storage)); }
continue; if( camMask.unsafe_get(camX,camY) == 1 ) { p2s.compute(p2.x,p2.y,p3b);
continue; if( camMask.unsafe_get(camX,camY) == 1 ) { p2s.compute(p2.x,p2.y,p3b);