Skip to main content
Contact sales

Research paper

Optimal Framing for Group Photographs

An exact algorithm that keeps everyone in the frame and every face visible

A green-screen photo kiosk cuts the group out of the camera photo and places it on a printed design. The paper defines a correct placement, proves which placement is optimal and gives the algorithm that finds it.

At a glance

A replay framed 12,448 photographs from the most recent customer sessions at 13 of our venues (8 August 2026 to 23 November 2026) with both methods, each for the print format that the customer chose. A replayed picture counts as defective if a person is cropped, a face is lost, or a camera cut is visible.

Height fitting, the rule used before
258.6 defective pictures per 1,000
Proposed method
22.9 defective pictures per 1,000

Most of the remaining defects are pictures that the method deliberately sets inside a drawn border. The size of the gain depends on the camera. On 3:2 photographs the old rule crops people at the sides; on 4:3 cameras it crops nobody, and the rates on the 1,587 photographs from 4:3 cameras are 32.8 against 16.4 per 1,000. Most venues changed to 4:3 cameras in November 2026.

The method is not yet in production. The rates are for replayed pictures, not for prints that customers received.

  • The optimum exists for a frame of any shape and size whenever a centred framing within the size bounds meets the requirements.
  • The method works on the group as a separate layer, from a green screen or a segmentation model. A photograph without such a layer, where the background moves with the group, is a different problem that the paper does not treat.
  • Faces are protected through face boxes. Without them the method protects the whole group, and a face that the detector misses is not protected.
  • “Best” is geometric: centred and as large as allowed. Nobody was asked which prints they prefer, and no physical print was judged.
  • All data come from one application. The method is not yet in production: the results replay recorded production photographs with both methods, not prints that customers received.
Abstract. A camera that is installed at a venue cannot frame each group. The camera is fixed, the next group may be one person or eight, and the output rarely has the aspect ratio of the photograph. A practical answer is to capture the widest view possible and to let software choose the framing: a position and a size for the group in the output frame. A common default for that choice scales the photograph to the height of the frame and centres it. In a replay of 12,448 photographs from the 10,000 most recent customer sessions at our photo kiosks, this default gives a picture with a cropped person or a lost face 258.6 times in 1,000. We state framing as an optimisation problem with four requirements: everyone is inside the frame, everyone has the same scale, no face is under a foreground element, and no camera cut is visible. We prove that an exact optimum exists whenever a centred framing within the size bounds meets the requirements, for a frame of any shape and size, and that its scale is one of a polynomial number of candidates, so the problem needs no exponential search. We give a search that computes the optimum in rational arithmetic. We also prove that some photographs admit no framing that meets all four requirements. For those, the algorithm changes the layer order locally, so that a face is drawn in front of the element that would cover it. The procedure returns a picture for every photograph with a non-empty cutout, also when the search runs out of time. In the same replay it leaves 22.9 defective prints in 1,000, and all but 4 of these 285 prints are pictures that it sets inside a drawn border. In a sweep of 31 placement policies on four measures (defects, group size, changed foreground and centring), no policy has fewer defects. One policy dominates the method, by 0.001 percentage points of changed foreground. On a tall frame the size bound of the print formats leaves most groups without a framing that meets the requirements. A size bound that follows the frame shape removes this limit and keeps every exact optimum on the print formats. We test it on outputs from 1:3 to 3:1. The core lemmas are checked in Lean 4. The example figures show real groups as flat silhouettes: the alpha masks of production photographs.
Silhouette of ten people who fill a photograph in two rows. Shaded bands at the left and right mark the part that height fitting crops, and the group reaches into both bands.

(a) Photograph, 3:2

The same group in a frame with dunes in front. Arrows at the left and right edges mark cropped people. Dashed boxes mark three faces of the front row behind the dunes.

(b) Height fitting, 4:3 frame

The same group, whole and slightly smaller. All ten faces are visible, and three faces of the front row are drawn in front of the dunes.

(c) Proposed framing

