Given poster_data, compute: - tp: ratio of text length for each panel - gp: ratio of figure area for each panel - sp: ratio of panel area to total poster area - rp: aspect ratio (width / height) Returns a list of dicts, each: { 'tp': float, 'gp
(poster_data)
| 90 | } |
| 91 | |
| 92 | def compute_panel_attributes(poster_data): |
| 93 | """ |
| 94 | Given poster_data, compute: |
| 95 | - tp: ratio of text length for each panel |
| 96 | - gp: ratio of figure area for each panel |
| 97 | - sp: ratio of panel area to total poster area |
| 98 | - rp: aspect ratio (width / height) |
| 99 | |
| 100 | Returns a list of dicts, each: |
| 101 | { |
| 102 | 'tp': float, |
| 103 | 'gp': float, |
| 104 | 'sp': float, |
| 105 | 'rp': float |
| 106 | } |
| 107 | """ |
| 108 | |
| 109 | poster_w = poster_data["poster_width"] |
| 110 | poster_h = poster_data["poster_height"] |
| 111 | panels = poster_data["panels"] |
| 112 | |
| 113 | poster_area = max(poster_w * poster_h, 1.0) # avoid zero |
| 114 | |
| 115 | # 1) Compute total text length across all panels |
| 116 | # 2) Compute total figure area across all panels |
| 117 | total_text_length = 0 |
| 118 | total_figure_area = 0 |
| 119 | |
| 120 | # We'll store partial info about each panel so we don't parse multiple times |
| 121 | panel_list = [] |
| 122 | for p in panels: |
| 123 | # Combine all text |
| 124 | panel_text_joined = " ".join(p["text_blocks"]) |
| 125 | panel_text_len = len(panel_text_joined) |
| 126 | |
| 127 | # Sum area of figure blocks |
| 128 | panel_fig_area = 0.0 |
| 129 | for (fx, fy, fw, fh) in p["figure_blocks"]: |
| 130 | panel_fig_area += (fw * fh) |
| 131 | |
| 132 | panel_list.append({ |
| 133 | "x": p["x"], |
| 134 | "y": p["y"], |
| 135 | "width": p["width"], |
| 136 | "height": p["height"], |
| 137 | "text_len": panel_text_len, |
| 138 | "fig_area": panel_fig_area |
| 139 | }) |
| 140 | |
| 141 | total_text_length += panel_text_len |
| 142 | total_figure_area += panel_fig_area |
| 143 | |
| 144 | # Avoid divide by zero |
| 145 | if total_text_length < 1: |
| 146 | total_text_length = 1 |
| 147 | if total_figure_area < 1e-9: |
| 148 | total_figure_area = 1e-9 |
| 149 |