ahmedxeno commited on
Commit
16bd718
·
verified ·
1 Parent(s): 3ac0e79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -18,13 +18,15 @@ def musica_enhancement(image):
18
  print(f"Uploaded image shape: {img.shape}, dtype: {img.dtype}")
19
  print(f"Image min: {img.min()}, max: {img.max()}")
20
 
21
- # Check if the image is grayscale
22
- if len(img.shape) != 2:
23
- raise ValueError("Uploaded image must be a grayscale image.")
 
24
 
25
  # Ensure the image has 16-bit depth
26
  if img.dtype != np.uint16:
27
- raise ValueError("Uploaded image must be a 16-bit TIFF image.")
 
28
 
29
  # Normalize to [0, 1]
30
  img_norm = img.astype(np.float32) / 65535.0
@@ -50,7 +52,6 @@ def musica_enhancement(image):
50
 
51
  # Convert to 8-bit
52
  img_gamma_8bit = (img_gamma * 255).astype(np.uint8)
53
- print(f"Final image min: {img_gamma_8bit.min()}, max: {img_gamma_8bit.max()}")
54
 
55
  # Convert to RGB for better viewing compatibility
56
  img_rgb = cv2.cvtColor(img_gamma_8bit, cv2.COLOR_GRAY2RGB)
@@ -72,6 +73,8 @@ def musica_enhancement(image):
72
  return enhanced_image, histogram
73
 
74
 
 
 
75
  # Define Gradio interface
76
  with gr.Blocks() as demo:
77
  gr.Markdown("# Musica Image Enhancement")
 
18
  print(f"Uploaded image shape: {img.shape}, dtype: {img.dtype}")
19
  print(f"Image min: {img.min()}, max: {img.max()}")
20
 
21
+ # Convert RGB to grayscale if necessary
22
+ if len(img.shape) == 3 and img.shape[2] == 3: # Check for RGB
23
+ img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
24
+ print("Converted RGB image to grayscale.")
25
 
26
  # Ensure the image has 16-bit depth
27
  if img.dtype != np.uint16:
28
+ img = img.astype(np.uint16) # Scale if necessary
29
+ print("Converted image to 16-bit.")
30
 
31
  # Normalize to [0, 1]
32
  img_norm = img.astype(np.float32) / 65535.0
 
52
 
53
  # Convert to 8-bit
54
  img_gamma_8bit = (img_gamma * 255).astype(np.uint8)
 
55
 
56
  # Convert to RGB for better viewing compatibility
57
  img_rgb = cv2.cvtColor(img_gamma_8bit, cv2.COLOR_GRAY2RGB)
 
73
  return enhanced_image, histogram
74
 
75
 
76
+
77
+
78
  # Define Gradio interface
79
  with gr.Blocks() as demo:
80
  gr.Markdown("# Musica Image Enhancement")