Spaces:
Running
Running
Sagar Bharadwaj
commited on
Commit
·
db4d0c4
1
Parent(s):
2fd9854
Added image downsampling
Browse files- colorbynumber/main.py +2 -1
- colorbynumber/simplify_image.py +16 -0
colorbynumber/main.py
CHANGED
|
@@ -2,7 +2,7 @@ import cv2 as cv
|
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
from .config import default_config
|
| 5 |
-
from .simplify_image import simplify_image
|
| 6 |
from .gen_islands import GenerateIslands
|
| 7 |
from .numbered_islands import create_islands, add_numbers_to_image
|
| 8 |
|
|
@@ -26,6 +26,7 @@ class ColorByNumber:
|
|
| 26 |
|
| 27 |
image = cv.imread(self.image_path)
|
| 28 |
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
|
|
|
|
| 29 |
self.image = image
|
| 30 |
|
| 31 |
def create_color_by_number(self):
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
from .config import default_config
|
| 5 |
+
from .simplify_image import simplify_image, downsample_image
|
| 6 |
from .gen_islands import GenerateIslands
|
| 7 |
from .numbered_islands import create_islands, add_numbers_to_image
|
| 8 |
|
|
|
|
| 26 |
|
| 27 |
image = cv.imread(self.image_path)
|
| 28 |
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
|
| 29 |
+
image = downsample_image(image)
|
| 30 |
self.image = image
|
| 31 |
|
| 32 |
def create_color_by_number(self):
|
colorbynumber/simplify_image.py
CHANGED
|
@@ -73,6 +73,22 @@ def _denoise_image(image, h, denoise_type, blur_size = None):
|
|
| 73 |
|
| 74 |
return denoised_image
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
def simplify_image(image,
|
| 77 |
color_list = None,
|
| 78 |
num_colors = None,
|
|
|
|
| 73 |
|
| 74 |
return denoised_image
|
| 75 |
|
| 76 |
+
def downsample_image(image):
|
| 77 |
+
"""
|
| 78 |
+
Downsample the image so the max dimension is 1000 pixels.
|
| 79 |
+
"""
|
| 80 |
+
max_dim = 1000
|
| 81 |
+
width, height = image.shape[:2]
|
| 82 |
+
if width > height:
|
| 83 |
+
new_width = max_dim
|
| 84 |
+
new_height = int(height * (new_width / width))
|
| 85 |
+
else:
|
| 86 |
+
new_height = max_dim
|
| 87 |
+
new_width = int(width * (new_height / height))
|
| 88 |
+
|
| 89 |
+
image = cv.resize(image, (new_height, new_width), interpolation = cv.INTER_AREA)
|
| 90 |
+
return image
|
| 91 |
+
|
| 92 |
def simplify_image(image,
|
| 93 |
color_list = None,
|
| 94 |
num_colors = None,
|