/** Returns a copy of the pixel data as a 2D int array with dimensions [x=0..width-1][y=0..height-1]. With RGB images, the returned values are in packed ARGB format. With float images, the returned values must be converted to float using Float.intBitsToFloat(). */ public int[][] getIntArray() { int[][] a = new int [width][height]; for(int y=0; y<height; y++) { for(int x=0; x<width; x++) a[x][y]=get(x,y); } return a; }
final static private void processGray(final ImageProcessor ip, final int value, final int min, final int max) { final int scale = max - min + 1; final Random rnd = new Random(); final int n = ip.getWidth() * ip.getHeight(); for (int i =0; i < n; ++i) { final int v = ip.get(i); if (v == value) ip.set(i, rnd.nextInt(scale) + min); } }
/** * Default settings are 4 connectivity, 16 bits image. */ @Test public void testFloodFillComponentsLabeling_Default() { ByteProcessor image = createFiveSquaresImage(); FloodFillComponentsLabeling algo = new FloodFillComponentsLabeling(); ImageProcessor result = algo.computeLabels(image); assertEquals(16, result.getBitDepth()); assertEquals(5, result.get(7, 7)); }
@Test public void testClosing_5x5_Square4x4() { ImageProcessor image = createImage_Square4x4(); Strel strel = new DiamondStrel(5); ImageProcessor result = strel.closing(image); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { assertEquals(image.get(x, y), result.get(x, y)); } } }
@Override public int get(int x, int y) { record("get", new Object[] {new Integer(x), new Integer(y)}, new Class[] {int.class, int.class}); return proc.get(x, y); }
/** * Using 8 connectivity should result in one connected component. */ @Test public void testFloodFillComponentsLabeling_C8_Short() { ByteProcessor image = createFiveSquaresImage(); FloodFillComponentsLabeling algo = new FloodFillComponentsLabeling(8, 16); ImageProcessor result = algo.computeLabels(image); assertEquals(16, result.getBitDepth()); assertEquals(1, result.get(7, 7)); }
@Test public void testClosing_3x3() { ImageProcessor image = createImage_Square10x10(); Strel strel = new OctagonStrel(3); ImageProcessor result = strel.closing(image); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { assertEquals(image.get(x, y), result.get(x, y)); } } }
@Override public int get(int index) { record("get", new Integer(index), int.class); return proc.get(index); }
@Test public void testClosing() { ImageProcessor image = createImage_Square10x10(); Strel strel = new SquareStrel(5); ImageProcessor result = strel.closing(image); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { assertEquals(image.get(x, y), result.get(x, y)); } } }
@Override public int get(int index) { record("get", new Integer(index), int.class); return proc.get(index); }
@Test public void testOpening() { ImageProcessor image = createImage_Square10x10(); Strel strel = new SquareStrel(5); ImageProcessor result = strel.opening(image); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { assertEquals(image.get(x, y), result.get(x, y)); } } }
@Override public int get(int x, int y) { record("get", new Object[] {new Integer(x), new Integer(y)}, new Class[] {int.class, int.class}); return proc.get(x, y); }
@Test public void testClosing() { ImageProcessor image = createImage_Square10x10(); Strel strel = new LinearVerticalStrel(5); ImageProcessor result = strel.closing(image); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { assertEquals(image.get(x, y), result.get(x, y)); } } }
@Override public double getDiff(int x, int y) { int c = ip.get(x, y); decompose(c); r -= r2; g -= g2; b -= b2; double x1 = x - x2; double y1 = y - y2; return super.getDiff(x, y) + r * r + g * g + b * b; }
@Test public final void testDistanceMapImageProcessor() { ImageProcessor image = createBinarySquareImage(); ImageProcessor result = BinaryImages.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(3, result.get(4, 4), 1e-12); }
@Override public void add(int x, int y) { int c = ip.get(x, y); decompose(c); r2 += r; g2 += g; b2 += b; super.add(x, y); }
@Test public final void testDistanceMapImageProcessorShortArrayBoolean() { ImageProcessor image = createBinarySquareImage(); short[] weights = new short[]{3, 4}; ImageProcessor result = BinaryImages.distanceMap(image, weights, true); assertNotNull(result); assertTrue(result instanceof ShortProcessor); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(3, result.get(4, 4), 1e-12); }
public static void threshold(Roi roi, int min, int max, ImageProcessor imageData, ImageProcessor labelData, int label) { mem = new Mem(labelData); Rectangle bounds = roi.getBounds(); for (int x = bounds.x; x <= bounds.x + bounds.width; x++) { for (int y = bounds.y; y <= bounds.y + bounds.height; y++) { if (roi.contains(x,y) && imageData.get(x, y) >= min && imageData.get(x, y) <= max) { mem.rememberPixel(x,y); labelData.set(x, y, label); } } } }
@Test public void testErosion_Square4x4() { ImageProcessor image = createImage_Square4x4(); Strel strel = new LinearHorizontalStrel(3); ImageProcessor result = strel.erosion(image); for (int y = 3; y < 7; y++) { assertEquals(0, result.get(3, y)); assertEquals(255, result.get(4, y)); assertEquals(255, result.get(5, y)); assertEquals(0, result.get(6, y)); } }
@Test public void testDilation_Square4x4() { ImageProcessor image = createImage_Square4x4(); Strel strel = new LinearVerticalStrel(3); ImageProcessor result = strel.dilation(image); for (int x = 3; x < 7; x++) { assertEquals(0, result.get(x, 1)); assertEquals(255, result.get(x, 2)); assertEquals(255, result.get(x, 7)); assertEquals(0, result.get(x, 8)); } }