141cb21fec5b5557a800cb2131e463b92913985a,niftynet/utilities/misc_common.py,,otsu_threshold,#Any#,206

Before Change


    threshold = 0
    sum_im = 0
    for i in range(0, 256):
        mean_ip = np.mean(img[img > bin_edges[i]])
        mean_im = np.mean(img[img < bin_edges[i]])
        sum_im = sum_im + hist[i]
        sum_ip = 1 - sum_im
        target = sum_ip*sum_im*np.square(mean_ip-mean_im)

After Change


def otsu_threshold(img):
    """ Implementation of otsu thresholding"""
    hist, bin_edges = np.histogram(img.ravel(), bins=256, density=True)
    hist = hist.astype(float)
    target_max = 0
    threshold = bin_edges[0]
    sum_im = 0

    mean_ip = np.cumsum(hist)
    mean_im = np.cumsum(hist[::-1])[::-1]
    for i in range(0, 256):
        sum_im = sum_im + hist[i]
        sum_ip = 1 - sum_im
        target = sum_ip * sum_im * np.square(mean_ip[i] - mean_im[i])
        if target > target_max:
            target_max, threshold = target, bin_edges[i]
    return threshold
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: NifTK/NiftyNet
Commit Name: 141cb21fec5b5557a800cb2131e463b92913985a
Time: 2017-07-18
Author: wenqi.li@ucl.ac.uk
File Name: niftynet/utilities/misc_common.py
Class Name:
Method Name: otsu_threshold


Project Name: nipy/dipy
Commit Name: 623daf36fdcc4fe3e3cc63f863532e10668faa86
Time: 2017-04-04
Author: arokem@gmail.com
File Name: dipy/denoise/tests/test_non_local_means.py
Class Name:
Method Name: test_nlmeans_random_noise


Project Name: dmlc/gluon-cv
Commit Name: b30cdf3a1a977927345f407a4c25be2884cfee7f
Time: 2018-09-06
Author: 8041160+zhanghang1989@users.noreply.github.com
File Name: scripts/segmentation/train.py
Class Name: Trainer
Method Name: validation