MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / collect_images

Method collect_images

utils/src/multimodal.py:65–89  ·  view source on GitHub ↗

Collect images from the presentation and gather other information.

(self)

Source from the content-addressed store, hash-verified

63 return self.image_stats
64
65 def collect_images(self):
66 """
67 Collect images from the presentation and gather other information.
68 """
69 for slide_index, slide in enumerate(self.presentation.slides):
70 for shape in slide.shape_filter(Picture):
71 image_path = pbasename(shape.data[0])
72 self.image_stats[image_path] = {
73 "appear_times": 0,
74 "slide_numbers": set(),
75 "relative_area": shape.area / self.slide_area * 100,
76 "size": PIL.Image.open(
77 pjoin(self.config.IMAGE_DIR, image_path)
78 ).size,
79 }
80 self.image_stats[image_path]["appear_times"] += 1
81 self.image_stats[image_path]["slide_numbers"].add(slide_index + 1)
82 for image_path, stats in self.image_stats.items():
83 stats["slide_numbers"] = sorted(list(stats["slide_numbers"]))
84 ranges = self._find_ranges(stats["slide_numbers"])
85 top_ranges = sorted(ranges, key=lambda x: x[1] - x[0], reverse=True)[:3]
86 top_ranges_str = ", ".join(
87 [f"{r[0]}-{r[1]}" if r[0] != r[1] else f"{r[0]}" for r in top_ranges]
88 )
89 stats["top_ranges_str"] = top_ranges_str
90
91 def _find_ranges(self, numbers):
92 """

Callers 1

__init__Method · 0.95

Calls 3

_find_rangesMethod · 0.95
shape_filterMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected