Search in sources :

Example 91 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestKernelMath method convertToImage_I32.

@Test
public void convertToImage_I32() {
    Kernel2D_S32 kernel = FactoryKernel.random2D_I32(7, 3, -10, 10, rand);
    GrayS32 image = KernelMath.convertToImage(kernel);
    assertEquals(kernel.width, image.width);
    assertEquals(kernel.width, image.height);
    for (int i = 0; i < kernel.width; i++) {
        for (int j = 0; j < kernel.width; j++) {
            assertEquals(kernel.get(j, i), image.get(j, i));
        }
    }
}
Also used : GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 92 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class ExampleBinaryOps method main.

public static void main(String[] args) {
    // load and convert the image into a usable format
    BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("particles01.jpg"));
    // convert into a usable format
    GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
    GrayU8 binary = new GrayU8(input.width, input.height);
    GrayS32 label = new GrayS32(input.width, input.height);
    // Select a global threshold using Otsu's method.
    double threshold = GThresholdImageOps.computeOtsu(input, 0, 255);
    // Apply the threshold to create a binary image
    ThresholdImageOps.threshold(input, binary, (float) threshold, true);
    // remove small blobs through erosion and dilation
    // The null in the input indicates that it should internally declare the work image it needs
    // this is less efficient, but easier to code.
    GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null);
    filtered = BinaryImageOps.dilate8(filtered, 1, null);
    // Detect blobs inside the image using an 8-connect rule
    List<Contour> contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, label);
    // colors of contours
    int colorExternal = 0xFFFFFF;
    int colorInternal = 0xFF2020;
    // display the results
    BufferedImage visualBinary = VisualizeBinaryData.renderBinary(binary, false, null);
    BufferedImage visualFiltered = VisualizeBinaryData.renderBinary(filtered, false, null);
    BufferedImage visualLabel = VisualizeBinaryData.renderLabeledBG(label, contours.size(), null);
    BufferedImage visualContour = VisualizeBinaryData.renderContours(contours, colorExternal, colorInternal, input.width, input.height, null);
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(visualBinary, "Binary Original");
    panel.addImage(visualFiltered, "Binary Filtered");
    panel.addImage(visualLabel, "Labeled Blobs");
    panel.addImage(visualContour, "Contours");
    ShowImages.showWindow(panel, "Binary Operations", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) Contour(boofcv.alg.filter.binary.Contour) GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 93 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class SegmentMeanShift method process.

/**
 * Performs mean-shift segmentation on the input image.   The
 * total number of regions can be found by calling {@link #getNumberOfRegions()}.
 *
 * @param image Image
 * @param output Storage for output image.  Each pixel is set to the region it belongs to.
 */
public void process(T image, GrayS32 output) {
    InputSanityCheck.checkSameShape(image, output);
    // long time0 = System.currentTimeMillis();
    search.process(image);
    // long time1 = System.currentTimeMillis();
    FastQueue<float[]> regionColor = search.getModeColor();
    GrayS32 pixelToRegion = search.getPixelToRegion();
    GrowQueue_I32 regionPixelCount = search.getRegionMemberCount();
    FastQueue<Point2D_I32> modeLocation = search.getModeLocation();
    merge.process(pixelToRegion, regionPixelCount, regionColor, modeLocation);
    // long time2 = System.currentTimeMillis();
    segment.process(pixelToRegion, output, regionPixelCount);
    if (prune != null)
        prune.process(image, output, regionPixelCount, regionColor);
// long time4 = System.currentTimeMillis();
// System.out.println("Search: "+(time1-time0)+" Merge: "+(time2-time1)+
// " segment: "+(time3-time2)+" Prune: "+(time4-time3));
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 94 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class BinaryImageOps method contour.

/**
 * <p>
 * Given a binary image, connect together pixels to form blobs/clusters using the specified connectivity rule.
 * The found blobs will be labeled in an output image and also described as a set of contours.  Pixels
 * in the contours are consecutive order in a clockwise or counter-clockwise direction, depending on the
 * implementation.  The labeled image will assign background pixels a label of 0 and each blob will be
 * assigned a unique ID starting from 1.
 * </p>
 *
 * <p>
 * The returned contours are traces of the object.  The trace of an object can be found by marking a point
 * with a pen and then marking every point on the contour without removing the pen.  It is possible to have
 * the same point multiple times in the contour.
 * </p>
 *
 * @see LinearContourLabelChang2004
 *
 * @param input Input binary image.  Not modified.
 * @param rule Connectivity rule.  Can be 4 or 8.  8 is more commonly used.
 * @param output (Optional) Output labeled image. If null, an image will be declared internally.  Modified.
 * @return List of found contours for each blob.
 */
public static List<Contour> contour(GrayU8 input, ConnectRule rule, GrayS32 output) {
    if (output == null) {
        output = new GrayS32(input.width, input.height);
    } else {
        InputSanityCheck.checkSameShape(input, output);
    }
    BinaryContourFinder alg = FactoryBinaryContourFinder.linearChang2004();
    alg.setConnectRule(rule);
    alg.process(input, output);
    return convertContours(alg);
}
Also used : FactoryBinaryContourFinder(boofcv.factory.filter.binary.FactoryBinaryContourFinder) BinaryContourFinder(boofcv.abst.filter.binary.BinaryContourFinder) GrayS32(boofcv.struct.image.GrayS32)

Example 95 with GrayS32

use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.

the class TestBinaryImageOps method labelToBinary_array_boolean.

@Test
public void labelToBinary_array_boolean() {
    GrayU8 expected = new GrayU8(13, 8);
    expected.data = TEST;
    GrayU8 found = new GrayU8(13, 8);
    GrayS32 input = new GrayS32(13, 8);
    input.data = EXPECTED8;
    boolean[] selected = new boolean[] { false, false, true };
    BinaryImageOps.labelToBinary(input, found, selected);
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 13; j++) {
            if (input.get(j, i) == 2) {
                assertEquals(1, found.get(j, i));
            } else {
                assertEquals(0, found.get(j, i));
            }
        }
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Aggregations

GrayS32 (boofcv.struct.image.GrayS32)102 Test (org.junit.Test)79 GrayU8 (boofcv.struct.image.GrayU8)52 GrayF32 (boofcv.struct.image.GrayF32)13 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)10 Point2D_I32 (georegression.struct.point.Point2D_I32)7 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)4 GImageGray (boofcv.core.image.GImageGray)4 ImageGray (boofcv.struct.image.ImageGray)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 ImageDimension (boofcv.struct.image.ImageDimension)3 BufferedImage (java.awt.image.BufferedImage)3 FastQueue (org.ddogleg.struct.FastQueue)3 WatershedVincentSoille1991 (boofcv.alg.segmentation.watershed.WatershedVincentSoille1991)2 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)2 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 ImageRectangle (boofcv.struct.ImageRectangle)2 PackedSetsPoint2D_I32 (boofcv.struct.PackedSetsPoint2D_I32)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2