MCPcopy
hub / github.com/camelot-dev/camelot / scale_image

Function scale_image

camelot/utils.py:340–417  ·  view source on GitHub ↗

Translate and scale image coordinate space to PDF coordinate space. Parameters ---------- tables : dict A dictionary with table boundaries as keys (tuples of four floats) and a list of intersections (list of tuples of two floats) as values. v_segments : list

(
    tables: dict[tuple[float, float, float, float], list[tuple[float, float]]],
    v_segments: list[tuple[float, float, float, float]],
    h_segments: list[tuple[float, float, float, float]],
    factors: tuple[float, float, float],
)

Source from the content-addressed store, hash-verified

338
339
340def scale_image(
341 tables: dict[tuple[float, float, float, float], list[tuple[float, float]]],
342 v_segments: list[tuple[float, float, float, float]],
343 h_segments: list[tuple[float, float, float, float]],
344 factors: tuple[float, float, float],
345) -> tuple[
346 dict[tuple[float, float, float, float], dict[str, list[tuple[float, float]]]],
347 list[tuple[float, float, float, float]],
348 list[tuple[float, float, float, float]],
349]:
350 """Translate and scale image coordinate space to PDF coordinate space.
351
352 Parameters
353 ----------
354 tables : dict
355 A dictionary with table boundaries as keys (tuples of four floats)
356 and a list of intersections (list of tuples of two floats) as values.
357 v_segments : list
358 A list of vertical line segments, where each segment is a tuple
359 of four floats (x1, y1, x2, y2).
360 h_segments : list
361 A list of horizontal line segments, where each segment is a tuple
362 of four floats (x1, y1, x2, y2).
363 factors : tuple
364 A tuple (scaling_factor_x, scaling_factor_y, img_y) where the
365 first two elements are scaling factors and img_y is the height of
366 the image.
367
368 Returns
369 -------
370 Tuple[Dict[Tuple[float, float, float, float], Dict[str, List[Tuple[float, float]]]],
371 List[Tuple[float, float, float, float]],
372 List[Tuple[float, float, float, float]]]
373 A tuple containing:
374 - tables_new: A new dictionary with scaled table boundaries and joints.
375 - v_segments_new: A new list of scaled vertical segments.
376 - h_segments_new: A new list of scaled horizontal segments.
377 """
378 scaling_factor_x, scaling_factor_y, img_y = factors
379 tables_new = {}
380
381 for k in tables.keys():
382 x1, y1, x2, y2 = k
383 x1 = scale(x1, scaling_factor_x)
384 y1 = scale(abs(translate(-img_y, y1)), scaling_factor_y)
385 x2 = scale(x2, scaling_factor_x)
386 y2 = scale(abs(translate(-img_y, y2)), scaling_factor_y)
387
388 # j_x and j_y are tuples of floats
389 j_x, j_y = zip(*tables[k]) # noqa B905
390 j_x_scaled = [scale(j, scaling_factor_x) for j in j_x]
391 j_y_scaled = [scale(abs(translate(-img_y, j)), scaling_factor_y) for j in j_y]
392
393 tables_new[(x1, y1, x2, y2)] = {
394 "joints": list(zip(j_x_scaled, j_y_scaled)) # noqa B905
395 }
396
397 # Scale vertical segments

Callers 1

_generate_table_bboxMethod · 0.85

Calls 2

scaleFunction · 0.85
translateFunction · 0.85

Tested by

no test coverage detected