Beispiel #1
0
def process(input_folder):
    file_count = util.check_file_count(input_folder)
    index = 1
    failed_files = 0
    skipped_files = 0
    for filename in os.listdir(input_folder):
        valid_ext = False
        for valid_extension in valid_extensions:
            if filename.endswith(valid_extension):
                valid_ext = True
                print("Processing Picture {} of {}".format(index, file_count))
                pic_path = "{0}{1}{2}".format(input_folder, slash, filename)
                try:
                    picture = Im.open(pic_path, "r")
                    picture = ImOps.grayscale(picture)
                    picture = picture.convert(mode="RGB")
                    picture.save(pic_path, "PNG", icc_profile='')
                    index += 1
                except Exception as e:
                    raise e
                    print("An error prevented this image from being converted")
                    print("Delete: {} ?".format(pic_path))
                    failed_files += 1
        if not valid_ext:
            print(
                "Skipped {} as it's not a valid image or not a valid extension."
                .format(filename))
            skipped_files += 1

    print("{} pictures failed to be processed.".format(failed_files))
    print("{} files were skipped.".format(skipped_files))
def process(input_folder):
    file_count = util.check_file_count(input_folder)
    index = 1
    failed_files = 0
    skipped_files = 0
    for filename in os.listdir(input_folder):
        valid_ext = False
        for valid_extension in valid_extensions:
            if filename.endswith(valid_extension):
                valid_ext = True
                print("Processing Picture {} of {}".format(index, file_count))
                pic_path = "{}{}{}".format(input_folder, sep, filename)
                output_path = "{}{}{}".format(input_folder, sep, "output")
                try:
                    picture = cv2.imread(pic_path, cv2.IMREAD_COLOR)
                    b, g, r = cv2.split(picture)
                    makedirs_list(("{0}_R\\".format(output_path),
                                   "{0}_G\\".format(output_path),
                                   "{0}_B\\".format(output_path)))
                    cv2.imwrite("{}_R\\{}".format(output_path, filename), r)
                    cv2.imwrite("{}_G\\{}".format(output_path, filename), g)
                    cv2.imwrite("{}_B\\{}".format(output_path, filename), b)
                    index += 1
                except:
                    failed_files += 1
        if not valid_ext:
            print(
                "Skipped {} as it's not a valid image or not a valid extension."
                .format(filename))
            skipped_files += 1

    print("{} pictures failed to be processed.".format(failed_files))
    print("{} files were skipped.".format(skipped_files))
def process(input_folder):
    file_count = util.check_file_count(input_folder)
    index = 1
    rgb_index = 0
    failed_files = 0
    skipped_files = 0
    for root, dirs, files in os.walk(input_folder):
        if not os.path.isdir("{0}{1}processed{2}".format(root, slash, slash)):
            print("Directory does not exist")
            os.makedirs("{0}{1}processed{2}".format(root, slash, slash))
        for filename in files:
            valid_ext = False
            for valid_extension in valid_extensions:
                if filename.endswith(valid_extension):
                    valid_ext = True
                    print("Processing Picture {} of {}".format(
                        index, file_count))
                    pic_path = "{}{}{}".format(root, slash, filename)
                    try:
                        picture = Im.open(pic_path, "r")
                        if picture.mode != "RGB":
                            picture = picture.convert(mode="RGB")
                            rgb_index += 1
                        # if get_random_blur_type() == "gaussian":
                        picture = picture.filter(
                            ImageFilter.GaussianBlur(get_random_radius()))
                        # else:
                        #     picture = picture.filter(ImageFilter.BoxBlur(get_random_radius()))
                        picture.save(pic_path, "PNG", icc_profile='')
                        index += 1
                    except Exception as e:
                        print(
                            "An error prevented this image from being converted"
                        )
                        print("Delete: {}".format(pic_path))
                        failed_files += 1
                        raise e
            if not valid_ext:
                print(
                    "Skipped {} as it's not a valid image or not a valid extension."
                    .format(filename))
                skipped_files += 1

    print("{} pictures were converted from Palette/Grayscale/Other to RGB.".
          format(rgb_index))
    print("{} pictures failed to be processed.".format(failed_files))
    print("{} files were skipped".format(skipped_files))
    # print("The GaussianBlur was applied {} times and Box {} times.".format(gauss_count, box_count))
    print("The average blur radius was = {}".format(get_radius_average()))
def process(input_folder):
    file_count = util.check_file_count(input_folder)
    index = 1
    failed_files = 0
    skipped_files = 0
    for root, dirs, files in os.walk(input_folder):
        if not os.path.isdir("{0}{1}processed{1}".format(root, slash)):
            print("Directory does not exist. Creating {0}".format(
                "{0}{1}processed".format(root, slash)))
            os.makedirs("{0}{1}processed{1}".format(root, slash))
        for filename in files:
            valid_ext = False
            for valid_extension in valid_extensions:
                if filename.endswith(valid_extension):
                    valid_ext = True
                    print("Processing Picture {} of {}".format(
                        index, file_count))
                    pic_path = "{0}{1}{2}".format(root, slash, filename)
                    try:
                        picture = Im.open(pic_path, "r")
                        if picture.mode != "RGB":
                            picture = picture.convert(mode="RGB")
                        pic_lab = ImCms.applyTransform(picture, rgb2lab)
                        picture.close()
                        L, a, b = pic_lab.split()
                        L = L.filter(
                            ImageFilter.GaussianBlur(
                                get_random_radius(0.5, 2.5)))
                        pic_lab = Im.merge("LAB", (L, a, b))
                        pic_lab = ImCms.applyTransform(pic_lab, lab2rgb)
                        pic_lab.save(pic_path, "PNG", icc_profile='')
                        index += 1
                    except Exception as e:
                        raise e  # well...
                        print(
                            "An error prevented this image from being converted"
                        )
                        print("Delete: {}".format(pic_path))
                        failed_files += 1
            if not valid_ext:
                print(
                    "Skipped {} as it's not a valid image or not a valid extension."
                    .format(filename))
                skipped_files += 1

    print("Average Blur Radius = {}".format(get_radius_average()))
    print("{} pictures failed to be processed.".format(failed_files))
    print("{} files were skipped.".format(skipped_files))
