Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload Colony_Analyzer_AI2_HF.py
Browse files- Colony_Analyzer_AI2_HF.py +4 -11
Colony_Analyzer_AI2_HF.py
CHANGED
|
@@ -11,21 +11,14 @@ import cv2
|
|
| 11 |
from PIL import Image
|
| 12 |
|
| 13 |
|
| 14 |
-
def
|
| 15 |
-
width, height = img.size
|
| 16 |
-
if width < min_width or height < min_height:
|
| 17 |
-
return img.resize((max(width, min_width), max(height, min_height)), Image.BICUBIC)
|
| 18 |
-
return img
|
| 19 |
-
|
| 20 |
-
def pad(img_np):
|
| 21 |
"""
|
| 22 |
Pads a numpy image (grayscale or RGB) to 2048x1536 (width x height) with white pixels.
|
| 23 |
Pads at the bottom and right as needed.
|
| 24 |
"""
|
| 25 |
-
target_width, target_height = 2048, 1536
|
| 26 |
height, width = img_np.shape[:2]
|
| 27 |
-
pad_bottom = max(0,
|
| 28 |
-
pad_right = max(0,
|
| 29 |
# Padding: (top, bottom, left, right)
|
| 30 |
if img_np.ndim == 3:
|
| 31 |
# Color image (H, W, 3)
|
|
@@ -267,7 +260,7 @@ def main(args):
|
|
| 267 |
min_circ = args[2]
|
| 268 |
do_necrosis = args[3]
|
| 269 |
colonies = {}
|
| 270 |
-
img_map, i_num, j_num = cut_img(
|
| 271 |
for z in img_map:
|
| 272 |
img_map[z] = eval_img(img_map[z])
|
| 273 |
del z
|
|
|
|
| 11 |
from PIL import Image
|
| 12 |
|
| 13 |
|
| 14 |
+
def pad(img_np, tw=2048, th=1536):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"""
|
| 16 |
Pads a numpy image (grayscale or RGB) to 2048x1536 (width x height) with white pixels.
|
| 17 |
Pads at the bottom and right as needed.
|
| 18 |
"""
|
|
|
|
| 19 |
height, width = img_np.shape[:2]
|
| 20 |
+
pad_bottom = max(0, th - height)
|
| 21 |
+
pad_right = max(0, tw - width)
|
| 22 |
# Padding: (top, bottom, left, right)
|
| 23 |
if img_np.ndim == 3:
|
| 24 |
# Color image (H, W, 3)
|
|
|
|
| 260 |
min_circ = args[2]
|
| 261 |
do_necrosis = args[3]
|
| 262 |
colonies = {}
|
| 263 |
+
img_map, i_num, j_num = cut_img(pad(args[0],512,512))
|
| 264 |
for z in img_map:
|
| 265 |
img_map[z] = eval_img(img_map[z])
|
| 266 |
del z
|