示例#1
0
def main(sourcedatafolder):
    abweichung_total = 0
    # Internetbeiträge zum Thema "HSV und Graustufen":
    # https://stackoverflow.com/questions/23811638/convert-hsv-to-grayscale-in-opencv
    # https://de.mathworks.com/matlabcentral/answers/312101-how-to-convert-gray-image-to-hsv-plane-v-value-image
    # https://stackoverflow.com/questions/38136291/why-the-gray-scale-image-is-different-from-value-channel-of-hsv-image?rq=1
    for file in glob.glob(join(sourcedatafolder, "*")):
        # load images
        image_1 = load_image_in_hsv(file)  # load with OpenCV
        image_2 = bif.mode(bif.load(file), 'gray')  # load with Pillow

        abweichung_img = 0
        count = 0
        for x in range(len(image_1)):  # compare V channel with gray pixel
            for y in range(len(image_1)):
                v_channel = image_1[x][y][2]  # x == row ; y == column
                gray_pixel = image_2.getpixel((y, x))  # y == row ; x == column
                abw_current = v_channel - gray_pixel  # berechne Abweichung
                abweichung_img += abw_current  # summiere Abweichungen für ein Bild
                count += 1

        # print(str(v_channel) + "  --  " + str(gray_pixel))
        print("Abweichung: " + str(
            abweichung_img / count))  # Durchschnittliche Abweichung je Bild
        print("----------")

        abweichung_total += abweichung_img / count  # füge Abweichung des einzelnen Bildes zu Gesamtabweichung hinzu

    print(
        "Durchschnittliche Abweichung: " + str(abweichung_total / 500)
    )  # Durchschnittliche Abweichung in allen Bildern ; 500 ist die Anzahl der Testbilder
示例#2
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__)