use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class GenericBinaryContourFinder method maxContour.
@Test
public void maxContour() {
GrayU8 input = TEST3.clone();
GrayS32 labeled = input.createSameShape(GrayS32.class);
BinaryContourFinder alg = create();
alg.setMaxContour(1);
alg.process(input, labeled);
assertEquals(1, alg.getContours().size());
checkExternalSize(alg, 0, 0);
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestImplIntegralImageOps method block_unsafe.
public void block_unsafe(Method m) throws InvocationTargetException, IllegalAccessException {
Class[] paramType = m.getParameterTypes();
Class inputType = paramType[0];
Class origType = inputType == GrayS32.class ? GrayU8.class : inputType;
ImageGray input = GeneralizedImageOps.createSingleBand(origType, width, height);
ImageGray integral = GeneralizedImageOps.createSingleBand(inputType, width, height);
GImageMiscOps.fill(input, 1);
GIntegralImageOps.transform(input, integral);
double found0 = ((Number) m.invoke(null, integral, 4, 5, 8, 8)).doubleValue();
assertEquals(12, found0, 1e-4f);
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class ExampleWatershedWithSeeds method main.
public static void main(String[] args) {
BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("particles01.jpg"));
GrayU8 input = ConvertBufferedImage.convertFromSingle(image, null, GrayU8.class);
// declare working data
GrayU8 binary = new GrayU8(input.width, input.height);
GrayS32 label = new GrayS32(input.width, input.height);
// Try using the mean pixel value to create a binary image then erode it to separate the particles from
// each other
double mean = ImageStatistics.mean(input);
ThresholdImageOps.threshold(input, binary, (int) mean, true);
GrayU8 filtered = BinaryImageOps.erode8(binary, 2, null);
int numRegions = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, label).size() + 1;
// +1 to regions because contour only counts blobs and not the background
// The labeled image can be used as is. A precondition for seeded watershed is that all seeds have an
// ID > 0. Luckily, a value of 0 was used for background pixels in the contour algorithm.
WatershedVincentSoille1991 watershed = FactorySegmentationAlg.watershed(ConnectRule.FOUR);
watershed.process(input, label);
GrayS32 output = watershed.getOutput();
BufferedImage outLabeled = VisualizeBinaryData.renderLabeledBG(label, numRegions, null);
VisualizeRegions.watersheds(output, image, 1);
// Removing the watersheds and update the region count
// NOTE: watershed.getTotalRegions() does not return correct results if seeds are used!
watershed.removeWatersheds();
numRegions -= 1;
BufferedImage outRegions = VisualizeRegions.regions(output, numRegions, null);
ListDisplayPanel gui = new ListDisplayPanel();
gui.addImage(image, "Watersheds");
gui.addImage(outRegions, "Regions");
gui.addImage(outLabeled, "Seeds");
ShowImages.showWindow(gui, "Watershed", true);
// Additional processing would be needed for this example to be really useful.
// The watersheds can be used to characterize the background while the seed binary image the particles
// From this the particles could be more accurately classified by assigning each pixel one of the two
// just mentioned groups based distance
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestClusterLabeledImage method case0_connect4.
@Test
public void case0_connect4() {
GrayS32 input = new GrayS32(5, 5);
input.data = case0;
int[] expected = new int[] { 0, 0, 2, 3, 4, 0, 0, 0, 4, 4, 5, 6, 1, 8, 4, 5, 6, 1, 1, 7, 5, 5, 7, 7, 7 };
GrayS32 output = new GrayS32(5, 5);
ClusterLabeledImage alg = new ClusterLabeledImage(ConnectRule.FOUR);
alg.process(input, output, counts);
int[] convert = new int[9];
convert[0] = output.get(0, 0);
convert[1] = output.get(2, 2);
convert[2] = output.get(2, 0);
convert[3] = output.get(3, 0);
convert[4] = output.get(4, 0);
convert[5] = output.get(0, 2);
convert[6] = output.get(1, 2);
convert[7] = output.get(4, 3);
convert[8] = output.get(3, 2);
assertEquals(convert.length, counts.size);
int sum = 0;
for (int i = 0; i < counts.size; i++) sum += counts.get(i);
assertEquals(25, sum);
for (int j = 0; j < output.data.length; j++) {
assertEquals(convert[expected[j]], output.data[j]);
}
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestMergeSmallRegions method process.
/**
* Runs everything to remove the small patches. This test hsa been designed to take multiple
* passes to complete.
*/
@Test
public void process() {
GrayU8 image = new GrayU8(10, 9);
image.data = new byte[] { 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 7, 8, 0, 0, 0, 0, 0, 5, 6, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 7, 0, 0, 0, 5, 5, 4, 4, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 9, 9, 6, 7 };
GrayS32 pixelToRegion = new GrayS32(10, 9);
pixelToRegion.data = new int[] { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 4, 5, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 9, 0, 0, 0, 1, 1, 3, 3, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 6, 6, 7, 8 };
GrowQueue_I32 memberCount = new GrowQueue_I32();
memberCount.resize(10);
for (int i = 0; i < pixelToRegion.data.length; i++) {
memberCount.data[pixelToRegion.data[i]]++;
}
FastQueue<float[]> regionColor = new FastQueue<float[]>(float[].class, true) {
protected float[] createInstance() {
return new float[1];
}
};
regionColor.resize(10);
ComputeRegionMeanColor<GrayU8> mean = new ComputeRegionMeanColor.U8();
mean.process(image, pixelToRegion, memberCount, regionColor);
MergeSmallRegions<GrayU8> alg = new MergeSmallRegions<>(3, ConnectRule.FOUR, mean);
alg.process(image, pixelToRegion, memberCount, regionColor);
// check the results. Should only be three regions
assertEquals(3, memberCount.size);
assertEquals(3, regionColor.size);
GrowQueue_I32 memberExpected = new GrowQueue_I32(3);
memberExpected.resize(3);
for (int i = 0; i < pixelToRegion.data.length; i++) {
memberExpected.data[pixelToRegion.data[i]]++;
}
for (int i = 0; i < 3; i++) assertEquals(memberExpected.get(i), memberCount.get(i));
// simple sanity check
assertTrue(memberExpected.get(0) > memberExpected.get(1));
}
Aggregations