MCPcopy Create free account
hub / github.com/BIT-DataLab/Edit-Banana / process_image

Method process_image

modules/text/restorer.py:135–190  ·  view source on GitHub ↗

Process image and return list of text blocks.

(self, image_path: str)

Source from the content-addressed store, hash-verified

133 return generator.generate_xml(text_cells)
134
135 def process_image(self, image_path: str) -> List[Dict[str, Any]]:
136 """Process image and return list of text blocks."""
137 total_start = time.time()
138 image_path = Path(image_path)
139
140 with Image.open(image_path) as img:
141 image_width, image_height = img.size
142
143 # Step 1: OCR
144 ocr_result, formula_result = self._run_ocr(str(image_path))
145
146 # Step 2: Formula (layout OCR + Pix2Text)
147 processing_start = time.time()
148
149 if formula_result:
150 print("\nFormula refinement...")
151 merged_blocks = self.formula_processor.merge_ocr_results(ocr_result, formula_result)
152 text_blocks = self.formula_processor.to_dict_list(merged_blocks)
153 else:
154 text_blocks = self._ocr_result_to_dict_list(ocr_result)
155
156 print(f" {len(text_blocks)} text blocks")
157
158 # Step 3: Coord transform
159 print("\nCoord transform...")
160 coord_processor = CoordProcessor(
161 source_width=image_width,
162 source_height=image_height
163 )
164
165 for block in text_blocks:
166 polygon = block.get("polygon", [])
167 if polygon:
168 geometry = coord_processor.polygon_to_geometry(polygon)
169 block["geometry"] = geometry
170 else:
171 block["geometry"] = {"x": 0, "y": 0, "width": 100, "height": 20, "rotation": 0}
172
173 # Step 4: Font size
174 print("\nFont size...")
175 text_blocks = self.font_size_processor.process(text_blocks)
176
177 # Step 5: Font family
178 print("\nFont family...")
179 global_font = self._detect_global_font(ocr_result)
180 text_blocks = self.font_family_processor.process(text_blocks, global_font=global_font)
181
182 # Step 6: Style (bold/color)
183 print("\nStyle...")
184 ocr_styles = getattr(ocr_result, "styles", [])
185 text_blocks = self.style_processor.process(text_blocks, ocr_styles=ocr_styles)
186
187 self.timing["processing"] = time.time() - processing_start
188 self.timing["total"] = time.time() - total_start
189
190 return text_blocks
191
192 def restore(

Callers 2

processMethod · 0.95
restoreMethod · 0.95

Calls 8

_run_ocrMethod · 0.95
polygon_to_geometryMethod · 0.95
_detect_global_fontMethod · 0.95
CoordProcessorClass · 0.85
merge_ocr_resultsMethod · 0.80
to_dict_listMethod · 0.80
processMethod · 0.45

Tested by

no test coverage detected