/** * Set pixel value at provided location * * @param x abscissa * @param y ordinate * @param val pixel value to set */ public void setPixel (int x, int y, int val) { buf.set(x, y, val); }
/** * Creates a new binary image of a square. * @return */ private final ImageProcessor createBinarySquareImage() { ByteProcessor image = new ByteProcessor(10, 10); image.setBackgroundValue(0); image.fill(); for (int y = 2; y < 8; y++) { for (int x = 2; x < 8; x++) { image.set(x, y, 255); } } return image; } }
@Test public final void testDistanceMap_UntilCorners_Chessboard() { ByteProcessor image = new ByteProcessor(7, 7); image.setValue(255); image.fill(); image.set(4, 4, 0); short[] weights = ChamferWeights.CHESSBOARD.getShortWeights(); DistanceTransform3x3Short algo = new DistanceTransform3x3Short(weights, false); ImageProcessor result = algo.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(4, result.get(0, 0)); assertEquals(4, result.get(6, 0)); assertEquals(4, result.get(0, 6)); assertEquals(2, result.get(6, 6)); }
@Test public final void testDistanceMap_UntilCorners_Borgefors34() { ByteProcessor image = new ByteProcessor(7, 7); image.setValue(255); image.fill(); image.set(4, 4, 0); short[] weights = ChamferWeights.BORGEFORS.getShortWeights(); DistanceTransform3x3Short algo = new DistanceTransform3x3Short(weights, false); ImageProcessor result = algo.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(16, result.get(0, 0)); assertEquals(14, result.get(6, 0)); assertEquals(14, result.get(0, 6)); assertEquals(8, result.get(6, 6)); }
public void setf( final int i, final float value ) { ip.set( i, Math.max( 0, Math.min( 255, Util.roundPos( value ) ) ) ); } }
@Test public final void testDistanceMap_UntilCorners_Chessboard() { ByteProcessor image = new ByteProcessor(7, 7); image.setValue(255); image.fill(); image.set(4, 4, 0); float[] weights = ChamferWeights.CHESSBOARD.getFloatWeights(); DistanceTransform3x3Float algo = new DistanceTransform3x3Float(weights, false); ImageProcessor result = algo.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(4, result.getf(0, 0), .01); assertEquals(4, result.getf(6, 0), .01); assertEquals(4, result.getf(0, 6), .01); assertEquals(2, result.getf(6, 6), .01); }
private ByteProcessor createImage (String[] rows) { final int width = rows[0].length(); final int height = rows.length; final ByteProcessor img = new ByteProcessor(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { char c = rows[y].charAt(x); img.set(x, y, (c == 'X') ? 0 : 255); } } return img; }
@Test public final void testDistanceMap_UntilCorners_Weights23() { ByteProcessor image = new ByteProcessor(7, 7); image.setValue(255); image.fill(); image.set(4, 4, 0); short[] weights = ChamferWeights.WEIGHTS_23.getShortWeights(); DistanceTransform3x3Short algo = new DistanceTransform3x3Short(weights, false); ImageProcessor result = algo.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(12, result.get(0, 0)); assertEquals(10, result.get(6, 0)); assertEquals(10, result.get(0, 6)); assertEquals(6, result.get(6, 6)); }
private static ByteProcessor createBuffer (BufferedImage img) { DataBuffer dataBuffer = img.getData().getDataBuffer(); ByteProcessor buf = new ByteProcessor(img.getWidth(), img.getHeight()); for (int y = 0, h = img.getHeight(); y < h; y++) { for (int x = 0, w = img.getWidth(); x < w; x++) { int index = x + (y * w); int elem = dataBuffer.getElem(index); // ShapeSymbol instances use alpha channel as the pixel level // With 0 as totally transparent so background (255) // And with 255 as totally opaque so foreground (0) int val = 255 - (elem >>> 24); buf.set(x, y, val); } } // binarize buf.threshold(216); return buf; } }
@Test public final void testDistanceMap_UntilCorners_CityBlock() { ByteProcessor image = new ByteProcessor(7, 7); image.setValue(255); image.fill(); image.set(4, 4, 0); short[] weights = ChamferWeights.CITY_BLOCK.getShortWeights(); DistanceTransform3x3Short algo = new DistanceTransform3x3Short(weights, false); ImageProcessor result = algo.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(8, result.get(0, 0)); assertEquals(6, result.get(6, 0)); assertEquals(6, result.get(0, 6)); assertEquals(4, result.get(6, 6)); }
/** * Get the image with the classified mismatches * * @param wr warping results * @param mismatchesLabels labels of the warping mismatches * @return image with classified mismatches */ public ImagePlus getMismatchImage(WarpingResults wr,int[] mismatchesLabels, int flags) { ByteProcessor bp = new ByteProcessor( wr.warpedSource.getWidth(), wr.warpedSource.getHeight() ); for(int i=0; i < wr.mismatches.size(); i++) { Point3f p = wr.mismatches.get( i ); bp.set( (int)p.x, (int)p.y, mismatchesLabels[ i ] & flags ); } return new ImagePlus( "Mismatches", bp ); }
@Test public final void testDistanceMap_UntilCorners_Weights23() { ByteProcessor image = new ByteProcessor(7, 7); image.setValue(255); image.fill(); image.set(4, 4, 0); float[] weights = ChamferWeights.WEIGHTS_23.getFloatWeights(); DistanceTransform3x3Float algo = new DistanceTransform3x3Float(weights, false); ImageProcessor result = algo.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(12, result.getf(0, 0), .01); assertEquals(10, result.getf(6, 0), .01); assertEquals(10, result.getf(0, 6), .01); assertEquals(6, result.getf(6, 6), .01); }
/** * Get the image with the classified mismatches * * @param wr warping results * @param mismatchesLabels labels of the warping mismatches * @return image with classified mismatches */ public ImagePlus getMismatchImage(WarpingResults wr,int[] mismatchesLabels, int flags) { ByteProcessor bp = new ByteProcessor( wr.warpedSource.getWidth(), wr.warpedSource.getHeight() ); for(int i=0; i < wr.mismatches.size(); i++) { Point3f p = wr.mismatches.get( i ); bp.set( (int)p.x, (int)p.y, mismatchesLabels[ i ] & flags ); } return new ImagePlus( "Mismatches", bp ); }
@Test public final void testDistanceMap_UntilCorners_Borgefors34() { ByteProcessor image = new ByteProcessor(7, 7); image.setValue(255); image.fill(); image.set(4, 4, 0); float[] weights = ChamferWeights.BORGEFORS.getFloatWeights(); DistanceTransform3x3Float algo = new DistanceTransform3x3Float(weights, false); ImageProcessor result = algo.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(16, result.getf(0, 0), .01); assertEquals(14, result.getf(6, 0), .01); assertEquals(14, result.getf(0, 6), .01); assertEquals(8, result.getf(6, 6), .01); }
@Override public ByteProcessor filteredImage () { ByteProcessor ip = new ByteProcessor(source.getWidth(), source.getHeight()); for (int x = 0, w = ip.getWidth(); x < w; x++) { for (int y = 0, h = ip.getHeight(); y < h; y++) { if (isFore(x, y)) { ip.set(x, y, FOREGROUND); } else { ip.set(x, y, BACKGROUND); } } } return ip; }
@Override public ByteProcessor filteredImage () { ByteProcessor ip = new ByteProcessor(source.getWidth(), source.getHeight()); for (int y = 0, h = ip.getHeight(); y < h; y++) { for (int x = 0, w = ip.getWidth(); x < w; x++) { if (isFore(x, y)) { ip.set(x, y, FOREGROUND); } else { ip.set(x, y, BACKGROUND); } } } return ip; }
/** * Get the image with the classified mismatches * * @param wr warping results * @param radius radius in pixels to use while classifying pixels * @return image with classified mismatches */ public ImagePlus getMismatchImage(WarpingResults wr, int radius) { int[] mismatchesLabels = classifyMismatches2d( wr.warpedSource, wr.mismatches, radius ); ByteProcessor bp = new ByteProcessor( wr.warpedSource.getWidth(), wr.warpedSource.getHeight() ); for(int i=0; i < wr.mismatches.size(); i++) { Point3f p = wr.mismatches.get( i ); bp.set( (int)p.x, (int)p.y, mismatchesLabels[ i ] ); } return new ImagePlus( "Mismatches", bp ); }
/** * Get the image with the classified mismatches * * @param wr warping results * @param radius radius in pixels to use while classifying pixels * @return image with classified mismatches */ public ImagePlus getMismatchImage(WarpingResults wr, int radius, int flags) { int[] mismatchesLabels = classifyMismatches2d( wr.warpedSource, wr.mismatches, radius ); ByteProcessor bp = new ByteProcessor( wr.warpedSource.getWidth(), wr.warpedSource.getHeight() ); for(int i=0; i < wr.mismatches.size(); i++) { Point3f p = wr.mismatches.get( i ); bp.set( (int)p.x, (int)p.y, mismatchesLabels[ i ] & flags ); } return new ImagePlus( "Mismatches", bp ); }
/** * Get the image with the classified mismatches * * @param wr warping results * @param radius radius in pixels to use while classifying pixels * @return image with classified mismatches */ public ImagePlus getMismatchImage(WarpingResults wr, int radius) { int[] mismatchesLabels = classifyMismatches2d( wr.warpedSource, wr.mismatches, radius ); ByteProcessor bp = new ByteProcessor( wr.warpedSource.getWidth(), wr.warpedSource.getHeight() ); for(int i=0; i < wr.mismatches.size(); i++) { Point3f p = wr.mismatches.get( i ); bp.set( (int)p.x, (int)p.y, mismatchesLabels[ i ] ); } return new ImagePlus( "Mismatches", bp ); }
private void merge (ByteProcessor img, boolean[][] lines) { for (int y = 0, h = img.getHeight(); y < h; y++) { for (int x = 0, w = img.getWidth(); x < w; x++) { if (lines[x][y]) { img.set(x, y, PixelSource.BACKGROUND); } } } } }