Ritabrata04 commited on
Commit
39ab3eb
·
1 Parent(s): 1a8bca6

cast to uint8

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,13 +1,13 @@
1
  import gradio as gr
2
  import cv2
3
  from transforms import *
 
4
 
5
  # Wrapper function to call the correct transform
6
  def apply_transform(image, domain, transform):
7
  img, img_type = load_image(image)
8
 
9
- # Default value for result to avoid UnboundLocalError
10
- result = None
11
 
12
  if domain == 'Spatial':
13
  if transform == 'Histogram Equalization':
@@ -22,21 +22,29 @@ def apply_transform(image, domain, transform):
22
  result = median_filter(img)
23
  else:
24
  return "Invalid spatial transform selection."
25
-
26
  elif domain == 'Frequency':
27
  if transform == 'Fourier Transform':
28
  result = fourier_transform(img)
 
 
 
 
29
  elif transform == 'Discrete Cosine Transform':
30
  result = discrete_cosine_transform(img)
 
 
31
  elif transform == 'High-Pass Filter':
32
  result = high_pass_filter(img)
33
  elif transform == 'Low-Pass Filter':
34
  result = low_pass_filter(img)
35
  elif transform == 'Wavelet Transform':
36
  result = wavelet_transform(img)
 
 
37
  else:
38
  return "Invalid frequency transform selection."
39
-
40
  else:
41
  return "Invalid domain selection."
42
 
 
1
  import gradio as gr
2
  import cv2
3
  from transforms import *
4
+ import numpy as np
5
 
6
  # Wrapper function to call the correct transform
7
  def apply_transform(image, domain, transform):
8
  img, img_type = load_image(image)
9
 
10
+ result = None # Initialize result to avoid UnboundLocalError
 
11
 
12
  if domain == 'Spatial':
13
  if transform == 'Histogram Equalization':
 
22
  result = median_filter(img)
23
  else:
24
  return "Invalid spatial transform selection."
25
+
26
  elif domain == 'Frequency':
27
  if transform == 'Fourier Transform':
28
  result = fourier_transform(img)
29
+ # Normalize the Fourier transform result to fit within 0-255 for visualization
30
+ result = np.abs(result)
31
+ result = 255 * result / np.max(result)
32
+ result = result.astype(np.uint8)
33
  elif transform == 'Discrete Cosine Transform':
34
  result = discrete_cosine_transform(img)
35
+ result = 255 * result / np.max(result)
36
+ result = result.astype(np.uint8)
37
  elif transform == 'High-Pass Filter':
38
  result = high_pass_filter(img)
39
  elif transform == 'Low-Pass Filter':
40
  result = low_pass_filter(img)
41
  elif transform == 'Wavelet Transform':
42
  result = wavelet_transform(img)
43
+ result = 255 * result / np.max(result) # Normalize wavelet transform output
44
+ result = result.astype(np.uint8)
45
  else:
46
  return "Invalid frequency transform selection."
47
+
48
  else:
49
  return "Invalid domain selection."
50