-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
22 lines (17 loc) · 744 Bytes
/
Copy pathmain.py
File metadata and controls
22 lines (17 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from PIL import Image
from utils import compress_image_kmeans, show_images_side_by_side, show_centroid_colors
from IPython.display import display
# Function to run the compression
def run_image_compression(image_path, k):
image = Image.open(image_path)
compressed_image, kmeans = compress_image_kmeans(image, k=k)
# Display the compressed image
display(compressed_image)
# Display the centroid colors
show_centroid_colors(kmeans)
# Compare the original image and the compressed image side by side
show_images_side_by_side(image, compressed_image)
if __name__ == "__main__":
# Example usage
run_image_compression('images/ikeashark.JPG', 16)
run_image_compression('images/pancake_burger.JPG', 16)