Figure 1: One group of 10 people, framed by both methods. The silhouette is the alpha mask of a production photograph. Each face is marked in yellow, and the scenery is drawn for the figure. In (a) the boxes are the face boxes, and the shaded bands are the part of the photograph that height fitting cannot show. The camera cut the group at the right and at the bottom. In (b) height fitting crops 5.8% of the group at the two sides (arrows), and the dunes cover at least 10% of 3 faces of the front row (dashed boxes). In (c) the proposed framing shows the whole group at scale 𝑠=25/23, with both camera cuts on the edges of the frame. No framing clears the faces that the camera cut at the bottom edge and also keeps the cuts on an edge or hidden (Section 4.2), so the algorithm draws the faces of the front row in front of the dunes. All 10 faces are visible.

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.

  1. 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.
  2. 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).
  3. 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).
  4. 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.
  5. 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 [𝑐,𝑐+1]×[𝑟,𝑟+1], and 𝑦 grows downwards. The foreground gives every frame pixel an opacity 𝛼(𝑐,𝑟) between 0 and 255. A pixel is blocked if 𝛼>0 and opaque if 𝛼=255.

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 𝑖=1,…,𝑛. 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 𝑠>0. 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.

Diagram of a frame of width W and height H. A dashed rectangle of width sS and height sT is the placed cutout box with its top-left corner at (x, y). Four small rectangles inside it are face boxes. A hatched region along the bottom is the foreground.
Figure 2: Notation. The dashed rectangle is the placed box of the cutout. The hatched region is the foreground, which is drawn in front of the people.

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: 𝑥≥0, 𝑦≥0, 𝑥+𝑠𝑆≤𝑊 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, 𝑠min≤𝑠≤𝑠max. 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, ⌈0.6𝐻⌉≤𝑠𝑇≤⌊0.86𝐻⌋.

2.3 Objective

Many framings can satisfy R1 to R4. We order them lexicographically. First, the group is centred horizontally, 𝑥=(𝑊−𝑠𝑆)/2. Second, the scale 𝑠 is as large as possible. Third, 𝑦 is as close as possible to a target 𝑦∗(𝑠), which by default centres the group vertically, 𝑦∗(𝑠)=(𝐻−𝑠𝑇)/2. 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 1 (box). All pixels of the group are inside the frame if and only if the placed box is inside the frame.
Proof. The box is the smallest axis-aligned rectangle that contains the support, and the frame is an axis-aligned rectangle. A rectangle contains a set exactly when it contains that set’s bounding rectangle.□
Lemma 2 (separation). Two axis-aligned rectangles overlap with positive area if and only if their projections overlap with positive length on both axes. Equivalently, they do not overlap if and only if one lies entirely to the left of, to the right of, above or below the other, where touching edges are allowed.

Lemma 2 turns R3 into arithmetic. Face 𝑖 avoids the blocked pixel (𝑐,𝑟) exactly when one of four linear inequalities holds:

𝑥+𝑠𝑟𝑖≤𝑐or𝑥+𝑠𝑙𝑖≥𝑐+1or𝑦+𝑠𝑏𝑖≤𝑟or𝑦+𝑠𝑡𝑖≥𝑟+1.

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.

Lemma 3 (interval).

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 𝑗≤𝑟<𝑘,

𝑗−𝑠𝑡𝑖≤𝑦≤𝑘−𝑠𝑏𝑖.
Proof. By Lemma 2, the placed face overlaps pixel (𝑐,𝑟) with positive area exactly when 𝑎𝑖≤𝑐<𝑎̄𝑖 and 𝑦+𝑠𝑡𝑖−1<𝑟<𝑦+𝑠𝑏𝑖. The rows that satisfy the second condition are consecutive integers from ⌊𝑦+𝑠𝑡𝑖⌋ to ⌈𝑦+𝑠𝑏𝑖⌉−1. R3 requires all of them to be clear, so they must lie in one run [𝑗,𝑘). That holds exactly when 𝑗≤⌊𝑦+𝑠𝑡𝑖⌋ and ⌈𝑦+𝑠𝑏𝑖⌉≤𝑘. Because 𝑗 and 𝑘 are integers, these are the stated inequalities.□
Proposition 4 (fixed scale).

