cmodule2 URecog > DynPrintLog { // 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 IIntegralImage image; DoubleRange xClip, yClip; // color transformations in place DoubleRange[] colorClips = new[3]; *() {} // internal // make the root cell *(IIntegralImage *image) { xClip = yClip = zeroToOne(); for i to 3: colorClips[i] = zeroToOne(); } Cell copy() { new Cell c; c.image = image; 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; } } }