Fixed chaching bug when chach file did not exist yet.
Start of the alternative ant rander selection which pixels need duplication.
This commit is contained in:
parent
a7d200ca82
commit
242566643c
1 changed files with 15 additions and 1 deletions
|
|
@ -66,11 +66,15 @@ def load_cached_point_arrays():
|
||||||
|
|
||||||
|
|
||||||
def save_cached_point_arrays(cached_point_arrays):
|
def save_cached_point_arrays(cached_point_arrays):
|
||||||
|
if not os.path.isfile(CACHE_FILE_PATH):
|
||||||
|
open(CACHE_FILE_PATH, "x").close()
|
||||||
|
|
||||||
with open(CACHE_FILE_PATH, "w") as file:
|
with open(CACHE_FILE_PATH, "w") as file:
|
||||||
json.dump(cached_point_arrays, file)
|
json.dump(cached_point_arrays, file)
|
||||||
|
|
||||||
|
|
||||||
def generate_point_array_from_image(image):
|
def generate_point_array_from_image(image):
|
||||||
|
image.load()
|
||||||
image = image.convert("RGB") # Convert image to RGB color mode
|
image = image.convert("RGB") # Convert image to RGB color mode
|
||||||
image_hash = get_image_hash(image)
|
image_hash = get_image_hash(image)
|
||||||
cached_point_arrays = load_cached_point_arrays()
|
cached_point_arrays = load_cached_point_arrays()
|
||||||
|
|
@ -83,10 +87,12 @@ def generate_point_array_from_image(image):
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
pixel_array = []
|
pixel_array = []
|
||||||
|
|
||||||
|
image.save(f"/home/cisco/CiscoTheProot/animations/loaded.png")
|
||||||
|
|
||||||
for y in range(height):
|
for y in range(height):
|
||||||
for x in range(width):
|
for x in range(width):
|
||||||
pixel = image.getpixel((x, y))
|
pixel = image.getpixel((x, y))
|
||||||
if pixel != (0, 0, 0): # any non-white pixels
|
if sum(pixel) > 15: # any pixel which total color value is greater than 15.
|
||||||
point = {"x": x, "y": y, "color": pixel}
|
point = {"x": x, "y": y, "color": pixel}
|
||||||
pixel_array.append(point)
|
pixel_array.append(point)
|
||||||
|
|
||||||
|
|
@ -131,6 +137,14 @@ def pair_points(points1: list[Point2D], points2: list[Point2D]) -> list[tuple[Po
|
||||||
for j in range(size2):
|
for j in range(size2):
|
||||||
cost_matrix[i, j] = points1[i].distance(points2[j])
|
cost_matrix[i, j] = points1[i].distance(points2[j])
|
||||||
|
|
||||||
|
# Solve the assignment problem using the Hungarian algorithm
|
||||||
|
row_ind, col_ind = linear_sum_assignment(cost_matrix)
|
||||||
|
|
||||||
|
# Create pairs of points based on the optimal assignment
|
||||||
|
pairs = []
|
||||||
|
for i, j in zip(row_ind, col_ind):
|
||||||
|
pairs.append((points1[i], points2[j]))
|
||||||
|
|
||||||
# Duplicate points in the smaller array to match the size of the larger array
|
# Duplicate points in the smaller array to match the size of the larger array
|
||||||
if size1 > size2:
|
if size1 > size2:
|
||||||
num_duplicates = size1 - size2
|
num_duplicates = size1 - size2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue