aidevices commited on
Commit
a6a2fc4
·
verified ·
1 Parent(s): 8f6ea70

Sync third-solution for HF Jobs Docker image

Browse files
Files changed (2) hide show
  1. .hf_space_build_stamp +4 -4
  2. src/preprocessing.py +14 -14
.hf_space_build_stamp CHANGED
@@ -1,4 +1,4 @@
1
- utc=2026-05-09T05:45:47.394877+00:00
2
- github_sha=85e7d7d60f17e78371c84f4a2311d3e4d10f7b65
3
- run_id=1
4
- nonce=6cf30304638d4189bdef757570e7e993
 
1
+ utc=2026-05-14T06:47:08.584557+00:00
2
+ github_sha=5e2fd1bdd1562ab345e46ad1c3057571109aed9f
3
+ run_id=25845990858
4
+ nonce=3d6556a0353248faa4f2724f288a63b7
src/preprocessing.py CHANGED
@@ -50,7 +50,7 @@ def find_grid(image, frame=False, possible_colors=None):
50
 
51
  def find_color_boundaries(array, color):
52
  """Looks for the boundaries of any color and returns them"""
53
- if (array == color).any() == False:
54
  return None
55
  ind_0 = np.arange(array.shape[0])
56
  ind_1 = np.arange(array.shape[1])
@@ -120,18 +120,18 @@ def get_half(image, side):
120
 
121
 
122
  def get_corner(image, side):
123
- """ returns the half of the image"""
124
  if side not in ["tl", "tr", "bl", "br"]:
125
  return 1, None
126
  size = (image.shape[0]) // 2, (image.shape[1]) // 2
127
  if side == "tl":
128
- return 0, image[size[0] :, -size[1] :]
129
  if side == "tr":
130
- return 0, image[size[0] :, : size[1]]
131
  if side == "bl":
132
- return 0, image[: -size[0], : size[1]]
133
  if side == "br":
134
- return 0, image[: -size[0], -size[1] :]
135
 
136
 
137
  def get_k_part(image, num, k):
@@ -445,7 +445,7 @@ def get_mask_from_max_color_coverage(image, color):
445
  boundaries = find_color_boundaries(image, color)
446
  result = (image.copy() * 0).astype(bool)
447
  result[boundaries[0] : boundaries[1] + 1, boundaries[2] : boundaries[3] + 1] = True
448
- return 0, image == color
449
  else:
450
  return 1, None
451
 
@@ -464,10 +464,10 @@ def add_unique_colors(image, result, colors=None):
464
  (image[-half_size[0] :], "top", unique_side),
465
  (image[:, : half_size[1]], "right", unique_side),
466
  (image[:, -half_size[1] :], "left", unique_side),
467
- (image[-half_size[0] :, -half_size[1] :], "tl", unique_corner),
468
- (image[-half_size[0] :, : half_size[1]], "tr", unique_corner),
469
- (image[: half_size[0], : half_size[1]], "br", unique_corner),
470
- (image[: half_size[0], -half_size[1] :], "left", unique_corner),
471
  ]:
472
  unique = np.uint8(np.unique(image_part))
473
  if len(unique) == len(colors) - 1:
@@ -1066,15 +1066,15 @@ def process_image(
1066
  """processes the original image and returns dict with structured image blocks"""
1067
 
1068
  result = get_color_scheme(image, target_image=target_image, params=color_params)
1069
- result = generate_blocks(image, result, max_time, max_blocks, max_masks, target_image, params, color_params)
1070
- result = generate_masks(image, result, max_time, max_blocks, max_masks, target_image, params, color_params)
1071
 
1072
  return result
1073
 
1074
 
1075
  def get_mask_from_block_params(image, params, block_cache=None, mask_cache=None, color_scheme=None):
1076
  if mask_cache is None:
1077
- mask_cache = {{"arrays": {}, "params": {}}}
1078
  dict_hash = get_dict_hash(params)
1079
  if dict_hash in mask_cache:
1080
  mask = mask_cache["arrays"][mask_cache["params"][dict_hash]]["array"]
 
50
 
51
  def find_color_boundaries(array, color):
52
  """Looks for the boundaries of any color and returns them"""
53
+ if not (array == color).any():
54
  return None
55
  ind_0 = np.arange(array.shape[0])
56
  ind_1 = np.arange(array.shape[1])
 
120
 
121
 
122
  def get_corner(image, side):
123
+ """Return one quadrant of the image; tl/tr/bl/br follow row-0-at-top conventions."""
124
  if side not in ["tl", "tr", "bl", "br"]:
125
  return 1, None
126
  size = (image.shape[0]) // 2, (image.shape[1]) // 2
127
  if side == "tl":
128
+ return 0, image[: size[0], : size[1]]
129
  if side == "tr":
130
+ return 0, image[: size[0], -size[1] :]
131
  if side == "bl":
132
+ return 0, image[-size[0] :, : size[1]]
133
  if side == "br":
134
+ return 0, image[-size[0] :, -size[1] :]
135
 
136
 
137
  def get_k_part(image, num, k):
 
445
  boundaries = find_color_boundaries(image, color)
446
  result = (image.copy() * 0).astype(bool)
447
  result[boundaries[0] : boundaries[1] + 1, boundaries[2] : boundaries[3] + 1] = True
448
+ return 0, result
449
  else:
450
  return 1, None
451
 
 
464
  (image[-half_size[0] :], "top", unique_side),
465
  (image[:, : half_size[1]], "right", unique_side),
466
  (image[:, -half_size[1] :], "left", unique_side),
467
+ (image[: half_size[0], : half_size[1]], "tl", unique_corner),
468
+ (image[: half_size[0], -half_size[1] :], "tr", unique_corner),
469
+ (image[-half_size[0] :, : half_size[1]], "bl", unique_corner),
470
+ (image[-half_size[0] :, -half_size[1] :], "br", unique_corner),
471
  ]:
472
  unique = np.uint8(np.unique(image_part))
473
  if len(unique) == len(colors) - 1:
 
1066
  """processes the original image and returns dict with structured image blocks"""
1067
 
1068
  result = get_color_scheme(image, target_image=target_image, params=color_params)
1069
+ result = generate_blocks(image, result, max_time, max_blocks, max_masks, target_image, params)
1070
+ result = generate_masks(image, result, max_time, max_blocks, max_masks, target_image, params)
1071
 
1072
  return result
1073
 
1074
 
1075
  def get_mask_from_block_params(image, params, block_cache=None, mask_cache=None, color_scheme=None):
1076
  if mask_cache is None:
1077
+ mask_cache = {"arrays": {}, "params": {}}
1078
  dict_hash = get_dict_hash(params)
1079
  if dict_hash in mask_cache:
1080
  mask = mask_cache["arrays"][mask_cache["params"][dict_hash]]["array"]