kambris commited on
Commit
b832053
·
verified ·
1 Parent(s): 5ae1466

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -154,7 +154,37 @@ def preprocess_voynich_image(img_pil):
154
 
155
  return Image.fromarray(enhanced)
156
 
157
- # Create interface with preprocessing option
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  with gr.Blocks(title="Voynich Manuscript Line Extractor") as demo:
159
  gr.Markdown("# Voynich Manuscript Line Extractor")
160
  gr.Markdown("Upload a scanned folio of the Voynich manuscript. The app will detect and crop the first visible line of text.")
@@ -164,10 +194,16 @@ with gr.Blocks(title="Voynich Manuscript Line Extractor") as demo:
164
  input_image = gr.Image(type="pil", label="Upload Voynich Folio")
165
  enhance_btn = gr.Button("Enhance Image First")
166
  extract_btn = gr.Button("Extract First Line")
 
167
 
168
  with gr.Column():
169
  enhanced_output = gr.Image(label="Enhanced Image")
170
  line_output = gr.Image(label="Extracted First Line")
 
 
 
 
 
171
 
172
  enhance_btn.click(
173
  fn=preprocess_voynich_image,
@@ -180,6 +216,12 @@ with gr.Blocks(title="Voynich Manuscript Line Extractor") as demo:
180
  inputs=input_image,
181
  outputs=line_output
182
  )
 
 
 
 
 
 
183
 
184
  if __name__ == "__main__":
185
  demo.launch()
 
154
 
155
  return Image.fromarray(enhanced)
156
 
157
+ def debug_line_detection(img_pil):
158
+ """Debug version that shows intermediate processing steps"""
159
+ if img_pil is None:
160
+ return None, None, None
161
+
162
+ img = np.array(img_pil)
163
+ if len(img.shape) == 3:
164
+ gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
165
+ else:
166
+ gray = img
167
+
168
+ # Try different thresholds
169
+ _, thresh1 = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY_INV)
170
+ thresh2 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
171
+ cv2.THRESH_BINARY_INV, 11, 2)
172
+ _, thresh3 = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
173
+
174
+ # Combine all
175
+ thresh = cv2.bitwise_or(thresh1, cv2.bitwise_or(thresh2, thresh3))
176
+
177
+ # Small dilation
178
+ kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 2))
179
+ dilated = cv2.dilate(thresh, kernel, iterations=1)
180
+
181
+ # Convert back to PIL for display
182
+ thresh_pil = Image.fromarray(thresh)
183
+ dilated_pil = Image.fromarray(dilated)
184
+
185
+ return thresh_pil, dilated_pil, extract_first_line(img_pil)
186
+
187
+ # Add debug interface
188
  with gr.Blocks(title="Voynich Manuscript Line Extractor") as demo:
189
  gr.Markdown("# Voynich Manuscript Line Extractor")
190
  gr.Markdown("Upload a scanned folio of the Voynich manuscript. The app will detect and crop the first visible line of text.")
 
194
  input_image = gr.Image(type="pil", label="Upload Voynich Folio")
195
  enhance_btn = gr.Button("Enhance Image First")
196
  extract_btn = gr.Button("Extract First Line")
197
+ debug_btn = gr.Button("Debug Line Detection")
198
 
199
  with gr.Column():
200
  enhanced_output = gr.Image(label="Enhanced Image")
201
  line_output = gr.Image(label="Extracted First Line")
202
+
203
+ with gr.Row():
204
+ debug_thresh = gr.Image(label="Threshold Result")
205
+ debug_dilated = gr.Image(label="After Dilation")
206
+ debug_extracted = gr.Image(label="Final Extraction")
207
 
208
  enhance_btn.click(
209
  fn=preprocess_voynich_image,
 
216
  inputs=input_image,
217
  outputs=line_output
218
  )
219
+
220
+ debug_btn.click(
221
+ fn=debug_line_detection,
222
+ inputs=input_image,
223
+ outputs=[debug_thresh, debug_dilated, debug_extracted]
224
+ )
225
 
226
  if __name__ == "__main__":
227
  demo.launch()