For a fixed scale 𝑠 with 𝑠𝑆≤𝑊 and the group centred, the vertical offsets that satisfy R1 and R3 form the set

𝑌(𝑠)=[0,𝐻−𝑠𝑇]∩⋂𝑖=1𝑛⋃runs[𝑗,𝑘)of face𝑖[𝑗−𝑠𝑡𝑖,𝑘−𝑠𝑏𝑖],

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.

Silhouette of four people who crouch in the middle of the photograph, in full length.

(a) Photograph

The group in a frame with pennants along the top. Two heads are partly behind pennants, marked by dashed boxes.

(b) Height fitting

The group is smaller and lower. The head of the tallest person is just below the tip of a long pennant and the feet are at the bottom edge.

(c) Proposed framing, exact optimum

Figure 3: The Garland scene, with the alpha mask of a second production photograph. No side of the box is cut by the camera. Pennants hang from the top and two of them are long. Height fitting shows the group at 80% of the frame height and puts all 4 face boxes partly behind pennants, 2 of them by at least 10% (dashed boxes). The exact optimum is the largest group with all 4 face boxes clear: the top of the tallest face box touches a pennant tip while the feet reach the bottom edge, at 66% of the frame height.

Proposition 4 handles one scale. The next lemma removes 𝑦, so that the largest scale follows directly.

Lemma 5 (eliminating y).

Choose one clear run [𝑗𝑖,𝑘𝑖) for every face, and treat containment as a face 0 with 𝑡0=0, 𝑏0=𝑇 and the run [0,𝐻). A common offset 𝑦 exists if and only if, for every pair (𝑖,𝑚),

𝑠(𝑏𝑚−𝑡𝑖)≤𝑘𝑚−𝑗𝑖.
Proof. By Lemma 3 each face allows the interval [𝑗𝑖−𝑠𝑡𝑖,𝑘𝑖−𝑠𝑏𝑖]. Finitely many closed intervals on a line share a point exactly when every lower end is at most every upper end.□

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 𝑠max 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), 𝑊×𝐻=1600×1200 and the box is 𝑆×𝑇=743×801. The tallest person has face rows 𝑡2=0 to 𝑏2=203. Under the long pennant, the clear run of this face starts at row 𝑗2=407. The pair that binds is this face against the bottom edge of the frame (𝑘0=1200, 𝑏0=801):

𝑠(801−0)≤1200−407so𝑠≤793/801≈0.99.

At 𝑠=793/801 the two intervals share exactly one point, 𝑦=407. 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, 𝑠=793/801 and 𝑦=407, after 2 exact evaluations.

Number line of the vertical offset y. Five bars show the allowed intervals: inside the frame and faces 1 to 4. Their intersection is a single point at y = 407.
Figure 4: Proposition 4 at the optimal scale of the Garland scene. Each bar is the set of offsets 𝑦 that one condition allows. The bars share a single point (bottom row). The dashed line is the vertical target 𝑦∗, which would centre the group. The target is not feasible, so the nearest feasible offset is chosen.
Plot of all framings in the plane of scale s and vertical offset y, over the whole allowed range of scales. Two shaded regions are not feasible: above a horizontal line a face box is behind a pennant, and below a slanted dashed line the group leaves the frame. The feasible framings are a small triangle between the two lines at the smallest scales. Its tip, where the lines cross, is marked optimum.
Figure 5: All framings of the Garland scene in the (𝑠,𝑦) plane. The horizontal axis is the whole allowed range of scales, from 60% to 86% of the frame height. The shaded areas are not feasible. Above the solid line a face box is behind a pennant, and below the dashed line the group leaves the frame. The feasible framings (computed with Proposition 4 at 701 exact rational scales) are the triangle between the two lines. The optimum is its tip: at every larger scale the two shaded areas overlap, so no offset is left. The empty part of the chart is therefore not unused room. In this scene the long pennants, not the size cap, decide the size of the group.

