Example #1
0
def patient_accuracy(patient_file):

    p = Patient()
    p.set_parent_file(patient_file)
    p.set_window_size(0)
    p.start_iteration()

    print("patient accuracy")
    print(p.file_parent)
    for z in range(0, p.limit_z):
        for y in range(0, p.limit_y):
            for x in range(0, p.limit_x):
                if (p.label[z][y][x] != 0):
                    p.label[z][y][x] = 1

    a = p.label
    b = utility.read_mha_image_as_nuarray(p._find_file("segmentation.mha"))

    print("files load , start accuracy calculation")

    P = TP(a, b, 0, a.ndim) + FP(a, b, 0, a.ndim)  #total positive
    T = TP(a, b, 0, a.ndim) + FN(a, b, 0, a.ndim)  #total actual positive
    N = TN(a, b, 0, a.ndim) + FP(a, b, 0, a.ndim)  #total actual negative
    dice = TP(a, b, 0, a.ndim) / float(((P + T) / 2))
    sens = TP(a, b, 0, a.ndim) / float(T)
    spec = TN(a, b, 0, a.ndim) / float(N)
    acc = (TP(a, b, 0, a.ndim) + TN(a, b, 0, a.ndim)) / float(T + N)
    error = 1.0 - acc

    p.stop_iteration()
    print("P %s" % P)
    print("T %s" % T)
    print("N %s" % N)
    print("dice %s" % dice)
    print("sens %s" % sens)
    print("spec %s" % spec)
    print("acc %s" % acc)
    print("error %s" % error)