@@ -0,0 +1,1799 @@
+package imj3.draft;%0A%0Aimport static imj3.tools.IMJTools.read;%0Aimport static multij.tools.Tools.debugPrint;%0A%0Aimport java.util.Map;%0Aimport java.util.TreeMap;%0Aimport java.util.concurrent.atomic.AtomicLong;%0A%0Aimport imj3.core.Image2D;%0Aimport imj3.core.Image2D.Pixel2DProcessor;%0A%0Aimport multij.tools.CommandLineArgumentsParser;%0Aimport multij.tools.IllegalInstantiationException;%0A%0A/**%0A * @author codistmonk (creation 2015-12-29)%0A */%0Apublic final class CountComponents %7B%0A%09%0A%09private CountComponents() %7B%0A%09%09throw new IllegalInstantiationException();%0A%09%7D%0A%09%0A%09/**%0A%09 * @param commandLineArguments%0A%09 * %3Cbr%3EMust not be null%0A%09 */%0A%09public static final void main(final String... commandLineArguments) %7B%0A%09%09final CommandLineArgumentsParser arguments = new CommandLineArgumentsParser(commandLineArguments);%0A%09%09final String imagePath = arguments.get(%22file%22, %22%22);%0A%09%09final boolean buildHistogram = arguments.get(%22histogram%22, 0)%5B0%5D != 0;%0A%09%09final long%5B%5D count = %7B 0L %7D;%0A%09%09final Map%3CLong, AtomicLong%3E histogram = new TreeMap%3C%3E();%0A%09%09final Image2D image = read(imagePath);%0A%09%09%0A%09%09ExtractComponents.forEachPixelInEachComponent4(image, new Pixel2DProcessor() %7B%0A%09%09%09%0A%09%09%09private Long pixelValue;%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public final boolean pixel(final int x, final int y) %7B%0A%09%09%09%09if (buildHistogram && this.pixelValue == null) %7B%0A%09%09%09%09%09this.pixelValue = image.getPixelValue(x, y);%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09return true;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public final void endOfPatch() %7B%0A%09%09%09%09++count%5B0%5D;%0A%09%09%09%09%0A%09%09%09%09if (buildHistogram) %7B%0A%09%09%09%09%09histogram.computeIfAbsent(this.pixelValue, v -%3E new AtomicLong()).incrementAndGet();%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09this.pixelValue = null;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09private static final long serialVersionUID = 2045154224638453864L;%0A%09%09%09%0A%09%09%7D);%0A%09%09%0A%09%09debugPrint(%22count:%22, count%5B0%5D);%0A%09%09%0A%09%09if (buildHistogram) %7B%0A%09%09%09debugPrint(%22histogram:%22, histogram);%0A%09%09%7D%0A%09%7D%0A%09%0A%7D%0A

Add tool CountComponents.