Beispiel #5
0
def process(input_folder):
    file_count = util.check_file_count(input_folder)
    index = 1
    failed_files = 0
    skipped_files = 0
    for root, dirs, files in os.walk(input_folder):
        if not os.path.isdir("{0}{1}processed{2}".format(root, slash, slash)):
            print("Directory does not exist. Creating {}".format(
                "{0}{1}processed".format(root, slash)))
            os.makedirs("{0}{1}processed{1}".format(root, slash))
        for filename in files:
            valid_ext = False
            for valid_extension in valid_extensions:
                if filename.endswith(valid_extension):
                    valid_ext = True
                    print("Processing Picture {} of {}".format(
                        index, file_count))
                    pic_path = "{0}{1}{2}".format(root, slash, filename)
                    try:
                        with Im.open(pic_path, "r") as picture:
                            if picture.mode != "RGB":
                                picture = picture.convert(mode="RGB")
                            pic_nn = picture.resize(
                                (int(picture.width / scale),
                                 int(picture.height / scale)),
                                resample=0)
                            pic_nn = pic_nn.resize(
                                (int(picture.width), int(picture.height)),
                                resample=0)
                            pic_nn.save(pic_path, "PNG", icc_profile='')
                            index += 1
                    except Exception as e:
                        print(
                            "An error prevented this image from being converted"
                        )
                        print("Delete: {}".format(pic_path))
                        failed_files += 1
                        raise e
            if not valid_ext:
                print(
                    "Skipped {} as it's not a valid image or not a valid extension."
                    .format(filename))
                skipped_files += 1

    print("{} pictures failed to be processed.".format(failed_files))
    print("{} files were skipped.".format(skipped_files))
Beispiel #6
0
def process(input_folder):
    file_count = util.check_file_count(input_folder)
    index = 1
    rgb_index = 0
    failed_files = 0
    skipped_files = 0
    for root, dirs, files in os.walk(input_folder):
        for filename in files:
            valid_ext = False
            for valid_extension in valid_extensions:
                if filename.endswith(valid_extension):
                    valid_ext = True
                    print("Processing Picture {} of {}".format(
                        index, file_count))
                    pic_path = "{}{}{}".format(root, slash, filename)
                    try:
                        picture = Im.open(pic_path, "r")
                        if picture.mode != "RGB":
                            picture = picture.convert(mode="RGB")
                            rgb_index += 1
                        picture.save("{0}.jpg".format(
                            pic_path.rstrip(".png").rstrip(".jpg").rstrip(
                                ".dds")),
                                     "JPEG",
                                     subsampling=get_random_subsampling(),
                                     quality=get_random_quality(),
                                     icc_profile='')
                        index += 1
                    except Exception as e:
                        print(
                            "An error prevented this image from being converted"
                        )
                        print("Delete: {}".format(pic_path))
                        failed_files += 1
                        raise e
            if not valid_ext:
                print(
                    "Skipped {} as it's not a valid image or not a valid extension."
                    .format(filename))
                skipped_files += 1
    print("{} pictures were converted from Palette Mode to RGB.".format(
        rgb_index))
    print("{} pictures failed to be processed.".format(failed_files))
    print("{} files were skipped.".format(skipped_files))
Beispiel #7
0
def main():
    idx_limit = util.check_file_count(input_folder)
    idx = 1
    for file in os.listdir(input_folder):
        print("Processing file {} | {} of {} | {:.2f} percent".format(file, idx, idx_limit, (idx / idx_limit) * 100))
        temp_red = list()
        temp_green = list()
        temp_blue = list()

        file_path = input_folder + file
        with Im.open(file_path, "r") as image:
            image_data = image.load()

            for x in range(image.width):
                for y in range(image.height):
                    red, green, blue = image_data[x, y][0], image_data[x, y][1], image_data[x, y][2]
                    temp_red.append(red)
                    temp_green.append(green)
                    temp_blue.append(blue)

            avg_colors = round(avg_color(temp_red)), round(avg_color(temp_green)), round(avg_color(temp_blue))
            red_values.append(avg_colors[0])
            green_values.append(avg_colors[1])
            blue_values.append(avg_colors[2])
        idx += 1

    # axis.plot3D(red_values, green_values, blue_values)
    print("\nPlotting...")
    try:
        axis.scatter(red_values, green_values, blue_values, color="black")
    except Exception as e:
        pass
    axis.set_xlabel("Red")
    axis.set_ylabel("Green")
    axis.set_zlabel("Blue")
    print("Done.")
    plt.show()