Here you can find the source of averageX(long[][] intImg, int width, int height, int i, int j, int dl, int dr)
Parameter | Description |
---|---|
intImg | the integral image |
width | the width of the picture |
height | the height of the picture |
i | the x coordinate |
j | the y coordinate |
dl | left offset |
dr | right offset |
public static final int averageX(long[][] intImg, int width, int height, int i, int j, int dl, int dr)
//package com.java2s; /* ImageUtil.java/*from w ww . j a v a 2 s . co m*/ * ========================================================================= * This file is originally part of the MathOCR Project * * Copyright (C) 2015 Chan Chung Kwong * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * */ public class Main { /** * Compute the average x coordinate of nonzero pixels * @param intImg the integral image * @param width the width of the picture * @param height the height of the picture * @param i the x coordinate * @param j the y coordinate * @param dl left offset * @param dr right offset * @return the sum */ public static final int averageX(long[][] intImg, int width, int height, int i, int j, int dl, int dr) { int count = 0, sum = 0, xstart = Math.max(0, j - dl), xend = Math.min(width - 1, j + dr), ystart = Math.max(-1, i - dl), yend = Math.min(height - 1, i + dr); for (int k = xstart; k < xend; k++) { int tmp = (int) (intImg[yend][k] - (ystart != -1 ? intImg[ystart][k] : 0) + (k != 0 ? -intImg[yend][k - 1] + (ystart != -1 ? intImg[ystart][k - 1] : 0) : 0)); count += tmp; sum += tmp * k; } return count == 0 ? Integer.MAX_VALUE : sum / count; } }