Alexandros Popov commited on
Commit
d274a6d
·
1 Parent(s): 69ebb65

muted noisy tools.

Browse files
Files changed (3) hide show
  1. agents.py +0 -3
  2. filters.py +62 -39
  3. judges.py +0 -4
agents.py CHANGED
@@ -261,11 +261,8 @@ picture_operator = CodeAgent(
261
  flt.adjust_exposure,
262
  flt.adjust_saturation,
263
  flt.adjust_shadows_highlights,
264
- flt.adjust_temperature,
265
- flt.adjust_tint,
266
  flt.adjust_hue_color,
267
  flt.adjust_saturation_color,
268
- flt.adjust_luminance_color,
269
  flt.add_vignette,
270
  flt.add_grain,
271
  flt.save_image,
 
261
  flt.adjust_exposure,
262
  flt.adjust_saturation,
263
  flt.adjust_shadows_highlights,
 
 
264
  flt.adjust_hue_color,
265
  flt.adjust_saturation_color,
 
266
  flt.add_vignette,
267
  flt.add_grain,
268
  flt.save_image,
filters.py CHANGED
@@ -139,7 +139,7 @@ def adjust_shadows_highlights(
139
  # ---------------------------------------------------------------------------
140
 
141
 
142
- @tool
143
  def adjust_temperature(img: Image.Image, delta: int) -> Image.Image:
144
  """Shift white‑balance temperature.
145
 
@@ -157,7 +157,7 @@ def adjust_temperature(img: Image.Image, delta: int) -> Image.Image:
157
  return _to_image(arr * np.array([r_scale, 1.0, b_scale], dtype=np.float32))
158
 
159
 
160
- @tool
161
  def adjust_tint(img: Image.Image, delta: int) -> Image.Image:
162
  """Shift white‑balance tint between green and magenta.
163
 
@@ -303,7 +303,6 @@ def adjust_saturation_color(
303
  return adjust_hsl_channel(h, s, li, _range_for(color), s_factor=factor)
304
 
305
 
306
- @tool
307
  def adjust_luminance_color(
308
  h: np.ndarray, s: np.ndarray, li: np.ndarray, color: ColorName, factor: float
309
  ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
@@ -314,7 +313,7 @@ def adjust_luminance_color(
314
  s (np.ndarray): Saturation channel `[0, 1]`.
315
  li (np.ndarray): Lightness channel `[0, 1]`.
316
  color (ColorName): Colour family to target[red, orange, yellow, green, aqua, blue, purple, magenta]
317
- factor (float): Luminance multiplier. A factor of 0.5 is a lot, 0.9 is a delicate modification .
318
 
319
  Returns:
320
  Tuple[np.ndarray, np.ndarray, np.ndarray]: Hue, Saturation, Lightness
@@ -450,7 +449,7 @@ def load_image(path: str) -> Image.Image:
450
  # ---------------------------------------------------------------------------
451
 
452
 
453
- def demo_all(input_path: str, output_dir: str | Path = "demo_out") -> dict[str, str]:
454
  """Run every adjustment once and save results.
455
 
456
  Args:
@@ -461,36 +460,63 @@ def demo_all(input_path: str, output_dir: str | Path = "demo_out") -> dict[str,
461
  Returns:
462
  Dict[str, str]: Mapping of effect name to the saved file path.
463
  """
464
- output_path = Path(output_dir)
465
- output_path.mkdir(parents=True, exist_ok=True)
466
- img = Image.open(input_path).convert("RGB")
467
-
468
- effects = {
469
- "contrast": adjust_contrast(img, 0.7),
470
- "exposure": adjust_exposure(img, 0.05),
471
- # "saturation": adjust_saturation(img, ),
472
- "shadows_highlights": adjust_shadows_highlights(img, 1.3, 0.5),
473
- "temperature": adjust_temperature(img, -700),
474
- "tint": adjust_tint(img, 150),
475
- "vignette": add_vignette(img, 0.1),
476
- "grain": add_grain(img, 0.02),
477
- "blue_saturation": adjust_saturation_color(img, "yellow", 0.2),
478
- # "blue_saturation": adjust_saturation_color(img, "green", 0.2),
479
- # "blue_saturation": adjust_saturation_color(img, "orange", 0.2),
480
- # "blue_hue": adjust_hue_color(img, "blue", 15),
481
- # "blue_saturation": adjust_saturation_color(img, "blue", 1.2),
482
- "blue_luminance": adjust_luminance_color(img, "yellow", 1.1),
483
- }
484
-
485
- saved: dict[str, str] = {}
486
- stem = Path(input_path).stem
487
- for name, im in effects.items():
488
- file_path = output_path / f"{stem}_{name}.jpg"
489
- im.save(file_path, quality=95)
490
- im.show(title=name)
491
- saved[name] = str(file_path)
492
-
493
- return saved
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
494
 
495
 
496
  if __name__ == "__main__":
@@ -511,7 +537,4 @@ if __name__ == "__main__":
511
  if not args.output_dir:
512
  args.output_dir = tempfile.mkdtemp(prefix="photo_adjustments_")
513
 
514
- results = demo_all(args.input, args.output_dir)
515
-
516
- for effect, path in results.items():
517
- print(f"{effect}: {path}")
 
139
  # ---------------------------------------------------------------------------
140
 
141
 
142
+ # @tool
143
  def adjust_temperature(img: Image.Image, delta: int) -> Image.Image:
144
  """Shift white‑balance temperature.
145
 
 
157
  return _to_image(arr * np.array([r_scale, 1.0, b_scale], dtype=np.float32))
158
 
159
 
160
+ # @tool
161
  def adjust_tint(img: Image.Image, delta: int) -> Image.Image:
162
  """Shift white‑balance tint between green and magenta.
163
 
 
303
  return adjust_hsl_channel(h, s, li, _range_for(color), s_factor=factor)
304
 
305
 
 
306
  def adjust_luminance_color(
307
  h: np.ndarray, s: np.ndarray, li: np.ndarray, color: ColorName, factor: float
308
  ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
 
313
  s (np.ndarray): Saturation channel `[0, 1]`.
314
  li (np.ndarray): Lightness channel `[0, 1]`.
315
  color (ColorName): Colour family to target[red, orange, yellow, green, aqua, blue, purple, magenta]
316
+ factor (float): Luminance multiplier. The allowed maximum is 0.1 variation. 0.05 is a delicate modication.
317
 
318
  Returns:
319
  Tuple[np.ndarray, np.ndarray, np.ndarray]: Hue, Saturation, Lightness
 
449
  # ---------------------------------------------------------------------------
450
 
451
 
452
+ def demo_all(input_path: str, output_dir: str | Path = "demo_out") -> None:
453
  """Run every adjustment once and save results.
454
 
455
  Args:
 
460
  Returns:
461
  Dict[str, str]: Mapping of effect name to the saved file path.
462
  """
463
+ img = load_image(path=input_path)
464
+
465
+ # Apply global RGB adjustments in sequence
466
+ # 2. Reduced exposure (moderately)
467
+ img = adjust_exposure(img=img, ev=0.05) # Decreased from 0.1 as per feedback
468
+
469
+ # 1. Reduced contrast (significantly)
470
+ img = adjust_contrast(img=img, factor=1.03) # From 1.1 to 1.03 (delicate contrast increase)
471
+
472
+ # 3. Reduced global saturation
473
+ img = adjust_saturation(img=img, factor=1.1) # From 1.2 to 1.1 (moderate enhancement)
474
+
475
+ # 5. Subtler shadows/highlights
476
+ img = adjust_shadows_highlights(img=img, shadow=1.05, highlight=0.95) # From 1.1 # From 0.9 to 0.95
477
+
478
+ # 7. Remove vignette
479
+ img = add_vignette(img=img, strength=0.0) # Set to min per feedback
480
+
481
+ # 8. Remove grain
482
+ img = add_grain(img=img, amount=0.0) # No grain
483
+
484
+ # Convert to HSL for color-specific modifications
485
+ h, s, li = rgb_to_hsl(img)
486
+
487
+ # 3(a) Reduced blue saturation
488
+ h, s, li = adjust_saturation_color(h=h, s=s, li=li, color="blue", factor=1.3) # From 1.5 to 1.3
489
+
490
+ # 3(b) Reduced red & yellow saturation
491
+ for color in ["red", "yellow"]:
492
+ h, s, li = adjust_saturation_color(h=h, s=s, li=li, color=color, factor=1.1) # From 1.2 to 1.1
493
+
494
+ # 4. Adjusted hue (reduced intensity)
495
+ # Red/orange toward amber
496
+ h, s, li = adjust_hue_color(h=h, s=s, li=li, color="red", delta=10) # From 15° to 10°
497
+ h, s, li = adjust_hue_color(h=h, s=s, li=li, color="orange", delta=10) # From 15° to 10°
498
+
499
+ # Blue cooling (reduced effect)
500
+ h, s, li = adjust_hue_color(h=h, s=s, li=li, color="blue", delta=-10) # From -15° to -10°
501
+
502
+ # 6. Adjusted luminance (reduced effect)
503
+ # Blue luminance boost (reduced)
504
+ # h, s, li = adjust_luminance_color(
505
+ # h=h, s=s, li=li,
506
+ # color='blue',
507
+ # factor=1.05 # From 1.1 to 1.05
508
+ # )
509
+
510
+ # # Orange luminance (adjusted)
511
+ # h, s, li = adjust_luminance_color(
512
+ # h=h, s=s, li=li,
513
+ # color='orange',
514
+ # factor=0.95 # From 0.9 to 0.95
515
+ # )
516
+
517
+ # Save the processed image
518
+ print(output_dir)
519
+ save_image(h, s, li, output_directory=output_dir)
520
 
521
 
522
  if __name__ == "__main__":
 
537
  if not args.output_dir:
538
  args.output_dir = tempfile.mkdtemp(prefix="photo_adjustments_")
539
 
540
+ demo_all(args.input, args.output_dir)
 
 
 
judges.py CHANGED
@@ -109,11 +109,8 @@ def call_to_director(image_path: str, user_prompt):
109
  "- adjust_exposure\n"
110
  "- adjust_saturation\n"
111
  "- adjust_shadows_highlights\n"
112
- "- adjust_temperature\n"
113
- "- adjust_tint\n"
114
  "- adjust_hue_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]\n"
115
  "- adjust_saturation_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]'n"
116
- "- adjust_luminance_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]\n"
117
  "- add_vignette\n"
118
  "- add_grain\n"
119
  "In particular, you should use the methods that adjust colors luminance staturation and hue. "
@@ -181,7 +178,6 @@ def critic(output_directory: str, original_image_path: str, user_prompt: str, li
181
  "- adjust_tint\n"
182
  "- adjust_hue_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]\n"
183
  "- adjust_saturation_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]'n"
184
- "- adjust_luminance_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]\n"
185
  "- add_vignette\n"
186
  "- add_grain\n"
187
  "FOR EACH, you must say what should be done to improve the image"
 
109
  "- adjust_exposure\n"
110
  "- adjust_saturation\n"
111
  "- adjust_shadows_highlights\n"
 
 
112
  "- adjust_hue_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]\n"
113
  "- adjust_saturation_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]'n"
 
114
  "- add_vignette\n"
115
  "- add_grain\n"
116
  "In particular, you should use the methods that adjust colors luminance staturation and hue. "
 
178
  "- adjust_tint\n"
179
  "- adjust_hue_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]\n"
180
  "- adjust_saturation_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]'n"
 
181
  "- add_vignette\n"
182
  "- add_grain\n"
183
  "FOR EACH, you must say what should be done to improve the image"