sclass FloodFillBWImage_v2 extends FloodFillBWImage { Matrix matrix = new ArrayMatrix; class Region { new PointSetBitMatrix points; Rect boundingBox; void add(Pt p) { points.set(p, true); boundingBox = rectUnionWithPt(boundingBox, p); } int size() { ret points.nSetBits(); } toString { ret "Region with " + nPixels(size()) + " within " + boundingBox; } } void visited(Pt p) { matrix.put(p, new Region); } *(IBWImage *img) { super(img); } bool isConnectable(Pt a, Pt b) { float brightnessA = img.getFloatPixel(a); float brightnessB = img.getFloatPixel(b); ret abs(brightnessA-brightnessB) <= tolerance; } }