001package org.openimaj.demos.sandbox.tldcpp.detector; 002 003import org.openimaj.image.FImage; 004 005/** 006 * a 2D double array such that each element is the sum of each 007 * value to the top left of the element, 008 * @author Sina Samangooei (ss@ecs.soton.ac.uk) 009 * 010 */ 011public class IntegralImage { 012 double[][] data; 013 014 IntegralImage() { 015 } 016 void calcIntImg(FImage img, boolean squared) 017 { 018 data = new double[img.height][img.width]; 019 float[][] input = img.pixels; 020 double[][] output = data; 021 for(int j = 0;j < img.height;j++){ 022 for(int i = 0;i < img.width;i++){ 023 double A = (i > 0) ? output[j][i - 1] : 0; 024 double B = (j > 0) ? output[j - 1][i] : 0; 025 double C = (j > 0 && i > 0) ? output[j - 1][ i - 1] : 0; 026 double value = input[j][i]; 027 if(squared) { 028 value = value*value; 029 } 030 output[j][i] = A + B - C + value; 031 } 032 } 033 034 } 035}