sinterface IIntegralImage extends MakesBufferedImage { public int getWidth(); public int getHeight(); default public Pt getSize() { ret pt(getWidth(), getHeight()); } default public int nChannels() { ret 3; } // get value for 1 channel // normal range [0; pixelCount*256) public double getIntegralValue(int x, int y, int channel); // gets value of the 3 channels // normal range [0; pixelCount*256*3) default double getIntegralValue(int x, int y) { ret getIntegralValue(x, y, 0) + getIntegralValue(x, y, 1) + getIntegralValue(x, y, 2); } default double rectSum(int x1, int y1, int x2, int y2, int channel) { double bottomLeft = getIntegralValue(x1-1, y2-1, channel); double bottomRight = getIntegralValue(x2-1, y2-1, channel); double topLeft = getIntegralValue(x1-1, y1-1, channel); double topRight = getIntegralValue(x2-1, y1-1, channel); ret bottomRight+topLeft-topRight-bottomLeft; } default double rectSum(int x1, int y1, int x2, int y2) { double bottomLeft = getIntegralValue(x1-1, y2-1); double bottomRight = getIntegralValue(x2-1, y2-1); double topLeft = getIntegralValue(x1-1, y1-1); double topRight = getIntegralValue(x2-1, y1-1); ret bottomRight+topLeft-topRight-bottomLeft; } default double rectSum(Rect r) { ret rectSum(r.x, r.y, r.x2(), r.y2()); } default double rectSum(Rect r, int channel) { ret rectSum(r.x, r.y, r.x2(), r.y2(), channel); } default IIntegralImage clip(int x, int y, int w, int h) { ret IIVirtualClip(this, x, y, w, h); } default double averageBrightness() { int w = getWidth(), h = getHeight(); ret doubleRatio(getIntegralValue(w-1, h-1), w*h*3*255.0); } default double getPixel(int x, int y, int channel) { ret rectSum(x, y, x+1, y+1, channel); } // returns RGB pixel without alpha default int getPixel(int x, int y) { int r = iround(rectSum(x, y, x+1, y+1, 0)); int g = iround(rectSum(x, y, x+1, y+1, 1)); int b = iround(rectSum(x, y, x+1, y+1, 2)); ret rgbInt(r, g, b); } default BufferedImage getBufferedImage() { int w = getWidth(), h = getHeight(); int[] pixels = new[w*h]; int i = 0; for y to h: for x to w: pixels[i++] = getPixel(x, y) | fullAlphaMask(); ret intArrayToBufferedImage(pixels, w, h); } // minimum and maximum brightness possible in image default DoubleRange colorRange(int channel) { ret doubleRange(0, 256); } }