1 Introduction
A camera at a venue cannot frame each group. It is fixed to a wall or a stand, in a space that was built for something else, and to fit a capture system into such a space is hard before any question of composition comes up. The next group may be one person or eight. They stand near or far, in the centre or at the edge, and nobody looks through a viewfinder. To capture every group correctly at the moment of the photograph is, in our experience, close to impossible.
The shapes do not match either. The photograph has the aspect ratio of the sensor. The output has the aspect ratio of the paper or the screen, and one photograph often serves several outputs. A 3:2 photograph does not fit a 4:3 frame: either a ninth of its width is cut away, or empty bands appear above and below it. The person who stood at the edge is the one who is cut.
Our answer is to capture the widest view that the site allows and to leave the framing to software: where the group sits in the output frame, and how large it is. This paper is about that software. The same decision comes up whenever a group picture changes shape: when it goes onto other paper, into a layout with a border, a logo or a caption bar, or into a new scene.
We study the case in which the group is available as its own layer. A green screen provides such a layer, and so does a segmentation model. A photograph without such a layer is a different problem, which we do not treat: the background moves with the group, so the photograph must also cover the whole frame. The picture then has three layers. The background is a scene. The cutout is the group of people. The foreground is everything that is drawn over the people: a graphic border, a caption, or scenery such as a wave or a row of dunes. The framing has one decision to make: where the cutout goes, and how large it is.
Three things can go wrong. A person can fall outside the frame. The foreground can cover a face. A camera cut, the straight line where the edge of the photograph ended across a body, can end up in the middle of the frame, where it looks like a mistake.
A common default is height fitting: scale the photograph to the height of the frame and centre it. Height fitting ignores all three problems. It does not look at where the group stands in the photograph, at the faces, or at the foreground. Figure 1 shows the consequence on the outline of a real group. The photograph is 3:2 and the frame is 4:3, so height fitting keeps the central 8/9 of the photograph. The group fills the photograph. Height fitting crops the people at both sides, and the foreground covers at least a tenth of 3 faces of the front row.
This paper replaces the fixed rule by a search for the best framing. “Best” has a precise meaning: among all centred framings that meet four requirements and a size range, the one that shows the group as large as possible. The paper makes five contributions, and they are also its plan.
- A problem statement (Section 2). A framing is three numbers: one scale and two offsets. Each of the three failures becomes a requirement, a fourth requirement keeps the group in proportion, and a lexicographic objective defines the best framing.
- The geometry of the feasible set (Section 3). This part shows how to test the requirements exactly. For a fixed scale, the allowed vertical offsets form a union of intervals. Over all scales, an optimum exists and is rational (Theorem 6).
- An algorithm that always returns a picture (Section 4). There are two cases. If the feasible set is not empty, an exact search finds the best framing, and its scale is among polynomially many candidates (Proposition 13). If the set is empty, and we prove that this happens (Corollary 10), or if the search runs out of time, a local change of layer order and a closed-form framing still give a picture (Theorem 12).
- A comparison with height fitting (Section 5, Section 6), by proof and by measurement. The test bed is a fleet of green-screen photo kiosks, where the frame is a photo print. The measurement includes a backtest on 12,448 recent production photographs and a frontier of placement policies. Section 8 reports how the proofs and the program were checked.
- Optimality for any frame shape (Section 7). The proofs hold for every frame size. What depends on the shape is the size bound: on a tall frame it leaves most groups without a framing that meets the requirements. A size bound that follows the frame removes this limit and keeps every exact optimum of the print formats (Theorem 16). A replay on 13 shapes from 1:3 to 3:1 measures the effect.
2 The framing problem
2.1 Objects
The frame is a grid of pixels. Pixel is the unit square , and grows downwards. The foreground gives every frame pixel an opacity between 0 and 255. A pixel is blocked if and opaque if .
The cutout is an image with transparency that holds the group. Its support is the set of pixels with non-zero alpha, and its box is the tight bounding rectangle of the support, of size source pixels. We measure cutout coordinates from the top-left corner of the box. A face box is a rectangle with integer edges inside the box, for . If no face boxes are supplied, the whole box is the one face box. A side of the box is cut by the camera if it lies on the edge of the photograph. The cut of that side is the set of support pixels in the outermost row or column of the box on that side. It consists of one or more runs, each one source pixel deep.
A framing is a triple with . It maps a cutout point to the frame point
The map has one scale for both axes and for every person, so the group keeps its shape: any two points move apart by exactly the factor . Figure 2 shows the notation.
2.2 Requirements
Each failure of the Introduction becomes a requirement: R1 answers a person outside the frame, R3 a covered face, and R4 a visible camera cut. R2 keeps the group in proportion.
- R1, containment
- The placed box lies inside the frame: , , and .
- R2, one scale
- All people share the same on both axes. The map has this property by construction.
- R3, clear faces
- No blocked pixel overlaps a placed face box with positive area.
- R4, camera cuts
- A side that the camera cut lies on the matching edge of the frame. Otherwise, every frame pixel that a placed pixel of its cut overlaps with positive area is opaque, so the foreground hides the cut.
The scale is also bounded, . In this study the group height is between 60% and 86% of , and . These two percentages are design inputs, not results. The program rounds both bounds to whole pixels of group height, .
2.3 Objective
Many framings can satisfy R1 to R4. We order them lexicographically. First, the group is centred horizontally, . Second, the scale is as large as possible. Third, is as close as possible to a target , which by default centres the group vertically, . The target is a linear function of with rational coefficients. If two offsets are equally close to it, the smaller one is taken. Let be the set of centred framings that satisfy R1 to R4 and the scale bounds.
3 Geometry of the feasible set
The requirements are stated for pixels, and a frame has millions of pixels. This section reduces them to a few intervals. The search of Section 4 needs two operations: the allowed vertical offsets for a given scale (Proposition 4), and the largest scale that leaves an allowed offset (Lemma 5). Lemmas 1 to 3 prepare them, and Theorem 6 states that a best framing exists. The Garland scene of Figure 3 is the running example: its group is as large as it can be when a face touches a pennant while the feet are on the bottom edge, and the section computes that scale exactly.
Lemma 2 turns R3 into arithmetic. Face avoids the blocked pixel exactly when one of four linear inequalities holds:
Each inequality is linear in . The word “or” makes the problem non-convex: the feasible set can have holes and separate pieces. The next lemma removes the pixels from the picture for a fixed scale.
Fix and . Face covers the frame columns , where and . Call a row clear for face if it holds no blocked pixel in these columns. Then face satisfies R3 if and only if, for some maximal run of clear rows ,
For a fixed scale with and the group centred, the vertical offsets that satisfy R1 and R3 form the set
a finite union of closed intervals. The best offset at this scale is the point of nearest to .
Proposition 4 is a direct consequence of Lemmas 1 and 3. It is also how the program works. Row-wise prefix sums of the blocked pixels are computed once for each foreground, in time. After that, the clear rows of one face cost , and one scale costs plus the intersection of the interval lists.
Proposition 4 handles one scale. The next lemma removes , so that the largest scale follows directly.
Choose one clear run for every face, and treat containment as a face with , and the run . A common offset exists if and only if, for every pair ,
Each condition of Lemma 5 is linear in . For a fixed choice of runs the feasible scales therefore form one interval. Its upper end is the smallest of the ratios over the pairs with , or if that is smaller. The runs are valid only while the faces cover the same columns (Section 4.1).
Worked example. In the Garland scene (Figure 3), and the box is . The tallest person has face rows to . Under the long pennant, the clear run of this face starts at row . The pair that binds is this face against the bottom edge of the frame (, ):
At the two intervals share exactly one point, . Figure 4 shows the intervals of Proposition 4 at this scale, and Figure 5 shows the whole feasible set. The search of Section 4.1 returns exactly this framing, and , after 2 exact evaluations.
The example has an optimum, and it is a fraction. The last result of this section says that this is always so.
Theorem 6 is the reason why the program uses fractions and not floating-point numbers. The answer is a ratio of integers, and the program returns that ratio.
4 The algorithm
The program has two paths. If some framing meets all four requirements, an exact search returns the best one (Section 4.1). If none does, and we prove that such photographs exist (Section 4.2), the program draws the covered face in front of the foreground (Section 4.3), at a framing that is given in closed form (Section 4.4). Algorithm 1 joins the two paths.
4.1 Exact search over the scale
The columns that a face covers change only when one of its vertical edges crosses a pixel boundary. With a centred group, the left edge of face is at , and it crosses the boundary at the event scale . An edge at does not move and has no event. Event scales are rational and finite in number. Between two consecutive events, the covered columns and the clear runs do not change, and Lemma 5 gives the largest feasible scale in closed form. A search through the event intervals, from the largest scale downwards, is therefore exact.
The program does not list all events. For an interval of scales it clears only the columns that a face covers at every scale of the interval. This is a relaxation, so Lemma 5 applied to it gives an upper bound on the feasible scale. If the bound is feasible when tested with Proposition 4, it is the optimum on the interval. If not, the interval is split at an event scale and both parts are searched, the larger scales first. The feasible scales need not form one interval, and the search handles that case.
When a side is cut by the camera, R4 adds a choice: the cut is on the frame edge, or it is under opaque foreground. The program resolves this choice with an SMT solver over linear real arithmetic (Z3 [1]). The solver proposes a framing from a relaxed problem. The bitmap answers with the pixel constraints that this framing violates. The loop ends when the proposal violates nothing. The result is then certified by the following fact.
As a second check, the program asks the solver for a feasible framing that is strictly better than the result and accepts the result only when the solver proves that none exists.
Special case: no face boxes. If no face boxes are available, the whole box is protected. This case has a faster exact solution.
For every row , let be the width of the widest interval of columns that is centred in the frame and free of blocked pixels in that row. For a run of rows , let . A run is maximal if no larger run that contains it has the same . Then the largest scale at which the centred box satisfies R1 and R3 is
There are at most maximal runs. A monotone stack finds them in time, as in the classical largest-rectangle problem [2]. If the value of Proposition 8 is below , is empty.
4.2 Some photographs have no feasible framing
Such photographs occur in production, and the group of Figure 1 is one. A child who stands close to the camera is cut at the chin, and a border, a caption bar or scenery covers the bottom of the frame. Figure 6 shows the three ways out. Each one gives up one thing.
4.3 The depth rule
Picture (c) of Figure 6 needs a rule that draws a face in front of the foreground and changes nothing away from the faces. Standard compositing draws the foreground over the group over the background [3]. The front order draws the group over the foreground over the background. Let and be the two results at a pixel. The depth rule outputs
with a weight between 0 and 1. The weight is 1 on every pixel that a placed face box touches. It falls smoothly to 0 over a margin around the box: 34% of the box width at the sides and 42% of the box height above and below, and at least two pixels. Without face boxes, on the whole group.
The depth rule changes the picture. A face in front of a wave is a design decision. It is the most local change that we found for the photographs of Corollary 10, and it is visible, most of all on crowded groups (Figure 1 c).
4.4 A picture for every photograph
The exact search can report that is empty, and it has a time budget. Neither may stop the picture. Before the search starts, the program computes a fallback framing in closed form. Let be the largest scale at which the box fits in the frame.
- If no two opposite sides are cut, the scale is . A cut side is put on its frame edge. The group is centred along an axis that has no cut side.
- If the left and right sides are both cut, they force . If the top and bottom sides are both cut, they force . A forced scale is used when it does not exceed and when two forced scales agree.
- Otherwise the group is placed whole and centred, with a 3% inset, inside a thin drawn border. The border presents the cuts as the edges of a picture within the picture.
Algorithm 1 puts the parts together. Every picture carries a receipt with the framing, the path taken (exact optimum, edge-anchored fallback or bordered panel) and the amount of foreground that the depth rule moved behind the group.
4.5 Running time
Algorithm 1 gives the exact search a time budget. This section says why the search needs one, and why the problem does not.
The search of Section 4.1 is a branch and bound. To bound one interval of scales it tries combinations of clear runs, one run for each face, and it drops a combination as soon as that combination cannot beat the best scale found. When a side is cut, the program calls an SMT solver instead. We have no polynomial bound for either procedure, and the budget is the safeguard.
The problem itself is not hard: the optimal scale is one of a small number of candidates. Call the face boxes and the runs of the cuts (Section 2) the constraint rectangles. A face box must be clear. A run of a cut must be on its frame edge or under opaque foreground. Let be the number of constraint rectangles.
Every run of a cut counts as its own rectangle. This matters: in a scene with three runs on the bottom side, the optimum that the SMT solver certifies is , an event scale of the middle run. It is not among the candidates of one strip for the whole side.
Proposition 13 is a statement about the problem, not about the program. The branch and bound is a different procedure, and we did not compare their costs. We ran the enumeration against the search on 5,000 random scenes with one to five face boxes and no hidden cuts, 1,520 of them with the bottom side on the frame edge. The two returned the same result in all 5,000: 4,469 optima, 1,116 of them below the size cap, and 531 empty sets. The random test covers no cut under opaque foreground.
5 Comparison with height fitting
We now compare Algorithm 1 with height fitting, in this section by proof and in Section 6 by measurement. Height fitting is one fixed map. For a photograph of pixels it applies the scale to the photograph, centres it, and crops what falls outside the frame. Let be the aspect ratio of the frame divided by the aspect ratio of the photograph.
Proposition 14 describes the ideal map. The production code rounds the scaled width to whole pixels, which moves the window by less than one pixel.
For a 3:2 photograph and a 4:3 frame, : height fitting discards 5.56% of the photograph at each side. For a 7:5 frame it discards 3.33% at each side.
For every photograph, foreground and frame size:
(i) The proposed framing satisfies R1 and R2. Height fitting violates R1 exactly when and the support leaves the central window of Proposition 14.
(ii) In the proposed picture no foreground is drawn over a protected face box. Under height fitting a face is fully visible only if it lies in the window and no foreground lies on it. Height fitting tests neither.
(iii) In the proposed picture every camera cut is on a frame edge, under opaque foreground, or inside the drawn border. Under height fitting with , cuts at the left and right sides lie inside the frame.
(iv) If is not empty and the search completes, the proposed framing is optimal in . In particular, if the height-fitting framing belongs to , the proposed group is at least as large.
Theorem 15 says in which sense the proposed method is better. Containment and one scale hold on every input. A protected face box is never under foreground, by the framing or by the layer order. A camera cut is on a frame edge, hidden, or inside a border. The last two are treatments, not R3 and R4 themselves: the depth rule changes the picture, and a cut inside a border is still inside the frame. The measure of Section 6.3 counts such a cut as visible. Height fitting fails on inputs that occur in production (Section 6). Table 1 lists the requirements side by side. The theorem is about boxes and layer order. It does not say that a face of a few pixels can be recognised, and a frame of one or two pixels on an axis cannot show a separate border. It also does not say that people prefer the pictures. The objective says centred and large, and we measured geometry: we did not ask people which picture they prefer, and we did not judge physical prints. Rules of composition such as headroom or the height of the eye line are not in the objective, and the paper trim of a printer is not modelled.
| Requirement | Height fitting | Proposed |
|---|---|---|
| Group inside the frame | Only inside the central window | Always (Theorem 12) |
| One scale for all | Yes | Yes |
| Faces not under foreground | Not tested | The supplied face boxes: by framing, else by layer order |
| Camera cuts | Top and bottom on the edge. Sides inside the frame if | On an edge, under opaque foreground, or inside a border |
| Centring | Centres the photograph | Centres the group, unless a side cut pins it |
| Group size | Fixed by the camera distance | Largest feasible up to the size cap, else the fallback scale |
| Picture for every input | Yes | Yes (Theorem 12) |
6 Evaluation
6.1 Data
The data come from our green-screen photo kiosks, and every number in this section comes from that one application. There a green screen provides the cutout, the foreground is scenery designed for each background, the frame is a photo print, and the current compositor uses height fitting. The corpus is the geometry of 1,791 stored cutouts from completed print jobs at 10 venues, September to November 2026: photograph size and support box, no image content. The camera cut the group at the bottom in 1,733 of them (96.8%), at a side in 421 (23.5%), and at both sides in 148. For nine groups we also inspected the photographs and recorded every visible face, 36 face boxes in total. These nine were chosen to cover the failure types and are not a random sample. The example figures of this paper show two of them (Figure 1 and Figure 6 the first, Figure 3 the second). A figure shows only the alpha mask of the cutout, as a flat silhouette with each face marked in a second tone. It shows no pixel of a photograph, and its background and foreground are drawn. Each of the nine groups was rendered in three print formats (4×6, 5×7 and 6×8 in), which gives 108 face regions in 27 pictures.
6.2 Results on the study corpus
| Measure | Height fitting | Proposed |
|---|---|---|
| Cutouts cropped at a side, 4:3 frame () | 457 (25.5%) | 0 |
| Cutouts cropped at a side, 7:5 frame () | 400 (22.3%) | 0 |
| Face regions with ≥ 10% lost, three formats () | 20 | 0 |
| Pictures with such a face () | 13 | 0 |
| Face regions with ≥ 10% lost, 3000 × 2250 px () | 8 | 0 |
| Time for one 3000 × 2250 px picture, mean | 0.49 s | 1.54 s |
Cropping. The side crops in Table 2 are exact geometry on the stored boxes (Proposition 14). They occur when the photograph is wider than the frame, and 1,324 of the photographs are 3:2. The proposed method cannot crop (Theorem 12). A separate run produced a decodable picture for all 5,373 pairs of a cutout and a format, at review resolution and without face boxes.
Faces. Face visibility was measured on the final images of both compositors. The inputs were recoloured first, each face region in its own flat colour, and the pixels of each colour were counted in the output. Height fitting ran as the unmodified production code. It lost at least 10% of 20 of the 108 face regions, in 13 of the 27 pictures. A geometric replay with an alpha-weighted measure gives 22. The proposed method lost none, and the smallest visible share was 99.2%.
Paths. At the production size, 4 of the nine groups had an exact optimum with the normal layer order, 4 used the edge-anchored fallback with the depth rule, and 1 used the drawn border. The times in Table 2 are from a desktop computer.
Without face boxes. Without face boxes the method protects the whole group, and when the exact search fails, the whole group is drawn in front of the foreground. On the nine inspected groups, with their own foregrounds, this moved up to 93% of the foreground’s opacity behind the group. With face boxes it moved at most 34%, and nothing in 4 of the nine. The face boxes must be complete: the guarantee covers the regions that are supplied.
6.3 Production backtest
The study corpus is small and was chosen. The second evaluation replays recent production as it is. The sample comes from the 10,000 most recent customer sessions with a completed print: 12,449 photographs at 13 venues, from 8 August to 23 November 2026. One cutout was empty and is left out, which leaves 12,448 photographs of 9,999 sessions. A print in this section is the replayed picture for the format that was printed. It is not a judgement of the sheet that the customer received. Of these, 10,657 are not in the study corpus, so the method was designed without them. Both methods framed each photograph for the format that was printed, with the foreground that the customer chose. The photographs stayed in memory, and only geometry was stored. The faces come from a face detector, which found 33 of the 36 inspected faces of the study corpus. A face that the detector misses is not protected and is not counted, for either method.
The measures and their thresholds were written down before any result was computed. A print has a defect if a person is cropped (0.3% or more of the group’s pixels are outside the frame), if a face is lost (10% or more, as in Table 2), or if a camera cut is visible inside the frame. Table 3 gives the counts.
| Prints (and prints per 1,000) | Height fitting | Proposed |
|---|---|---|
| With at least one defect () | 3,219 (258.6) | 285 (22.9) |
| a person cropped | 3,046 (244.7) | 4 (0.3) |
| a face lost | 552 (44.3) | 0 (0) |
| a camera cut visible | 0 (0) | 281 (22.6) |
| With a defect, 3:2 cameras () | 3,167 (291.9) | 259 (23.9) |
| With a defect, 4:3 cameras () | 52 (32.8) | 26 (16.4) |
Benefit. The proposed method removes 235.7 defective prints in 1,000. When whole venues are resampled, the 95% interval of this difference is 99.6 to 335.8: the gain differs much between venues. On the 10,657 photographs outside the study corpus the rates are 263.3 and 22.8 in 1,000, nearly the same as for the whole sample.
The remaining defects. All 281 visible cuts of the proposed method are pictures with the drawn border of Section 4.4. The measure counts a cut inside the border as visible, although Theorem 15 treats it as presented. If the border is accepted, 4 defects remain. In those 4 photographs the detector found no face, and the kiosk implementation keeps height fitting when it has no face box.
The camera decides the size of the benefit. Until October every photograph in the sample is 3:2. In November, 1,587 of 2,052 are 4:3, because the venues changed cameras. On 3:2 photographs nearly all defects of height fitting are side crops (Proposition 14). On 4:3 photographs height fitting crops nobody, and its defects are the 52 prints with a lost face. On our 4:3 photographs the observed benefit is therefore 16.4 prints in 1,000 by the measure of Table 3, or 32.8 if the border is accepted. It is not 236.
Cost. The median group height falls from 89.5% to 86% of the frame: the group is smaller in 7,065 photographs and larger in 4,794. The median centring error falls from 3.64% of the frame width to zero. The depth rule moved some foreground behind a face in 4,519 prints (36%). The mean over all prints is 0.21% of the foreground’s opacity. 6,572 prints took the exact path of the kiosk implementation, 5,570 used the edge-anchored fallback, 281 the drawn border and 25 height fitting. The kiosk implementation placed and rendered one picture at full resolution in 294 ms (median of 200 photographs, without face detection, encoding and transfer).
Implementation. The backtest ran the implementation that is prepared for the kiosks and is not yet in production: a port of the reference program of Section 4 without the SMT solver. Its replay of height fitting matched the production code on the 200 photographs that we compared: 0 of 24,000,000 pixels differed. The port is not identical to the reference. On 300 photographs the two gave a different framing in 99. In 94 of them the scale was equal and the port placed the group lower. In 8 the reference found an exact optimum where the port used the fallback, because the port does not search for a cut that opaque foreground can hide. An exact path of the port is therefore an optimum of a smaller problem, in which every cut lies on its frame edge. A defect label differed in 2.
6.4 Frontier
The backtest compares two methods. It does not say whether a third would be better than both. We therefore ran 31 placement policies on the same photographs and compared them on four measures: the defect rate, the median group height, the foreground that the depth rule moves, and the centring error. A policy is dominated if another policy is at least as good on all four measures and better on one. The policies that are not dominated form the Pareto frontier, and 9 of the 31 are on it. Figure 7 shows two views.
Height fitting is dominated. The same rule with the group centred has 34 fewer defects in 1,000 at no cost on the other three measures. The proposed method is dominated by one variant of itself, by a margin without practical meaning: the variant with a minimum size of 40% moves 0.001 percentage points less foreground and is equal on the other three measures. No policy has fewer defects. The size cap moves the method along the frontier and does not change the defect rate. A cap of 90% gives the median group about the size that it has under height fitting, and moves 0.226% of the foreground’s opacity where the cap of 86% moves 0.214%. The sweep is exploratory. The parameters of the proposed method were fixed before it, and the four measures do not say when a large group looks cramped.
7 Any aspect ratio
The method was built for three print formats, and all three are landscape. The same decision comes up for a square post, a portrait story or a wide banner. No proof in Section 2 to Section 5 uses the aspect ratio of the frame: for every and , the optimum of Theorem 6 exists when is not empty, and a search that completes finds it. This section shows the part of the problem statement that does depend on the shape, changes it, and states the result as Theorem 16.
Experiment. We framed 1,887 archived groups (the study corpus and 96 records from a test venue) for 13 output shapes from 1:3 to 3:1, with three kinds of foreground: none, the real foreground stretched to the frame, and a synthetic border with a caption bar. A foreground was stored for 1,229 of the groups, and the other 658 have an empty layer in the second condition. This gives 73,593 trials for each method. The replay is geometric. It uses the boxes, the detected faces and low-resolution masks on a coarse grid, and it renders no picture. Its measures are coarser than those of Section 6.3: a group counts as cropped when its box leaves the frame, a cut counts as visible when a sampled pixel on it is not opaque, and a cut inside a drawn border is not counted.
The size bound depends on the shape. Height fitting cropped the group in 31,671 of the 73,593 trials, lost 28,712 of 246,090 face regions and left 5,696 of 98,046 camera cuts visible. The method of Section 4 did none of the three in any trial (Figure 8 b), as Theorems 12 and 15 say for every frame size. But on tall frames it reaches this through its fallback, not through its search (Figure 8 a). The cause is the lower size bound of Section 2, a group height of at least 60% of . In a 1:3 frame the width limits the group, the bound cannot hold, and is empty for 1,765 of 1,887 groups before the foreground is read. On such a frame there is no framing to choose from, and the fallback gives the picture.
An aspect-free form. Two changes remove the dependence on the shape.
- Size. Let be the largest scale at which the box fits the frame. If the interval of admissible scales of Section 2 is empty, its lower end is replaced by , or by its upper end if that is smaller. The bound then follows the dimension that limits the group. A non-empty interval is not changed.
- Objective. The horizontal distance of the group from the centre is minimised first, then the scale is maximised, then the vertical target applies. A remaining tie goes to the smaller , then to the smaller . If a centred framing exists, this is the objective of Section 2. If none exists, the group may leave the centre, where the method of Section 4 goes to its fallback.
Let be the set of framings that satisfy R1 to R4 and the scale bounds after change 1, with a free horizontal position.
For every frame size and , every cutout with a non-empty support and every foreground, with the default settings (no margin, no minimum face size):
(i) The interval of admissible scales is not empty.
(ii) If is not empty, the optimum for the objective of change 2 exists and is rational.
(iii) If is not empty, that optimum is the optimum of : an exact optimum of Section 4 does not change.
(iv) If is empty, the fallback framing of Theorem 12 gives a picture.
Theorem 16 is the exact sense in which the method is optimal for any shape. For every frame size the variant returns the best framing of when one exists and the search completes. It changes no exact optimum of Section 4 when both searches complete. A framing that came from the fallback of Section 4 can change, and that is the purpose. The theorem cannot promise that is never empty. If the camera cut a face at the bottom and the foreground covers the whole bottom row of the frame, no position helps (Theorem 9). The exact search runs first with the group centred, as before, and the free search runs only after the centred problem is proved empty.
The program of the variant also changes the fallback in two small ways: a bordered panel leaves one full pixel at each side, and a frame of one or two pixels on an axis gets a border below pixel size. In the replay this changed 325 fallback framings at 1:3.
Results. On the three print formats the variant returns exactly the framing of Section 4 wherever that method finds an exact optimum: in 13,072 of 13,072 trials on the coarse grid, and in 1,565 of 1,565 trials of a second replay at 420 pixels that protects the whole group. In 1,926 further print trials of 16,983 the method of Section 4 used its fallback and the variant finds an exact optimum, in 1,912 of them by leaving the centre. The framing changes in 1,917 of these trials. No other print trial differs. On the ten other shapes the exact optima rise from 33,552 to 48,826 of 56,610 trials, and the depth rule changes the picture in 4,420 trials, not 8,269. The variant ran out of time in 4 of these trials. At 1:3 without a foreground the exact optima rise from 122 to 1,778 of 1,887. On the 12,448 photographs of the backtest, 485,472 trials over the same shapes gave no cropped group, no lost face region and no visible cut by the measures of this replay, and the exact optima rose from 281,079 to 397,947. On the print trials of that run the variant kept 81,659 of the 81,660 exact optima of Section 4 and lost one to its time budget.
Speed and open points. The free search is slower. This belongs to the search, not to the problem: the argument of Proposition 13 extends to a free position, where the candidates are the vertices of an arrangement of planes in : the planes of the constraints and the two planes on which a distance of the objective changes sign. Their number is still polynomial. With a search budget of 0.25 s it ran out of time in 2,346 of 112,032 print trials on the backtest photographs, and the method of Section 4 in 49. With 2 s on the archived groups neither ran out of time on a print format. The kiosk implementation therefore keeps the method of Section 4 until the variant is timed at print size. The foregrounds were designed for the print formats, so the other shapes used stretched or synthetic foregrounds, and no picture was judged by a person. A group that fills the whole width of a tall frame can look cramped. The variant has a width cap for this, and we have not chosen its value. The proofs hold for every frame size, and the tests cover the shapes from 1:3 to 3:1.
A first rewrite put the size before the centring and let the group move freely. It found nearly as many exact optima, but it changed 1,611 of 5,373 print framings: the group became larger in 840 of them and smaller in 771. We rejected it: a general method must not change the prints that are already right.
8 How the work was done and checked
The method, its proofs and the first evaluation took three days, 21 to 23 November 2026. We wrote the problem statement from the source code of the kiosk software and from measurements of production cutouts. Two OpenAI models, GPT-6.2 Sol and GPT-6.2 Astra, then worked as coding agents under our direction. They derived the formal model, wrote the solver in Python with exact fractions, ran it on the production sample, and wrote the tests and the Lean file. We reviewed each stage. One review changed the design: an early version reported “infeasible” for photographs such as the Wave scene and returned no picture. A kiosk must return a picture, and the requirement that became Theorem 12 followed.
The mathematics: Lean 4. The Lean proof assistant [4] checks a proof line by line and accepts no gap. We used Lean 4.19.0 with its standard library only. The file has 216 lines and 13 theorems, nine of which are the results in Table 4. It contains no unproved step. The statements about framings are about integers: a rational framing is first multiplied by its common denominator. The proofs use induction over lists and the decision procedure omega for linear integer arithmetic. Table 4 maps the theorems to this paper.
| Lean theorem | Statement in this paper |
|---|---|
uniform_displacement | R2: one scale moves any two points apart by the factor |
group_enclosure_exact | Lemma 1, for any list of boxes |
separated_iff_clear | Lemma 2 |
clear_exact | Proposition 4: unions of intervals are intersected exactly |
vertical_projection | Lemma 5 |
relaxation_certificate | Lemma 7 |
envelope_optimal, envelope_attained | Proposition 8, on any fixed scale denominator |
shared_patch_forces_border | Theorem 9, for general opacity thresholds |
Lean checks the listed lemmas. It does not check the steps between them: Lemma 3, which turns pixels into intervals, and Theorem 6 are proved by hand. It does not check that the Python code implements the method. Two tests cover the program.
- The program: SMT cross-check. The exact search was compared with a direct encoding of R1 to R4 for every blocked pixel in Z3 [1], on 166 adversarial and random cases with 332 centred comparisons (181 feasible, 151 infeasible), and on 252 further comparisons, a third of them with a free horizontal position. All agree.
- The program: pixel oracle. A separate test, which shares no code with the solver’s own tests, drew 3,000 random scenes in three flat colours and read the claims back from the output pixels: the group is inside the frame, the scene is unchanged where no person lands, protected pixels show the person (5,748,125 pixels), foreground away from faces stays in front, and, in the 431 scenes without foreground and border, the group area equals times the source area within the rounding of the renderer. It found 0 violations. Of 4,565 camera cuts, 3,893 were on a frame edge, 331 under opaque foreground and 341 inside a drawn border.
Three further GPT-6.2 Sol agents ran the production backtest and the frontier (Section 6.3, Section 6.4) and the study of other aspect ratios (Section 7) on 23 and 24 November. The variant of Section 7 was tested like the method itself: a pixel oracle on 5,000 random scenes with shapes from 1:3 to 3:1, 450 SMT comparisons, and four further Lean lemmas for the new size bound and the new objective, which carry parts (i) and (iii) of Theorem 16. All pass.
Audit. A third model, Claude Fable 5.2 (Anthropic), audited the result. It re-ran every check, recompiled the Lean file, wrote the pixel oracle, and compared both compositors on the nine inspected groups through the production code. It recounted the backtest from the per-photograph records and recompiled the further Lean lemmas. It also produced the figures and the first draft of this text. After the author’s review on 27 November it rebuilt the example figures from the alpha masks of production photographs, added Proposition 13 with its test (Section 4.5), and stated the result of Section 7 as Theorem 16. GPT-6.2 Astra then reviewed that version for internal consistency. Its review listed 31 points. Two were errors in new mathematics: R4 did not define a closed set, and Proposition 13 counted one strip for a cut side where every run must count. This version corrects them and the other points that we could confirm.
References
- [1] L. de Moura and N. Bjørner, “Z3: An efficient SMT solver,” in Tools and Algorithms for the Construction and Analysis of Systems (TACAS 2008), Springer, 2008, pp. 337–340.
- [2] A. Naamad, D. T. Lee, and W.-L. Hsu, “On the maximum empty rectangle problem,” Discrete Applied Mathematics, vol. 8, no. 3, pp. 267–277, 1984.
- [3] T. Porter and T. Duff, “Compositing digital images,” Computer Graphics (Proceedings of SIGGRAPH '84), vol. 18, no. 3, pp. 253–259, 1984.
- [4] L. de Moura and S. Ullrich, “The Lean 4 theorem prover and programming language,” in Automated Deduction - CADE 28, Springer, 2021, pp. 625–635.








