lyimo commited on
Commit
4064d1f
·
verified ·
1 Parent(s): 915a80d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -24,11 +24,15 @@ def add_noise(image, password):
24
 
25
  def remove_noise(noisy_image, password):
26
  """Attempt to remove noise from the image using the same password."""
 
 
 
 
27
  seed = hash_password(password) % (2**32)
28
  np.random.seed(seed) # Reset the seed to generate the same noise parameters
29
  mean = np.random.uniform(-0.05, 0.05)
30
  var = np.random.uniform(0.001, 0.01)
31
- image = noisy_image.convert('L')
32
  image_np = np.array(image)
33
  sigma_est = np.mean(estimate_sigma(image_np, multichannel=False))
34
  denoised_image = denoise_nl_means(image_np, h=1.15 * sigma_est, fast_mode=True,
@@ -36,6 +40,7 @@ def remove_noise(noisy_image, password):
36
  denoised_image = (255 * denoised_image).astype(np.uint8) # Scale back to 0-255
37
  return Image.fromarray(denoised_image)
38
 
 
39
  # Define Gradio interface with tabs for adding and removing noise
40
  with gr.Blocks() as interface:
41
  gr.Markdown("### Image Noise Encryption and Decryption App")
 
24
 
25
  def remove_noise(noisy_image, password):
26
  """Attempt to remove noise from the image using the same password."""
27
+ # Check if the noisy_image is a numpy array and convert it to PIL Image if so
28
+ if isinstance(noisy_image, np.ndarray):
29
+ noisy_image = Image.fromarray(noisy_image.astype('uint8'))
30
+
31
  seed = hash_password(password) % (2**32)
32
  np.random.seed(seed) # Reset the seed to generate the same noise parameters
33
  mean = np.random.uniform(-0.05, 0.05)
34
  var = np.random.uniform(0.001, 0.01)
35
+ image = noisy_image.convert('L') # Ensure image is in grayscale
36
  image_np = np.array(image)
37
  sigma_est = np.mean(estimate_sigma(image_np, multichannel=False))
38
  denoised_image = denoise_nl_means(image_np, h=1.15 * sigma_est, fast_mode=True,
 
40
  denoised_image = (255 * denoised_image).astype(np.uint8) # Scale back to 0-255
41
  return Image.fromarray(denoised_image)
42
 
43
+
44
  # Define Gradio interface with tabs for adding and removing noise
45
  with gr.Blocks() as interface:
46
  gr.Markdown("### Image Noise Encryption and Decryption App")