The example has an optimum, and it is a fraction. The last result of this section says that this is always so.

Theorem 6 (existence and exactness). If Θ is not empty, the lexicographic optimum exists and its coordinates are rational numbers.
Proof. By Lemma 2, R3 is a finite conjunction of four-way disjunctions of weak linear inequalities, one for each pair of a face and a blocked pixel. R4 is a finite disjunction of an equality and such conjunctions. R1, the scale bounds and centring are weak linear conditions. Choosing one alternative in every disjunction gives a closed polyhedron, and there are finitely many choices, so Θ is a finite union of closed polyhedra. R1 bounds it, so Θ is compact. The scale 𝑠 is continuous and attains its maximum on Θ. The set of maximisers is again a finite union of compact polyhedra, on which the piecewise linear function |𝑦−𝑦∗(𝑠)| attains its minimum. All coefficients are rational, and a linear objective on a polyhedron with rational data attains its optimum at a point with rational coordinates.□

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.

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 𝑊/2+𝑠(𝑙𝑖−𝑆/2), and it crosses the boundary 𝑐 at the event scale 𝑠=(2𝑐−𝑊)/(2𝑙𝑖−𝑆). An edge at 𝑙𝑖=𝑆/2 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.

Lemma 7 (certificate). Let Θ⊆Θ′. If a framing belongs to Θ and is optimal in Θ′, it is optimal in Θ.

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.

Proposition 8 (largest centred clear rectangle).

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 𝜇=min𝑗≤𝑟<𝑘𝑤𝑟. 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

maxmaximal runs[𝑗,𝑘)min(𝑠max,𝜇𝑆,𝑘−𝑗𝑇).
Proof. A centred rectangle of width 𝑠𝑆 and height 𝑠𝑇 is clear exactly when 𝑠𝑆≤𝑤𝑟 for every row it touches. A rectangle that fits in the run [𝑗,𝑘) therefore has 𝑠𝑆≤𝜇 and 𝑠𝑇≤𝑘−𝑗, and these two conditions are also sufficient, with the top of the rectangle at row 𝑗. The rows of any feasible rectangle lie in some maximal run with 𝜇≥𝑠𝑆, so the maximum over maximal runs is an upper bound that is attained.□

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 𝑠min, Θ is empty.

4.2 Some photographs have no feasible framing

Theorem 9 (forced edge). Suppose a face box contains a group pixel 𝑞 on a side that the camera cut. If a framing satisfies R1, R3 and R4, then that side lies on its edge of the frame.
Proof. The placed pixel 𝜏𝜃(𝑞) has positive area and lies in the frame by R1, so it overlaps some frame pixel 𝑄 with positive area. Because 𝑞 is in a face box, R3 requires 𝛼(𝑄)=0. If the side were not on its frame edge, R4 would require 𝛼(𝑄)=255. A pixel has one opacity.□
Corollary 10. Let the camera cut a face at the bottom of the photograph. If, at every admissible scale, the foreground is blocked somewhere in the bottom row of the frame under that face, then Θ is empty.
Proof. By Theorem 9, 𝑦+𝑠𝑇=𝐻, so the placed face reaches the bottom row of the frame. A blocked pixel under it violates R3.□

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.

Silhouette of ten people behind a wave. Dashed boxes mark three faces of the front row that the wave covers.

(a) Cut on the edge, foreground in front

The group floats above the wave. A line marks the straight cut along the occupied parts of its lower side.

(b) Faces clear, cut inside the frame

The group stands behind the wave. The three faces of the front row are drawn in front of the wave.

(c) Cut on the edge, faces in front

