Siyun He commited on
Commit
6861f2c
·
1 Parent(s): b893355

update code so the processed image can show by running evaluate.py

Browse files
Files changed (2) hide show
  1. ASCII_functions.py +8 -4
  2. evaluation.py +4 -1
ASCII_functions.py CHANGED
@@ -104,15 +104,19 @@ def format_ascii_art(ascii_str, width):
104
  ascii_art += ascii_str[i:i+width] + "\n"
105
  return ascii_art
106
 
107
-
108
- def generate_ascii_art(image):
109
- """Generate ASCII art from the given image."""
110
- # Ensure the input is a PIL Image object
111
  if not isinstance(image, Image.Image):
112
  image = Image.fromarray(image)
113
  grayscale_image = convert_to_grayscale(image)
114
  adjusted_image = adjust_contrast(grayscale_image)
115
  adjusted_image = resize_image(adjusted_image)
 
 
 
 
 
 
116
  ascii_str = map_pixels_to_ascii(adjusted_image)
117
  ascii_art = format_ascii_art(ascii_str, adjusted_image.width)
118
  return ascii_art
 
104
  ascii_art += ascii_str[i:i+width] + "\n"
105
  return ascii_art
106
 
107
+ def process_image(image):
108
+ """Process the input image to prepare it for ASCII art generation."""
 
 
109
  if not isinstance(image, Image.Image):
110
  image = Image.fromarray(image)
111
  grayscale_image = convert_to_grayscale(image)
112
  adjusted_image = adjust_contrast(grayscale_image)
113
  adjusted_image = resize_image(adjusted_image)
114
+ return adjusted_image
115
+
116
+ def generate_ascii_art(image):
117
+ """Generate ASCII art from the given image."""
118
+ # Ensure the input is a PIL Image object
119
+ adjusted_image = process_image(image)
120
  ascii_str = map_pixels_to_ascii(adjusted_image)
121
  ascii_art = format_ascii_art(ascii_str, adjusted_image.width)
122
  return ascii_art
evaluation.py CHANGED
@@ -1,4 +1,4 @@
1
- from ASCII_functions import generate_ascii_art, calculate_similarity
2
  from PIL import Image
3
  import argparse
4
 
@@ -14,6 +14,9 @@ if __name__ == "__main__":
14
 
15
  ascii_art = generate_ascii_art(original_image)
16
 
 
 
 
17
  print(ascii_art)
18
 
19
  ssim_value, mse = calculate_similarity(original_image, ascii_art)
 
1
+ from ASCII_functions import generate_ascii_art, calculate_similarity, process_image
2
  from PIL import Image
3
  import argparse
4
 
 
14
 
15
  ascii_art = generate_ascii_art(original_image)
16
 
17
+ adjusted_image = process_image(original_image)
18
+ adjusted_image.show()
19
+
20
  print(ascii_art)
21
 
22
  ssim_value, mse = calculate_similarity(original_image, ascii_art)