lyimo commited on
Commit
2032cc0
·
verified ·
1 Parent(s): fdefea8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -7,7 +7,7 @@ from skimage.restoration import denoise_nl_means, estimate_sigma
7
  def add_noise(image, mean, var):
8
  sigma = var ** 0.5
9
  noisy_image = random_noise(np.array(image), mode='gaussian', mean=mean, var=var)
10
- noisy_image = (255 * noisy_image).astype(np.uint8)
11
  return Image.fromarray(noisy_image)
12
 
13
  def remove_noise(image):
@@ -16,17 +16,21 @@ def remove_noise(image):
16
  sigma_est = np.mean(estimate_sigma(image_np, multichannel=False))
17
  denoised_image = denoise_nl_means(image_np, h=1.15 * sigma_est, fast_mode=True,
18
  patch_size=5, patch_distance=6, multichannel=False)
19
- denoised_image = (255 * denoised_image).astype(np.uint8)
20
  return Image.fromarray(denoised_image)
21
 
 
22
  interface = gr.Interface(
23
  fn=add_noise,
24
- inputs=[gr.Image(label="Original Image"),
 
25
  gr.Slider(0, 0.05, step=0.001, value=0, label="Mean of Gaussian Noise"),
26
- gr.Slider(0, 0.01, step=0.0001, value=0.001, label="Variance of Gaussian Noise"),
 
27
  outputs=gr.Image(label="Processed Image"),
28
  title="Image Noise Addition and Removal",
29
  description="Add Gaussian noise to an image and attempt to remove it. Adjust the mean and variance for different effects."
30
  )
31
 
 
32
  interface.launch()
 
7
  def add_noise(image, mean, var):
8
  sigma = var ** 0.5
9
  noisy_image = random_noise(np.array(image), mode='gaussian', mean=mean, var=var)
10
+ noisy_image = (255 * noisy_image).astype(np.uint8) # Scale back to 0-255
11
  return Image.fromarray(noisy_image)
12
 
13
  def remove_noise(image):
 
16
  sigma_est = np.mean(estimate_sigma(image_np, multichannel=False))
17
  denoised_image = denoise_nl_means(image_np, h=1.15 * sigma_est, fast_mode=True,
18
  patch_size=5, patch_distance=6, multichannel=False)
19
+ denoised_image = (255 * denoised_image).astype(np.uint8) # Scale back to 0-255
20
  return Image.fromarray(denoised_image)
21
 
22
+ # Define Gradio interface
23
  interface = gr.Interface(
24
  fn=add_noise,
25
+ inputs=[
26
+ gr.Image(label="Original Image"),
27
  gr.Slider(0, 0.05, step=0.001, value=0, label="Mean of Gaussian Noise"),
28
+ gr.Slider(0, 0.01, step=0.0001, value=0.001, label="Variance of Gaussian Noise")
29
+ ],
30
  outputs=gr.Image(label="Processed Image"),
31
  title="Image Noise Addition and Removal",
32
  description="Add Gaussian noise to an image and attempt to remove it. Adjust the mean and variance for different effects."
33
  )
34
 
35
+ # Launch the app
36
  interface.launch()