use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.
the class ImageGraphics method copyImageToProcessor.
/**
* Copies the contents of the {@link BufferedImage} to the specified
* {@link ImageProcessor}. The size and type of the BufferedImage
* is assumed to match the ImageProcessor.
*
* @param bi the local (intermediate) {@link BufferedImage} instance
* @param ip the original {@link ImageProcessor}
*/
private void copyImageToProcessor(BufferedImage bi, ImageProcessor ip) {
ImageProcessor ip2 = null;
if (ip instanceof ByteProcessor) {
ip2 = new ByteProcessor(bi);
} else if (ip instanceof ShortProcessor) {
ip2 = new ShortProcessor(bi);
} else if (ip instanceof ColorProcessor) {
ip2 = new ColorProcessor(bi);
} else {
throw new IllegalArgumentException("Cannot create BufferedImage from " + ip.getClass().getName());
}
ip.copyBits(ip2, 0, 0, Blitter.COPY);
}
use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.
the class Utils method showMask.
public static void showMask(CircularMask mask, String title) {
ByteProcessor bp = new FloatProcessor(mask.getMask()).convertToByteProcessor(false);
bp.threshold(0);
ImagePlus im = new ImagePlus(title, bp);
im.show();
GuiTools.zoomExact(im, 32);
}
use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.
the class ImageTests method match.
public static boolean match(ImageProcessor ip1, ImageProcessor ip2, double tolerance) {
assertTrue("images are of different type", IjUtils.sameType(ip1, ip2));
assertTrue("images are of different size", IjUtils.sameSize(ip1, ip2));
int width = ip1.getWidth();
int height = ip1.getHeight();
if (ip1 instanceof ColorProcessor) {
ColorProcessor cp1 = (ColorProcessor) ip1;
ColorProcessor cp2 = (ColorProcessor) ip2;
int[] rgb1 = new int[3];
int[] rgb2 = new int[3];
for (int v = 0; v < height; v++) {
for (int u = 0; u < width; u++) {
cp1.getPixel(u, v, rgb1);
cp2.getPixel(u, v, rgb2);
for (int k = 0; k < 3; k++) {
int c1 = rgb1[k];
int c2 = rgb2[k];
if (Math.abs(c1 - c2) > tolerance) {
fail(msgRgb(u, v, rgb1, rgb2));
}
}
}
}
} else if (ip1 instanceof ByteProcessor || ip1 instanceof ShortProcessor || ip1 instanceof FloatProcessor) {
final float toleranceF = (float) tolerance;
for (int v = 0; v < height; v++) {
for (int u = 0; u < width; u++) {
float v1 = ip1.getf(u, v);
float v2 = ip2.getf(u, v);
if (Math.abs(v1 - v2) > toleranceF) {
fail(msgFloat(u, v, v1, v2));
}
}
}
} else {
throw new IllegalArgumentException("unknown processor type " + ip1.getClass().getSimpleName());
}
return true;
}
use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.
the class DistanceTransformTest method testL1.
@Test
public void testL1() {
ImageProcessor ip = new ByteProcessor(W, H, pixels);
DistanceTransform dt = new DistanceTransform(ip, Norm.L1);
float[][] dmap = dt.getDistanceMap();
ArrayTests.assertArrayEquals(distL1, dmap, 1e-6);
}
use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.
the class DistanceTransformTest method testL2.
@Test
public void testL2() {
ImageProcessor ip = new ByteProcessor(W, H, pixels);
DistanceTransform dt = new DistanceTransform(ip, Norm.L2);
float[][] dmap = dt.getDistanceMap();
ArrayTests.assertArrayEquals(distL2, dmap, 1e-3);
}
Aggregations