<commit_before># Visual Interfaces Spring 2015 Assignment 1
# <NAME> - rja2139

import cv2
import numpy as np

results=[]

def positive(value):
    if value < 0:
        return (-1 * value)
    else:
        return value


def comparehist(hist1, hist2):
    total_distance = 0
    for r in range (0, len(hist1)):
        for g in range (0, len(hist1[r])):
            for b in range (0, len(hist1[r][g])):
                total_distance += (positive(hist1[r][g][b] - hist2[r][g][b]))
    return total_distance

#for i in range(1, 40):
i = 4
# We load the base image, against which other images will be tested
base = cv2.imread("i" + str(i) + ".ppm")

histbase = cv2.calcHist(base, [0,1,2], None, [8,8,8], [10, 256, 10, 256, 10, 256])
cv2.normalize(histbase, histbase, 0, 255, cv2.NORM_MINMAX)
for j in range(1, 41):
    #if i == j:
    #    continue
    test = cv2.imread("i" + str(j) + ".ppm")
    histtest = cv2.calcHist(test, [0,1,2], None, [8,8,8], [10, 256, 10, 256, 10, 256])
    cv2.normalize(histtest, histtest, 0, 255, cv2.NORM_MINMAX)
    results.append(comparehist(histbase,histtest))
print results
npres = np.array(results)
cv2.normalize(npres,npres,0,1,cv2.NORM_MINMAX)
    # print "Image " + str(j) + ": " + str(result)



#print result<commit_msg>Works at last! Now I only have to set up the display routine<commit_after># Visual Interfaces Spring 2015 Assignment 1
# <NAME> - rja2139

import cv2
import numpy as np
from operator import itemgetter


#
def positive(value):
    if value < 0:
        return -1 * value
    else:
        return value


#
def comparehist(hist1, hist2):
    total_distance = 0
    for i in range (0, len(hist1)):
        for j in range (0, len(hist1[i])):
            for k in range (0, len(hist1[i][j])):
                total_distance += positive(hist1[i][j][k] - hist2[i][j][k])
    return total_distance / 30


for i in range(1, 41):
    results = []
    # We load the base image, against which other images will be tested
    base = cv2.imread("i" + str(i) + ".ppm")
    histbase = cv2.calcHist(base, [0, 1, 2], None, [8, 8, 8], [10, 256, 10, 256, 10, 256])
    cv2.normalize(histbase, histbase, 0, 255, cv2.NORM_MINMAX)
    mergedbase = histbase.flatten()
    for j in range(1, 41):
        test = cv2.imread("i" + str(j) + ".ppm")
        histtest = cv2.calcHist(test, [0, 1, 2], None, [8, 8, 8], [10, 256, 10, 256, 10, 256])
        cv2.normalize(histtest, histtest, 0, 255, cv2.NORM_MINMAX)
        mergedtest = histtest.flatten()
        results.append(comparehist(histbase, histtest))
    npresults = np.array(results)
    cv2.normalize(npresults, npresults, 0, 1, cv2.NORM_MINMAX)
    np.set_printoptions(suppress=True)
    for j in range (0, len(npresults)):
        results[j] = (1 - npresults[j], j + 1)
    sort = sorted(results, key=itemgetter(0))

    print sort
{'fraction_non_alphanumeric': 0.1508498583569405, 'fraction_numerical': 0.06692634560906516, 'mean_word_length': 3.0764790764790764, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3445898', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1044, 'n_words': 306}