Vedansh-7 commited on
Commit
3be1428
·
1 Parent(s): 6be9857

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -300,9 +300,32 @@ def generate_images(label_str, num_images, progress=gr.Progress()):
300
 
301
  processed_images = []
302
  for img in images:
303
- img_np = img.cpu().permute(1, 2, 0).numpy()
 
 
 
304
  img_np = (img_np * 255).clip(0, 255).astype(np.uint8)
305
- pil_img = Image.fromarray(img_np)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  processed_images.append(pil_img)
307
 
308
  if num_images == 1:
 
300
 
301
  processed_images = []
302
  for img in images:
303
+ # Convert to numpy and remove channel dimension (3,128,128 -> 128,128)
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
+ # Apply bone colormap approximation (without matplotlib)
310
+ # This is a simplified version of the bone colormap
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
 
331
  if num_images == 1: