Ejemplo n.º 1
0
def create_averaged_imagesV4(target_images, rated_sorted_photos):
    print("creating averaged images")
    num_rows = len(target_images)
    printProgressBar(0, num_rows)
    rsp_cpy = copy.copy(rated_sorted_photos)

    res = 8
    images = []
    for row in range(len(target_images)):
        images.append([])
        for col in range(len(target_images[0])):
            # refill rp_copy occasionally (simpler, hackier way to threshold)
            if (len(rsp_cpy) <= float(len(rated_sorted_photos)) * 19.0 / 20.0):
                rsp_cpy = copy.copy(rated_sorted_photos)
            N = len(
                rsp_cpy
            ) / 10 + 1  # needs tweaking. dividing by larger = less color match, more pattern match.
            close_low_res_photos = get_closest_grayscale(
                target_images[row][col], rsp_cpy, N)
            match = low_res_match_grayscale(target_images[row][col],
                                            close_low_res_photos, res)
            images[row].append(
                match[0][1])  # match is ((low_res, orig), index)
            rsp_cpy.pop(
                match[1]
            )  # chose w/o replacement to avoid monotony. Comment out if you do want replacement. Note: this is the only thing you need to comment out if you want replacement.
        printProgressBar(row + 1, num_rows)

    return images
Ejemplo n.º 2
0
def create_averaged_imagesV5(target_images, rated_photos):
    print("creating averaged images")
    num_rows = len(target_images)
    printProgressBar(0, num_rows)
    rp_cpy = copy.copy(rated_photos)

    res = 8
    images = []
    for row in range(len(target_images)):
        images.append([])
        for col in range(len(target_images[0])):
            close_low_res_photos = get_close_images_by_avg_color(
                target_images[row][col], rp_cpy)
            match, dist = low_res_match_colored(target_images[row][col],
                                                close_low_res_photos, res)
            images[row].append(
                match[0][1])  # match is ((low_res, orig), index)
            rp_cpy.pop(
                match[1]
            )  # chose w/o replacement to avoid monotony. Comment out if you do want replacement. Note: this is the only thing you need to comment out if you want replacement.

            # refill match not close enough, or if rp_cpy is getting too empty.
            if (
                    dist > 2000 or len(rp_cpy) < len(rated_photos) / 2
            ):  # not sure if 2000 is the right threshold, but it works decently.
                rp_cpy = copy.copy(rated_photos)

        printProgressBar(row + 1, num_rows)

    return images
Ejemplo n.º 3
0
def create_averaged_imagesV2(block_averages, rated_sorted_photos):
    num_rows = len(block_averages)
    printProgressBar(0, num_rows)
    images = []
    rsp_copy = copy.copy(rated_sorted_photos)
    total_photos = len(rated_sorted_photos)
    for row in range(len(block_averages)):
        images.append([])
        for col in range(len(block_averages[0])):
            # find closest image in rsp_copy to block_averages[row][col], without replacement (to avoid having many adjacent photos be identical).
            closest_index = bisect.bisect_right(
                KeyList(rsp_copy, key=lambda x: x[0]),
                block_averages[row][col])
            if (
                    closest_index >= len(rsp_copy)
            ):  # deal w/ case that block_avgs[row][col] > all rsp_copy grayscale scores
                closest_index = len(rsp_copy) - 1
            img_rating, img = rsp_copy.pop(closest_index)

            # lifting
            img_cpy = img.copy()
            scaled_colored_img = raise_img_by_val(
                img_cpy, block_averages[row][col] - img_rating)
            images[row].append(scaled_colored_img)

            # thresholding
            if (abs(img_rating - block_averages[row][col]) > 30
                    or len(rsp_copy) < len(rated_sorted_photos) /
                    2):  # not sure if 30 is the best threshold but it works!
                rsp_copy = copy.copy(rated_sorted_photos)

        printProgressBar(row + 1, num_rows)

    return images
Ejemplo n.º 4
0
def create_averaged_imagesV3(block_averages, rated_photos):
    num_rows = len(block_averages)
    printProgressBar(0, num_rows)
    images = []
    rs_copy = copy.copy(rated_photos)
    for row in range(len(block_averages)):
        images.append([])
        for col in range(len(block_averages[0])):
            # find closest image in rs_copy to block_averages[row][col], with replacement
            closest_index, dist = find_closest_RGB(block_averages[row][col],
                                                   rs_copy)
            if (
                    closest_index >= len(rs_copy)
            ):  # deal w/ case that block_avgs[row][col] > all rs_copy color scores
                closest_index = len(rs_copy) - 1
            img_rating, img = rs_copy.pop(closest_index)
            images[row].append(img)

            # thresholding
            threshold = 30
            if (
                    dist > threshold or len(rs_copy) < len(rated_photos) / 2
            ):  # the lower threshold is, the closer colors match, but the more chance there is for repeated images.
                rs_copy = copy.copy(rated_photos)
        printProgressBar(row + 1, num_rows)
    return images
Ejemplo n.º 5
0
def rate_low_res_colored(photos):
    print("Rating photos")
    num_photos = len(photos)
    counter = 0
    printProgressBar(counter, num_photos)

    rated_photos = []
    for photo in photos:
        level = get_avg_RGB(photo[0])
        rated_photos.append((level, photo))

        counter = counter + 1
        printProgressBar(counter, num_photos)

    return rated_photos
