Search in sources :

Example 46 with ByteProcessor

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);
}
Also used : ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) ColorProcessor(ij.process.ColorProcessor) ShortProcessor(ij.process.ShortProcessor)

Example 47 with ByteProcessor

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);
}
Also used : ByteProcessor(ij.process.ByteProcessor) FloatProcessor(ij.process.FloatProcessor) ImagePlus(ij.ImagePlus)

Example 48 with ByteProcessor

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;
}
Also used : ByteProcessor(ij.process.ByteProcessor) ColorProcessor(ij.process.ColorProcessor) FloatProcessor(ij.process.FloatProcessor) ShortProcessor(ij.process.ShortProcessor)

Example 49 with ByteProcessor

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);
}
Also used : ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) Test(org.junit.Test)

Example 50 with ByteProcessor

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);
}
Also used : ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) Test(org.junit.Test)

Aggregations

ByteProcessor (ij.process.ByteProcessor)103 ImagePlus (ij.ImagePlus)36 ImageProcessor (ij.process.ImageProcessor)31 FloatProcessor (ij.process.FloatProcessor)23 ShortProcessor (ij.process.ShortProcessor)21 ColorProcessor (ij.process.ColorProcessor)20 ArrayList (java.util.ArrayList)13 Point (java.awt.Point)12 Rectangle (java.awt.Rectangle)11 Roi (ij.gui.Roi)10 AffineTransform (java.awt.geom.AffineTransform)10 ImageStack (ij.ImageStack)9 Patch (ini.trakem2.display.Patch)9 Calibration (ij.measure.Calibration)8 Pair (mpicbg.trakem2.util.Pair)7 Color (java.awt.Color)6 LUT (ij.process.LUT)5 BufferedImage (java.awt.image.BufferedImage)5 IOException (java.io.IOException)5 CoordinateTransformMesh (mpicbg.models.CoordinateTransformMesh)5