예제 #1
0
def lip_segmentation2(inputRawImage, featureImage, inputLabel):
    retLabel = inputLabel
    width, height = retLabel.shape
    for i in range(width):
        for j in range(height):
            retLabel[i][j] == 0
        for i in range(width):
            for j in range(height):
                retLabel[i][j] = 255 * math.exp(
                    featureImage[i][j][0]) / (math.exp(featureImage[i][j][0]) +
                                              math.exp(featureImage[i][j][1]))
                print retLabel[i][j]
                if (retLabel[i][j] > 128):
                    retLabel[i][j] = (retLabel[i][j] - 128) * 2
                else:
                    retLabel[i][j] = 0
        return 0, retLabel
    features = extract_feature2(inputRawImage, featureImage, inputLabel)
    center, clusterResult = kMeans.kMeans(mat(features), 2)
    distance = sqrt(sum(power(center[0, 2:] - center[1, 2:], 2)))
    for i in range(len(clusterResult)):
        x = features[i][0]
        y = features[i][1]
        if distance > 0:
            retLabel[x][y] = clusterResult[i, 0] + 1
        else:
            retLabel[x][y] = 2
    return distance, retLabel
예제 #2
0
def lip_segmentation(inputRawImage, inputLabel):
    retLabel = inputLabel
    width, height = retLabel.shape
    for i in range(width):
        for j in range(height):
            retLabel[i][j] == 0
    features = extract_feature(inputRawImage, inputLabel)
    center, clusterResult = kMeans.kMeans(mat(features), 2)
    distance = sqrt(sum(power(center[0, 2:] - center[1, 2:], 2)))
    for i in range(len(clusterResult)):
        x = features[i][0]
        y = features[i][1]
        if distance > 0:
            retLabel[x][y] = clusterResult[i, 0] + 1
        else:
            retLabel[x][y] = 2
    return distance, retLabel
예제 #3
0
while loop:
    print_menu()

    try:
        choice = int(input(' Enter your choice [1-5]: '))
    except Exception:
        print(' Enter valid choice!')
        choice = 6

    if choice == 1:
        print(
            '\n K-Means Clustering technique is used to group unrealated data.'
            '\n For example : Unsupervised learning model (i.e. no additional information provided to work on) like where rich people lives'
        )
        input(' Press enter to proceed to plot')
        kMeans()

    elif choice == 2:
        print(
            '\n Naive Bayes is used for classifying data.'
            '\n For example : Supervised learning model (i.e. making action according to previous deduction) like drug-test results'
        )
        input(' Press enter to proceed to result')
        nBayes()

    elif choice == 3:
        print(
            '\n Decision Tree is used for resolving to get conclusion from past decisions.'
            '\n For example : Supervised learning model (i.e. making action according to previous deduction) like Should i play outside ?'
        )
        input(' Press enter to proceed to get decision tree')
예제 #4
0
    if (not sum(dataSet[x])):
        del dataSet[x]

t = list(userdata.keys())
for x in t:
    if (not sum(userdata[x])):
        del userdata[x]

centroids = []
for x in range(9):
    centroids.append(dataSet[x])

print(len(dataSet))

dataSet = k_means.mat(dataSet)
centroids = k_means.kMeans(dataSet, 9, k_means.mat(centroids))

fl = []
for x in range(9):
    fl.append(open('sort/' + str(x) + '.txt', 'w', encoding='utf-8'))

for x in userdata:
    num = 0
    distance = k_means.distEclud(centroids[0], userdata[x])
    for i in range(1, 9):
        if (k_means.distEclud(centroids[i], userdata[x]) < distance):
            distance = k_means.distEclud(centroids[i], userdata[x])
            num = i
    fl[num].write(x + '\n')

for x in range(9):