Ejemplo n.º 6
0
def rate_and_sort_grayscale(mini_photos_grayscale):
    num_photos = len(mini_photos_grayscale)
    counter = 0
    rated_sorted_photos = []
    # rate
    for photo in mini_photos_grayscale:
        printProgressBar(counter, num_photos)
        counter = counter + 1
        level = get_avg_grayscale(photo)
        rated_sorted_photos.append((level, photo))

    # sort
    rated_sorted_photos.sort(key=operator.itemgetter(0))
    printProgressBar(num_photos, num_photos)
    return rated_sorted_photos
Ejemplo n.º 7
0
def rate_colored(mini_photos):
    print("Rating photos")
    num_photos = len(mini_photos)
    counter = 0
    rated_photos = []
    # rate
    for photo in mini_photos:
        level = get_avg_RGB(photo)
        rated_photos.append((level, photo))

        printProgressBar(counter, num_photos - 1)
        counter = counter + 1

    # we will not be sorting b/c it's hard to sort color images (return to this in future...)
    return rated_photos
Ejemplo n.º 8
0
def create_low_res_photos(photos):
    print("creating low res photos")
    num_photos = len(photos)
    counter = 0
    printProgressBar(counter, num_photos)

    low_res_photos = []
    res = 8
    for photo in photos:
        low_res_photo = rescale(photo, res,
                                res)  # rescale doesn't modify original
        low_res_photos.append((low_res_photo, photo))

        counter = counter + 1
        printProgressBar(counter, num_photos)

    return low_res_photos
Ejemplo n.º 9
0
def make_mini_photos_grayscale(photos_paths, subimage_width):
    num_photos = len(photos_paths)
    counter = 0
    printProgressBar(0, num_photos)

    mini_photos = []
    scaled_width = subimage_width
    scaled_height = scaled_width

    for photo_path in photos_paths:
        raw_photo = convert_img_to_grayscale(Image.open(photo_path))
        raw_photo_mini = rescale(raw_photo, scaled_width, scaled_height)
        mini_photos.append(raw_photo_mini)
        counter = counter + 1
        printProgressBar(counter, num_photos)

    return mini_photos
Ejemplo n.º 10
0
def rate_and_sort_low_res_grayscale(photos):
    print("Rating and sorting photos")
    num_photos = len(photos)
    counter = 0
    printProgressBar(counter, num_photos)

    rated_sorted_photos = []

    # rate
    for photo in photos:
        level = get_avg_grayscale(photo[0])
        rated_sorted_photos.append((level, photo))

        counter = counter + 1
        printProgressBar(counter, num_photos)

    # sort
    rated_sorted_photos.sort(key=operator.itemgetter(0))
    return rated_sorted_photos
Ejemplo n.º 11
0
def create_averaged_imagesV1(img, block_averages, subimage_width):
    orig_height = img.size[1]
    orig_color = get_avg_grayscale(img)

    scaled_width = subimage_width
    scaled_height = int(orig_height * (float(subimage_width) / orig_height))

    # modify img to the scaled size
    img.thumbnail((scaled_width, scaled_height))

    averaged_images = []
    for row in range(len(block_averages)):
        averaged_images.append([])
        for col in range(len(block_averages[0])):
            scaled_img_cpy = img.copy()
            scaled_colored_img = raise_img_by_val(
                scaled_img_cpy, block_averages[row][col] - orig_color)
            averaged_images[row].append(scaled_colored_img)
        printProgressBar(row, len(block_averages) - 1)
    return averaged_images
Ejemplo n.º 12
0
def make_mini_photos_colored(photos_paths, subimage_width, split=0):
    num_photos = len(photos_paths)
    counter = 0
    printProgressBar(0, num_photos)

    mini_photos = []
    scaled_width = subimage_width
    scaled_height = scaled_width

    for photo_path in photos_paths:
        raw_photo = Image.open(photo_path).convert("RGB")
        raw_photo_mini = rescale(raw_photo, scaled_width, scaled_height)
        mini_photos.append(raw_photo_mini)

        if (split != 0):
            width, height = raw_photo.size
            # also append 4 sub photos
            rp_1 = raw_photo.crop((0, 0, int(width / 2), int(height / 2)))
            rp_1_mini = rescale(rp_1, scaled_width, scaled_height)
            mini_photos.append(rp_1_mini)

            rp_2 = raw_photo.crop((0, int(height / 2), int(width / 2), height))
            rp_2_mini = rescale(rp_2, scaled_width, scaled_height)
            mini_photos.append(rp_2_mini)

            rp_3 = raw_photo.crop((int(width / 2), 0, width, int(height / 2)))
            rp_3_mini = rescale(rp_3, scaled_width, scaled_height)
            mini_photos.append(rp_3_mini)

            rp_4 = raw_photo.crop(
                (int(width / 2), int(height / 2), width, height))
            rp_4_mini = rescale(rp_4, scaled_width, scaled_height)
            mini_photos.append(rp_4_mini)

        counter = counter + 1
        printProgressBar(counter, num_photos)

    return mini_photos