Here you can find the source of clipHistogram(final int[] hist, final int[] clippedHist, final int limit)
Parameter | Description |
---|---|
hist | source |
clippedHist | target |
limit | clip limit |
bins | number of bins |
final static private void clipHistogram(final int[] hist, final int[] clippedHist, final int limit)
//package com.java2s; /**/*from www . j a v a2 s .co m*/ * License: GPL * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License 2 * as published by the Free Software Foundation. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ public class Main { /** * Clip histogram and redistribute clipped entries. * * @param hist source * @param clippedHist target * @param limit clip limit * @param bins number of bins */ final static private void clipHistogram(final int[] hist, final int[] clippedHist, final int limit) { System.arraycopy(hist, 0, clippedHist, 0, hist.length); int clippedEntries = 0, clippedEntriesBefore; do { clippedEntriesBefore = clippedEntries; clippedEntries = 0; for (int i = 0; i < hist.length; ++i) { final int d = clippedHist[i] - limit; if (d > 0) { clippedEntries += d; clippedHist[i] = limit; } } final int d = clippedEntries / (hist.length); final int m = clippedEntries % (hist.length); for (int i = 0; i < hist.length; ++i) clippedHist[i] += d; if (m != 0) { final int s = (hist.length - 1) / m; for (int i = s / 2; i < hist.length; i += s) ++clippedHist[i]; } } while (clippedEntries != clippedEntriesBefore); } }