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 { // Which part of the image we are looking at (x/y) // dimension 0 = x, dimension 1 = y DoubleRange[] clip = new[2]; // color transformations in place DoubleRange[] colorClips = new[3]; Cell copy() { new Cell c; arrayCopy(clip, c.clip); arrayCopy(colorClips, c.colorClips); ret c; } Rect rectInImage() { ret toRect_floor(doubleRectFromRanges(clip[0], clip[1])); } // 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[] split(int dimension) { Cell[] cells = new[3]; for i to 3: cells[i] = third(dimension, i); ret cells; } Cell slice(int dimension, double a, double b) { Cell c = copy(); c.clip[dimension] = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), clip[dimension]); ret c; } // index = 0 to 2 Cell third(int dimension, int index) { ret slice(dimension, index/3.0, (index+1)/3.0); } } // make the root cell Cell rootCell() { new Cell c; c.clip[0] = doubleRange(0, image.getWidth()); c.clip[1] = doubleRange(0, image.getHeight()); for i to 3: c.colorClips[i] = doubleRange(0, 255); ret c; } }