Esempio n. 1
0
def main(sourcedatafolder, targetdatafile):
    allimages = []
    allfaces = []
    allgenres = []
    allhashes = []
    allfiles = []
    for file in glob.glob(join(sourcedatafolder, "*")):
        filehash, genre = get_metadata(file)
        filename = get_filename(file)
        allhashes.append(filehash)
        allgenres.append(genre)
        allfiles.append(filename)
        image = load_image(file)
        image_gray = make_grayscale(image)
        faces = find_faces(image_gray, image)
        #imageblackwhite = make_binary(image_gray)
        #faces = find_faces(imageblackwhite, image)
        allfaces.append(faces)
        ### for showing images comment out show_image

        #print("faces:", faces)
        #show_image(image)
        #show_image(imageblackwhite)
    save_data(allhashes, allgenres, allfaces, allfiles, targetdatafile)
    docfile.write(sourcedatafolder, targetdatafile, documentationfile, __doc__,
                  tail, __file__)
Esempio n. 2
0
def main(sourcedatafolder, targetdatafile, tail):
    allhashes = []
    allgenres = []
    all_median = []
    all_stdev = []
    all_max = []
    count = 0
    for file in glob.glob(join(sourcedatafolder, "*")):
        count += 1
        filehash, genre = get_metadata(file)
        allhashes.append(filehash)
        allgenres.append(genre)
        image = load_image(file)
        gray_channel = get_channel(image)
        gray_hist = make_histogram(image)
        gray_median, gray_stdev = get_channel_data(gray_channel)
        gray_max = get_histogramdata(gray_hist)
        all_median.append(gray_median)
        all_stdev.append(gray_stdev)
        all_max.append(gray_max)
        if count % 100 == 0:
            print(str(count))
    save_data(allhashes, allgenres, all_median, all_stdev, all_max,
              targetdatafile)
    docfile.write(sourcedatafolder, targetdatafile, documentationfile,
                  docstring, tail, __file__)
Esempio n. 3
0
def main(sourcedatafile, targetdatafile, documentationfile, tail):
    """
    Visualize the feature distribution.
    """
    data = load_data(sourcedatafile)
    genres = get_metadata(data)
    featurematrix = get_featurematrix(data)
    make_scatterplot(genres, featurematrix, targetdatafile)
    docfile.write(sourcedatafile, targetdatafile, documentationfile, docstring, tail, __file__)
Esempio n. 4
0
def main(sourcedatafile, targetdatafile, documentationfile, classifiertype, tail):
    """
    Classify music albums into subgenres based on their cover art.
    """
    data = load_data(sourcedatafile)
    genres = get_metadata(data)
    featurematrix = get_featurematrix(	data)
    classifier = define_classifier(classifiertype)
    perform_classification(featurematrix, genres, classifier)
    docfile.write(sourcedatafile, targetdatafile, documentationfile, docstring, tail, __file__)
Esempio n. 5
0
def main(sourcedatafolder, targetdatafolder, documentationfile, docstring, tail):
    if not os.path.exists(targetdatafolder):
        os.makedirs(targetdatafolder)
    for file in glob.glob(sourcedatafolder + "/*"):
        basename, ext = os.path.basename(file).split(".")
        image = bif.load(file)
        image = bif.resize(image, 500, 500)
        image = bif.mode(image, "bw")
        bif.save(image, basename, targetdatafolder)
    docfile.write(sourcedatafolder, targetdatafolder, documentationfile, docstring, tail, __file__)
Esempio n. 6
0
def main(first_csv, second_csv):
    merged = merge(first_csv, second_csv)
    save_data(merged)

    first_tmp = os.path.basename(os.path.normpath(
        first_csv))  # get filenames of the CSV files for use in the docfile
    second_tmp = os.path.basename(os.path.normpath(second_csv))
    docfile.write(
        first_csv, merged_csv, documentationfile, __doc__ + " (" + first_tmp +
        " with " + second_tmp + " => " + os.path.basename(merged_csv) + ")\n",
        tail, __file__)
