sclass URecognizer { IIntegralImage image; *() {} *(IIntegralImage *image) {} *(BufferedImage image) { this.image = IntegralImage(image); } // returns 0, 1 or 2 int posterizeToInt(double x) { ret ifloor(clampZeroToOne(x)*3); } // returns 0, .5 or 1 double posterizeInPlace(double x) { ret posterizeToInt(x)*.5; } class Cell { // Original image and which part we are looking at DoubleRange xClip, yClip; // color transformations in place DoubleRange[] colorClips = new[3]; Cell copy() { new Cell c; c.xClip = xClip; arrayCopy(colorClips, c.colorClips); ret c; } Rect rectInImage() { ret toRect_floor(doubleRectFromRanges(xClip, yClip)); } // get color of cell double color(int channel) { double color = ii_averageBrightnessOfArea(image, rectInImage(), channel); ret transformBetweenDoubleRanges(color, colorClips[channel], zeroToOne()); } // unposterized color of all 3 channels double[] color() { double[] c = new[3]; for i to 3: c[i] = color(i); ret c; } toString { ret "Color: " + asList(color()); } int posterizedIntColor(int channel) { ret posterizeToInt(color(channel)); } // get sub-cells Cell[] xSplit() { Cell[] cells = new[3]; for i to 3: cells[i] = xSlice(i/3.0, (i+1)/3.0); ret cells; } Cell xSlice(double a, double b) { Cell c = copy(); c.xClip = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), xClip); ret c; } Cell[] ySplit() { Cell[] cells = new[3]; for i to 3: cells[i] = ySlice(i/3.0, (i+1)/3.0); ret cells; } Cell ySlice(double a, double b) { Cell c = copy(); c.yClip = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), yClip); ret c; } } // make the root cell Cell rootCell() { new Cell c; c.xClip = doubleRange(0, image.getWidth()); c.yClip = doubleRange(0, image.getHeight()); for i to 3: c.colorClips[i] = doubleRange(0, 255); ret c; } }