Java Integer Clip clipHistogram(final int[] hist, final int[] clippedHist, final int limit)

Here you can find the source of clipHistogram(final int[] hist, final int[] clippedHist, final int limit)

Description

Clip histogram and redistribute clipped entries.

License

GNU General Public License

Parameter

Parameter Description
hist source
clippedHist target
limit clip limit
bins number of bins

Declaration

final static private void clipHistogram(final int[] hist, final int[] clippedHist, final int limit) 

Method Source Code

//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);
    }
}

Related

  1. clip(int val, int from, int to)
  2. clip(int val, int from, int to)
  3. clip(int x)
  4. clip(int[][][] data, int startX, int startY, int stopX, int stopY)
  5. clipColor(final int compIn, final boolean allowRGB555)
  6. clipInt(int value, int max)
  7. clipInt(int value, int min, int max)
  8. clipPeerIdFromCurrentThreadName()
  9. clipPlus128(int v)