Figure 6: The Wave scene: the group of Figure 1 in a frame with a wave. The camera cut 2 children of the front row at the face. (a) keeps the layer order and loses 3 faces under the wave (dashed boxes). (b) is the best framing that clears every face when R4 is dropped: the group moves up, and 100% of the sampled pixels of the bottom cut show as a straight line (marked) at 25% of the frame height above the bottom edge. (c) is the delivered picture: framing as in (a), with the faces drawn in front of the wave. The change moves 35% of the foreground’s opacity behind the group.

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 𝐶normal and 𝐶front be the two results at a pixel. The depth rule outputs

𝐶=(1−𝑚)𝐶normal+𝑚𝐶front,

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, 𝑚=1 on the whole group.

Proposition 11. The depth rule (a) leaves every pixel unchanged where the group or the foreground is absent, (b) draws the person in front of the foreground on every pixel of every protected face, and (c) does not move, reshape or recolour the foreground.
Proof. Where the foreground is transparent or the group is absent, 𝐶normal=𝐶front, so the weight has no effect. On a protected pixel 𝑚=1 and 𝐶=𝐶front. The rule changes only the order of the two layers at a pixel.□

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 𝑐fit=min(𝑊/𝑆,𝐻/𝑇) be the largest scale at which the box fits in the frame.

  • If no two opposite sides are cut, the scale is 𝑠=min(0.86𝐻/𝑇,𝑐fit). 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 𝑐fit 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.
Theorem 12 (a framing always exists). For every cutout with non-empty support and every frame with 𝑊,𝐻≥1, the fallback framing has 𝑠>0 and satisfies R1 and R2. Every side that the camera cut lies on its frame edge, or the whole group lies inside the drawn border. With the depth rule, no foreground is drawn over a protected face box.
Proof. In the first two cases 𝑠≤𝑐fit, hence 𝑠𝑆≤𝑊 and 𝑠𝑇≤𝐻. The offset 𝑥 is one of 0, 𝑊−𝑠𝑆 and (𝑊−𝑠𝑆)/2, all in [0,𝑊−𝑠𝑆]. The offset 𝑦 is 0, 𝐻−𝑠𝑇, or the vertical target clamped to [0,𝐻−𝑠𝑇]. In the third case 𝑠≤0.94𝑐fit and the box is centred. 𝑆, 𝑇, 𝑊 and 𝐻 are positive, so 𝑠>0. The last claim is Proposition 11(b).□
Input: cutout, foreground, frame size 𝑊×𝐻, optional face boxes
1box and cut sides ← support of the cutout
2𝜃fb← fallback framing — closed form, Theorem 12
3protected ← face boxes if valid, else the whole box
4𝜃← exact optimum in Θ within a time budget — Theorem 6, Propositions 8 and 13
5if 𝜃 exists: return foreground over group at 𝜃 over background
6𝑚← depth weight of the protected regions at 𝜃fb — Proposition 11
7return depth-rule picture at 𝜃fb, with the drawn border if needed
Algorithm 1: Framing with a guaranteed 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.