Esempio n. 7
0
def main(sourcedatafile, targetdatafile, documentationfile, classifiertype, tail):
    """
    Classify music albums into subgenres based on their cover art.
    """
    data = load_data(sourcedatafile)
    # print(type(data))
    genres = get_metadata(data)
    featurematrix = get_featurematrix(data)
    classifier = define_classifier(classifiertype, n_neighbors, weights)
    features_test, labels_test, labels_predicted = perform_classification(featurematrix, genres, classifier)
    save_data( labels_test, labels_predicted, targetdatafile)
    docfile.write(sourcedatafile, targetdatafile, documentationfile, docstring, tail, __file__)
Esempio n. 8
0
def main(sourcedatafile, targetdatafile, documentationfile, classifiertype, tail):
    """
    Classify music albums into subgenres based on their cover art.
    """
    data = load_data(sourcedatafile)
    labels_test, labels_predicted, classes = unpack_data(data)

    # genres = get_metadata(data)
    # featurematrix = get_featurematrix(	data)
    # classifier = define_classifier(classifiertype)

    # labels_test, labels_predicted, classes = perform_classification(featurematrix, genres, classifier)

    make_confmatrix(labels_test, labels_predicted, classes, targetdatafile)
    docfile.write(sourcedatafile, targetdatafile, documentationfile, docstring, tail, __file__)
Esempio n. 9
0
def main(sourcedatafolder, targetdatafile, tail):
    allhashes = []
    allgenres = []
    all_median_blue = []
    all_median_green = []
    all_median_red = []
    all_stdev_blue = []
    all_stdev_green = []
    all_stdev_red = []
    allhist_max_blue = []
    allhist_max_green = []
    allhist_max_red = []
    for file in glob.glob(join(sourcedatafolder, "*")):
        filehash, genre = get_metadata(file)
        allhashes.append(filehash)
        allgenres.append(genre)
        image = load_image(file)

        h_blue, h_green, h_red = make_histograms(image)

        hist_max_blue = get_histogramdata(h_blue)
        hist_max_green = get_histogramdata(h_green)
        hist_max_red = get_histogramdata(h_red)

        blue, green, red = get_channels(image)
        median_blue, stdev_blue = get_channel_data(blue)
        median_green, stdev_green = get_channel_data(green)
        median_red, stdev_red = get_channel_data(red)

        all_median_blue.append(median_blue)
        all_median_green.append(median_green)
        all_median_red.append(median_red)
        all_stdev_blue.append(stdev_blue)
        all_stdev_green.append(stdev_green)
        all_stdev_red.append(stdev_red)
        allhist_max_blue.append(hist_max_blue)
        allhist_max_green.append(hist_max_green)
        allhist_max_red.append(hist_max_red)
    save_data(allhashes, allgenres, all_median_blue, all_median_green,
              all_median_red, all_stdev_blue, all_stdev_green, all_stdev_red,
              allhist_max_blue, allhist_max_green, allhist_max_red,
              targetdatafile)
    docfile.write(sourcedatafolder, targetdatafile, documentationfile,
                  docstring, tail, __file__)
    print(all_median_blue[0])
    print(all_stdev_blue[0])
    print(allhist_max_blue[0])
Esempio n. 10
0
def main(sourcedatafolder, targetdatafile, tail):
    allhashes = []
    allgenres = []
    allhist_median = []
    allhist_stdev = []
    allhist_max = []
    for file in glob.glob(join(sourcedatafolder, "*")):
        filehash, genre = get_metadata(file)
        allhashes.append(filehash)
        allgenres.append(genre)
        image = load_image(file)
        image_gray = make_grayscale(image)
        histogram = make_histogram(image_gray)
        hist_median, hist_stdev, hist_max = get_histogramdata(histogram)
        allhist_median.append(hist_median)
        allhist_stdev.append(hist_stdev)
        allhist_max.append(hist_max)
    save_data(allhashes, allgenres, allhist_median, allhist_stdev, allhist_max, targetdatafile)
    docfile.write(sourcedatafolder, targetdatafile, documentationfile, docstring, tail, __file__)
