use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class VisualizeWatershedApp method main.
public static void main(String[] args) {
BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("segment/berkeley_horses.jpg"));
GrayU8 gray = new GrayU8(image.getWidth(), image.getHeight());
ConvertBufferedImage.convertFrom(image, gray);
WatershedVincentSoille1991 alg = FactorySegmentationAlg.watershed(ConnectRule.FOUR);
alg.process(gray);
GrayS32 pixelToRegion = alg.getOutput();
VisualizeRegions.watersheds(pixelToRegion, image, 0);
alg.removeWatersheds();
int numRegions = alg.getTotalRegions();
BufferedImage outRegions = VisualizeRegions.regions(pixelToRegion, numRegions, null);
ShowImages.showWindow(image, "Watershed");
ShowImages.showWindow(outRegions, "Regions");
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestClusterLabeledImage method uniform.
/**
* Uniform image given different values. Should produce an output image of all zeros.
*/
@Test
public void uniform() {
GrayS32 input = new GrayS32(5, 7);
GrayS32 output = new GrayS32(5, 7);
for (int value = 0; value < 3; value++) {
GImageMiscOps.fill(input, value);
for (int i = 0; i < rules.length; i++) {
GImageMiscOps.fillUniform(output, rand, 0, 1000);
ClusterLabeledImage alg = new ClusterLabeledImage(rules[i]);
alg.process(input, output, counts);
assertEquals(1, counts.size);
assertEquals(5 * 7, counts.get(0));
for (int index = 0; index < output.data.length; index++) assertEquals(0, output.data[index]);
}
}
}
use of boofcv.struct.image.GrayS32 in project BoofCV by lessthanoptimal.
the class TestClusterLabeledImage method case0_connect8.
@Test
public void case0_connect8() {
GrayS32 input = new GrayS32(5, 5);
input.data = case0;
int[] expected = case0;
GrayS32 output = new GrayS32(5, 5);
ClusterLabeledImage alg = new ClusterLabeledImage(ConnectRule.EIGHT);
alg.process(input, output, counts);
int[] convert = new int[3];
convert[0] = output.get(0, 0);
convert[1] = output.get(0, 2);
convert[2] = output.get(1, 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 TestClusterLabeledImage method sameColorIslands.
/**
* Same color used on separate islands. Each island should have its own color on output
*/
@Test
public void sameColorIslands() {
GrayS32 input = new GrayS32(5, 5);
input.data = new int[] { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1 };
int[] expected = new int[] { 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2 };
for (int i = 0; i < rules.length; i++) {
GrayS32 output = new GrayS32(5, 5);
ClusterLabeledImage alg = new ClusterLabeledImage(rules[i]);
alg.process(input, output, counts);
int[] convert = new int[3];
convert[0] = output.get(0, 0);
convert[1] = output.get(2, 0);
convert[2] = output.get(2, 4);
assertEquals(3, counts.size);
assertEquals(4, counts.get(convert[0]));
assertEquals(15, counts.get(convert[1]));
assertEquals(6, counts.get(convert[2]));
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 TestMergeRegionMeanShift method basicAll.
@Test
public void basicAll() {
MergeRegionMeanShift alg = new MergeRegionMeanShift(1, 1);
GrayS32 pixelToRegion = new GrayS32(4, 4);
pixelToRegion.data = new int[] { 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 1, 0, 0, 3, 1 };
GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
regionMemberCount.data = new int[] { 1, 2, 3, 4 };
regionMemberCount.size = 4;
FastQueue<float[]> regionColor = createList(5, 1, 6, 4);
FastQueue<Point2D_I32> modeLocation = new FastQueue<>(Point2D_I32.class, true);
modeLocation.grow().set(0, 0);
modeLocation.grow().set(3, 3);
modeLocation.grow().set(0, 1);
modeLocation.grow().set(2, 3);
alg.process(pixelToRegion, regionMemberCount, regionColor, modeLocation);
GrayS32 expectedP2R = new GrayS32(4, 4);
expectedP2R.data = new int[] { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1 };
int[] expectedCount = new int[] { 4, 2, 4 };
for (int i = 0; i < expectedP2R.data.length; i++) assertEquals(expectedP2R.data[i], pixelToRegion.data[i]);
for (int i = 0; i < expectedCount.length; i++) assertEquals(expectedCount[i], regionMemberCount.data[i]);
}
Aggregations