Proposition 13 (polynomial bound). If Θ is not empty, the optimal scale is 𝑠min, 𝑠max, an event scale of a vertical side of a constraint rectangle, or a ratio 𝑑/(𝑎−𝑎′). Here 𝑑 is an integer with 1≤𝑑≤𝐻, and 𝑎>𝑎′ are two of the numbers 0, 𝑇 and the top and bottom rows of the constraint rectangles. There are at most 𝐾=2𝑝(𝑊+1)+(𝑝+1)(2𝑝+1)𝐻+2 such scales. A test of the candidates from the largest downwards finds the optimum in 𝑂(𝑊𝐻+𝐾𝑝2𝐻) arithmetic operations on rational numbers.
Proof. With the group centred, 𝑥 is a function of 𝑠, and a framing is a point (𝑠,𝑦). By the proof of Theorem 6, Θ is a finite union of bounded closed polygons, and every edge of such a polygon lies on a line of one of two kinds. A condition on columns, 𝑥+𝑠𝑎≤𝑐 or its reverse, depends on 𝑠 alone. Its line is vertical, at an event scale of a vertical side of a constraint rectangle. The scale bounds are vertical lines too, and so is a cut on the left or right frame edge, which fixes 𝑠=𝑊/𝑆. A condition on rows gives a line 𝑦+𝑠𝑎=𝑟 with an integer row 0≤𝑟≤𝐻 and 𝑎 in the stated set. Containment and a cut on the top or bottom frame edge are conditions of this kind. The scale attains its maximum over a polygon at a vertex, and a vertex lies on two lines that are not parallel. Either one of them is vertical, or both are row lines, and the lines 𝑦+𝑠𝑎=𝑟 and 𝑦+𝑠𝑎′=𝑟′ meet at 𝑠=(𝑟−𝑟′)/(𝑎−𝑎′). The count has 2𝑝 vertical sides with 𝑊+1 column boundaries each, and (𝑝+1)(2𝑝+1) pairs from at most 2𝑝+2 row numbers with 𝐻 values of 𝑑. For a fixed scale, every constraint rectangle allows a union of at most 𝐻 intervals of offsets: the clear runs of Lemma 3 for a face box, and the opaque runs or the one offset of its frame edge for a run of a cut. The intersection of these 𝑝 sorted unions takes 𝑂(𝑝2𝐻) steps, because the result of 𝑖 unions has at most 𝑖𝐻 intervals. The row sums of blocked and of non-opaque pixels cost 𝑂(𝑊𝐻) once. The first candidate with a non-empty intersection is the optimal scale, and the offset nearest to the target follows as in Proposition 4.□

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 𝑠=5/7, 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 (crop window). If 𝜌<1, height fitting shows exactly the central fraction 𝜌 of the photograph’s width: a group pixel at horizontal position 𝑢∈[0,1] is shown if and only if |𝑢−1/2|≤𝜌/2. If 𝜌>1, the whole photograph is shown, and its left and right edges lie inside the frame.
Proof. The scaled photograph is 𝑤𝐻/ℎ pixels wide and centred. The frame shows 𝑊 of them, the fraction 𝑊ℎ/(𝑤𝐻)=𝜌.□

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, 𝜌=8/9: height fitting discards 5.56% of the photograph at each side. For a 7:5 frame it discards 3.33% at each side.

Theorem 15 (comparison).

For every photograph, foreground and frame size:

(i) The proposed framing satisfies R1 and R2. Height fitting violates R1 exactly when 𝜌<1 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 𝜌>1, 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.

Proof. (i) and (iii) follow from Theorem 12, Proposition 14 and the definition of Θ. (ii) follows from R3 for a framing in Θ and from Proposition 11 otherwise. (iv) is Theorem 6 with Lemma 7.□

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.

RequirementHeight fittingProposed
Group inside the frameOnly inside the central windowAlways (Theorem 12)
One scale for allYesYes
Faces not under foregroundNot testedThe supplied face boxes: by framing, else by layer order
Camera cutsTop and bottom on the edge. Sides inside the frame if 𝜌>1On an edge, under opaque foreground, or inside a border
CentringCentres the photographCentres the group, unless a side cut pins it
Group sizeFixed by the camera distanceLargest feasible up to the size cap, else the fallback scale
Picture for every inputYesYes (Theorem 12)
Table 1: The two methods against the requirements of Section 2.

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

MeasureHeight fittingProposed
Cutouts cropped at a side, 4:3 frame (𝑛=1,791)457 (25.5%)0
Cutouts cropped at a side, 7:5 frame (𝑛=1,791)400 (22.3%)0
Face regions with ≥ 10% lost, three formats (𝑛=108)200
Pictures with such a face (𝑛=27)130
Face regions with ≥ 10% lost, 3000 × 2250 px (𝑛=36)80
Time for one 3000 × 2250 px picture, mean0.49 s1.54 s
Table 2: Height fitting and the proposed method on production data. A face region is lost when at least 10% of the person’s pixels in it are cropped or under foreground in the final image. The proposed method received the face boxes.

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 fittingProposed
With at least one defect (𝑛=12,448)3,219 (258.6)285 (22.9)
a person cropped3,046 (244.7)4 (0.3)
a face lost552 (44.3)0 (0)
a camera cut visible0 (0)281 (22.6)
With a defect, 3:2 cameras (𝑛=10,848)3,167 (291.9)259 (23.9)
With a defect, 4:3 cameras (𝑛=1,587)52 (32.8)26 (16.4)
Table 3: The production backtest. Each photograph is counted once, on the format that was printed.

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.

