eho69 commited on
Commit
e10024a
·
verified ·
1 Parent(s): fb83b42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -44
app.py CHANGED
@@ -82,63 +82,63 @@ def detect_objects(image):
82
 
83
  return annotated_image, summary
84
 
85
- # def scan_edges(image):
86
- # """
87
- # Simple edge detection using OpenCV
88
- # """
89
- # # Convert PIL image to numpy array
90
- # if isinstance(image, Image.Image):
91
- # image = np.array(image)
92
 
93
- # # Convert to grayscale
94
- # gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
95
 
96
- # clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
97
 
98
- # # Apply Gaussian blur
99
- # blurred = cv2.GaussianBlur(gray, (5, 5), 0)
100
 
101
- # enhanced = clahe.apply(gray_image)
102
 
103
- # # Edge detection using Canny
104
- # edges = cv2.Canny(enhanced, 50, 150)
105
 
106
- # # Convert back to RGB for display
107
- # edges_rgb = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
108
 
109
- # return edges_rgb
110
 
111
- def scan_edges(image):
112
 
113
- # --- 1. Convert PIL image to numpy array if needed ---
114
- if isinstance(image, Image.Image):
115
- image = np.array(image)
116
 
117
- # --- 2. Convert to grayscale ---
118
- gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
119
 
120
- # --- 3. Gaussian blur BEFORE CLAHE to reduce high-freq noise ---
121
- # that CLAHE would otherwise amplify
122
- blurred = cv2.GaussianBlur(gray, (5, 5), 0)
123
 
124
- # --- 4. Apply CLAHE on the blurred image ---
125
- # clipLimit=2.0 → controls noise amplification in flat regions
126
- # tileGridSize → 8x8 tiles work well for engine block scale features;
127
- # increase (e.g. 16x16) if bearing saddles are small
128
- # relative to full image resolution
129
- clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
130
- enhanced = clahe.apply(blurred)
131
-
132
- # --- 5. Canny edge detection on CLAHE-enhanced image ---
133
- # Lower threshold (30) helps recover weak edges in shadow regions
134
- # Upper threshold (120) keeps strong structural edges
135
- # Tune these if you get too much noise or missing arcs
136
- edges = cv2.Canny(enhanced, 30, 120)
137
-
138
- # --- 6. Convert single-channel edge map back to RGB for display ---
139
- edges_rgb = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
140
 
141
- return edges_rgb
142
 
143
  def process_image(image, mode):
144
  """
 
82
 
83
  return annotated_image, summary
84
 
85
+ def scan_edges(image):
86
+ """
87
+ Simple edge detection using OpenCV
88
+ """
89
+ # Convert PIL image to numpy array
90
+ if isinstance(image, Image.Image):
91
+ image = np.array(image)
92
 
93
+ # Convert to grayscale
94
+ gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
95
 
96
+ clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
97
 
98
+ # Apply Gaussian blur
99
+ blurred = cv2.GaussianBlur(gray, (5, 5), 0)
100
 
101
+ enhanced = clahe.apply(gray_image)
102
 
103
+ # Edge detection using Canny
104
+ edges = cv2.Canny(enhanced, 50, 150)
105
 
106
+ # Convert back to RGB for display
107
+ edges_rgb = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
108
 
109
+ return edges_rgb
110
 
111
+ # def scan_edges(image):
112
 
113
+ # # --- 1. Convert PIL image to numpy array if needed ---
114
+ # if isinstance(image, Image.Image):
115
+ # image = np.array(image)
116
 
117
+ # # --- 2. Convert to grayscale ---
118
+ # gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
119
 
120
+ # # --- 3. Gaussian blur BEFORE CLAHE to reduce high-freq noise ---
121
+ # # that CLAHE would otherwise amplify
122
+ # blurred = cv2.GaussianBlur(gray, (5, 5), 0)
123
 
124
+ # # --- 4. Apply CLAHE on the blurred image ---
125
+ # # clipLimit=2.0 → controls noise amplification in flat regions
126
+ # # tileGridSize → 8x8 tiles work well for engine block scale features;
127
+ # # increase (e.g. 16x16) if bearing saddles are small
128
+ # # relative to full image resolution
129
+ # clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
130
+ # enhanced = clahe.apply(blurred)
131
+
132
+ # # --- 5. Canny edge detection on CLAHE-enhanced image ---
133
+ # # Lower threshold (30) helps recover weak edges in shadow regions
134
+ # # Upper threshold (120) keeps strong structural edges
135
+ # # Tune these if you get too much noise or missing arcs
136
+ # edges = cv2.Canny(enhanced, 30, 120)
137
+
138
+ # # --- 6. Convert single-channel edge map back to RGB for display ---
139
+ # edges_rgb = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
140
 
141
+ # return edges_rgb
142
 
143
  def process_image(image, mode):
144
  """