Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -300,31 +300,13 @@ def generate_images(label_str, num_images, progress=gr.Progress()):
|
|
300 |
|
301 |
processed_images = []
|
302 |
for img in images:
|
303 |
-
# Convert to
|
|
|
304 |
img_np = img.cpu().permute(1, 2, 0).mean(dim=-1).numpy()
|
305 |
-
|
306 |
-
# Normalize to 0-255
|
307 |
img_np = (img_np * 255).clip(0, 255).astype(np.uint8)
|
308 |
|
309 |
-
#
|
310 |
-
|
311 |
-
bone_cmap = np.array([
|
312 |
-
[0, 0, 0], # Black
|
313 |
-
[25, 25, 51], # Dark blue-gray
|
314 |
-
[50, 50, 102], # Medium blue-gray
|
315 |
-
[76, 76, 153], # Blue-gray
|
316 |
-
[101, 101, 204], # Light blue-gray
|
317 |
-
[127, 127, 255], # Very light blue
|
318 |
-
[153, 178, 255], # Blue-white
|
319 |
-
[178, 204, 255], # Light blue-white
|
320 |
-
[204, 229, 255], # Very light blue-white
|
321 |
-
[229, 255, 255], # Almost white
|
322 |
-
[255, 255, 255] # White
|
323 |
-
], dtype=np.uint8)
|
324 |
-
|
325 |
-
# Apply colormap
|
326 |
-
colored = bone_cmap[(img_np * (len(bone_cmap)-1) / 255].astype(np.uint8)
|
327 |
-
pil_img = Image.fromarray(colored)
|
328 |
|
329 |
processed_images.append(pil_img)
|
330 |
|
|
|
300 |
|
301 |
processed_images = []
|
302 |
for img in images:
|
303 |
+
# Convert to grayscale (X-rays are naturally grayscale)
|
304 |
+
# Take the mean across RGB channels and convert to uint8
|
305 |
img_np = img.cpu().permute(1, 2, 0).mean(dim=-1).numpy()
|
|
|
|
|
306 |
img_np = (img_np * 255).clip(0, 255).astype(np.uint8)
|
307 |
|
308 |
+
# Create PIL image in grayscale mode
|
309 |
+
pil_img = Image.fromarray(img_np, mode='L')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
|
311 |
processed_images.append(pil_img)
|
312 |
|