Now using histogram to compute threshold.