Two charts in which up and right is better. Left: prints without a defect per 1,000 against median group height, for several placement policies. Height fitting is at 741 prints without a defect and 89.5 percent height. The proposed method is at 977 for every size cap from 60 to 100 percent, to the right of every other policy. Right: the share of foreground opacity that stays in front of the group, against median group height, for the proposed method. It is highest, at 99.80 percent, for size caps of 70 and 80 percent, and it falls to 99.71 percent at a cap of 100 percent. Height fitting is at 100 percent.
Figure 7: The frontier on the 12,448 backtest photographs, drawn so that up and right is better. (a) Every size cap of the proposed method leaves 977 of 1,000 prints without a defect, and each of the seven other policies leaves fewer. The panels show two of the four measures. (b) Above a cap of 80%, a larger group leaves a little less foreground in front. Height fitting leaves all of it, because it does not protect faces.

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.

Two charts over thirteen output shapes from 1:3 to 3:1. Left: share of groups with an exact optimum. The method of Section 4 falls from about 65 percent near the print formats to 5 percent at 1:3. The aspect-free variant stays between 58 and 78 percent. Right: height fitting crops nearly every group on tall frames and loses up to 55 percent of faces; both exact methods stay at zero.
Figure 8: 1,887 archived groups on 13 output shapes, with the real foreground stretched to the frame. The shaded band marks the three print formats. (a) The lower size bound of Section 2 empties the search on tall frames; the aspect-free variant removes this. (b) Height fitting has failed trials on every tested shape that is narrower than the photograph.

An aspect-free form. Two changes remove the dependence on the shape.

  1. Size. Let 𝑐fit=min(𝑊/𝑆,𝐻/𝑇) 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 0.6𝑐fit, 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.
  2. 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.

Theorem 16 (any frame shape).

For every frame size 𝑊≥1 and 𝐻≥2, 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.

Proof. (i) Let 𝑢 be the upper end of the interval: the smaller of 𝑐fit and the size cap ⌊0.86𝐻⌋/𝑇. It is positive because 𝐻≥2. An empty interval is replaced by [min(0.6𝑐fit,𝑢),𝑢], which is not empty. (ii) is Theorem 6 with a free 𝑥. The set is still a finite union of compact polyhedra with rational data. After a split along the two planes on which a distance of the objective changes sign, each objective is linear on each piece. (iii) A non-empty Θ has a non-empty interval, which change 1 keeps. Θ is then the set of centred framings in Θ+, and these are the framings at horizontal distance zero. The first objective selects them, and the other objectives and the tie rule are those of Section 2. (iv) Theorem 12 assumes nothing about 𝑊 and 𝐻.□

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 theoremStatement in this paper
uniform_displacementR2: one scale moves any two points apart by the factor 𝑠
group_enclosure_exactLemma 1, for any list of boxes
separated_iff_clearLemma 2
clear_exactProposition 4: unions of intervals are intersected exactly
vertical_projectionLemma 5
relaxation_certificateLemma 7
envelope_optimal, envelope_attainedProposition 8, on any fixed scale denominator
shared_patch_forces_borderTheorem 9, for general opacity thresholds
Table 4: The machine-checked lemmas. Lemma 3, Theorem 6, Corollary 10, Propositions 11, 13 and 14, and Theorems 12 and 15 are proved in this paper only. Theorem 16 rests in part on four further lemmas (see below).

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.

  1. 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.
  2. 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 𝑠2 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.

Download and cite

Cite as: Matvei Lapushinskii. Optimal Framing for Group Photographs. TheArtisan.ai, Amsterdam, 27 November 2026. https://theartisan.ai/technology/optimal-framing