Here you can find the source of getMean(int[] data)
public static int getMean(int[] data)
//package com.java2s; public class Main { public static int getMean(int[] data) { // C. A. Glasbey, // "An analysis of histogram-based thresholding algorithms," // CVGIP: Graphical Models and Image Processing, vol. 55, pp. 532-537, // 1993./*from w w w.ja v a 2 s.com*/ // // The threshold is the mean of the greyscale data int threshold = -1; double tot = 0, sum = 0; for (int i = 0; i < 256; i++) { tot += data[i]; sum += (i * data[i]); } threshold = (int) Math.floor(sum / tot); return threshold; } }