sclass URecognizer1 { 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()); ret transformBetweenDoubleRanges(color, colorClips[channel], zeroToOne()); } 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, i+1); 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, i+1); 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 = c.yClip = zeroToOne(); for i to 3: c.colorClips[i] = zeroToOne(); ret c; } }