Esempio n. 11
0
def main(sourcedatafolder, targetdatafile):
    allimages = []
    allpeople = []
    allgenres = []
    allhashes = []
    allfiles = []
    for file in glob.glob(join(sourcedatafolder, "*")):
        filehash, genre = get_metadata(file)
        filename = get_filename(file)
        allhashes.append(filehash)
        allgenres.append(genre)
        allfiles.append(filename)
        image = load_image(file)
        image_gray = image
        people = find_people(image_gray)
        allpeople.append(people)
        ### for showing images comment out show_image

        #print("people:", people)
        #show_image(image)

    save_data(allhashes, allgenres, allpeople, allfiles, targetdatafile)
    docfile.write(sourcedatafolder, targetdatafile, documentationfile, __doc__,
                  tail, __file__)
Esempio n. 12
0
def main(sourcedatafile, targetdatafile, documentationfile, tail):
    data = load_data(sourcedatafile)
    data = normalize_data(data)
    save_data(data, targetdatafile)
    docfile.write(sourcedatafile, targetdatafile, documentationfile, docstring,
                  tail, __file__)
Esempio n. 13
0
def main(sourcedatafolder, targetdatafile, tail):
    allfilenames = []
    # allhmed = []
    # allhstd = []
    allhmax1 = []
    allhmax2 = []
    allhmax3 = []
    allvmed = []
    allvstd = []
    allvmax1 = []
    allvmax2 = []
    allvmax3 = []
    allsmed = []
    allsstd = []
    allsmax1 = []
    allsmax2 = []
    allsmax3 = []
    for file in glob.glob(join(sourcedatafolder, "*")):
        filename = get_metadata(file)
        allfilenames.append(filename)
        print("\n====", filename)
        image = load_image(file)
        #print("histogram for HUE (which color)\n0=red, 60=yellow, 240=blue")
        histogram = make_histogram(image, 0, 12, [0, 180])
        #plt.plot(histogram)
        #plt.show()
        #print(histogram)
        hue, sat, val = get_channels(image)
        hmax1, hmax2, hmax3 = get_hmax(histogram)
        # allhmed.append(hmed)
        # allhstd.append(hstd)
        allhmax1.append(hmax1 * 10)
        allhmax2.append(hmax2 * 10)
        allhmax3.append(hmax3 * 10)
        print("histogram for SATURATION (how colorful)\n0=pale, 100=intense")
        histogram = make_histogram(image, 1, 10, [0, 256])
        #print(histogram)
        #plt.plot(histogram)
        #plt.show()
        smax1, smax2, smax3 = get_smax(histogram)
        print(smax1, smax2, smax3)
        smed, sstd = get_channel_data(sat)
        allsmax1.append(smax1 * 10)
        allsmax2.append(smax2 * 10)
        allsmax3.append(smax3 * 10)
        allsmed.append(smed)
        allsstd.append(sstd)
        print("histogram for VALUE (how bright)\n0=dark, 100=bright")
        histogram = make_histogram(image, 2, 10, [0, 256])
        #plt.plot(histogram)
        #plt.show()
        vmax1, vmax2, vmax3 = get_vmax(histogram)
        vmed, vstd = get_channel_data(val)
        print(vmax1, vmax2, vmax3)
        allvmax1.append(vmax1 * 10)
        allvmax2.append(vmax2 * 10)
        allvmax3.append(vmax3 * 10)
        allvmed.append(vmed)
        allvstd.append(vstd)
    save_data(allfilenames, allhmax1, allhmax2, allhmax3, allsmax1, allsmax2,
              allsmax3, allsmed, allsstd, allvmax1, allvmax2, allvmax3,
              allvmed, allvstd, targetdatafile)
    docfile.write(sourcedatafolder, targetdatafile, documentationfile,
                  docstring, tail, __file__)