ahmedxeno commited on
Commit
0e7f8ec
·
verified ·
1 Parent(s): 9c8b4c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -3,8 +3,12 @@ import numpy as np
3
  import gradio as gr
4
  import pywt
5
  from skimage import exposure
 
6
 
7
  def musica_enhancement(img):
 
 
 
8
  # Convert from RGB to grayscale if needed
9
  if len(img.shape) == 3:
10
  img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
@@ -46,20 +50,27 @@ def musica_enhancement(img):
46
  return img_sharp
47
 
48
  def process_image(input_img):
 
 
 
 
49
  enhanced_img = musica_enhancement(input_img)
 
 
 
 
50
  return input_img, enhanced_img
51
 
52
  # Gradio Interface
53
  demo = gr.Interface(
54
  fn=process_image,
55
- inputs=gr.Image(label="Upload X-ray"),
56
  outputs=[
57
  gr.Image(label="Original Image"),
58
  gr.Image(label="Enhanced Image")
59
  ],
60
- examples=[["./sample_xray.jpg"]],
61
  title="X-ray Enhancement (MUSICA®-Style)",
62
- description="Medical X-ray enhancement using multi-scale wavelet processing and adaptive contrast adjustment"
63
  )
64
 
65
  demo.launch()
 
3
  import gradio as gr
4
  import pywt
5
  from skimage import exposure
6
+ from PIL import Image
7
 
8
  def musica_enhancement(img):
9
+ # Convert PIL Image to NumPy array
10
+ img = np.array(img)
11
+
12
  # Convert from RGB to grayscale if needed
13
  if len(img.shape) == 3:
14
  img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
 
50
  return img_sharp
51
 
52
  def process_image(input_img):
53
+ # Convert Gradio input (PIL Image) to NumPy array
54
+ input_img = np.array(input_img)
55
+
56
+ # Enhance the image
57
  enhanced_img = musica_enhancement(input_img)
58
+
59
+ # Convert enhanced image back to PIL for display
60
+ enhanced_img = Image.fromarray(enhanced_img)
61
+
62
  return input_img, enhanced_img
63
 
64
  # Gradio Interface
65
  demo = gr.Interface(
66
  fn=process_image,
67
+ inputs=gr.Image(label="Upload X-ray (TIFF or JPEG/PNG)"),
68
  outputs=[
69
  gr.Image(label="Original Image"),
70
  gr.Image(label="Enhanced Image")
71
  ],
 
72
  title="X-ray Enhancement (MUSICA®-Style)",
73
+ description="Upload a TIFF, JPEG, or PNG X-ray image to enhance it using multi-scale wavelet processing and adaptive contrast adjustment."
74
  )
75
 
76
  demo.launch()