def splitHistogramKittlerIllingworth(histogram, binVals):
    '''Tries to compute an optimal histogram threshold using the Kittler/Illingworth method'''

    # Normalize the histogram (each bin is now a percentage)
    histSum      = float(sum(histogram))
    relativeHist = numpy.divide(histogram,histSum)


    # Try out every bin value in the histogram and pick the best one
    #  - For more resolution, use more bins!
    #  - Could write up a smarter solver for this.
    numBins = len(binVals)
    J = []
    for i in range(0, numBins):
        J.append(__computeJT(relativeHist, binVals, i))
        
    minJ      = J[1]
    threshold = binVals[0]
    for i in range(1, numBins):
        if J[i] < minJ:
            minJ      = J[i]
            threshold = (binVals[i] + binVals[1-i])/2 # Threshold is below current bin value
    
    return threshold
dataset/ETHPy150Open nasa/CrisisMappingToolkit/cmt/radar/histogram.py/splitHistogramKittlerIllingworth/swapped operands of `-`