A 4× upscale saved at quality 100 scored 62,21 dB against the buffer it came from. The same file, same bytes, same 106,9 KB, scored 46,58 dB against the photograph it was made from.
Nothing about the JPEG changed between those two measurements. The only variable was the picture I held up as the reference, and moving it cost 15,63 dB.
That gap is the whole subject of this article, and it explains a class of advice you have probably read: "upscale first, then export at high quality, because the file is big anyway." The byte saving is real. The quality claim attached to it usually is not.
The two yardsticks, and why only one of them is about your picture
When you save a JPEG and then measure PSNR, the obvious reference is the buffer you handed to the encoder:
PSNR( buffer_before_save , pixels_after_save ) Call this the arm-local score. It answers one question: how faithfully did the encoder reproduce what I gave it? That is a legitimate engineering question. It is also, on its own, completely blind to whether the thing you gave the encoder was any good.
The other yardstick is the picture as it existed before you started mangling it:
PSNR( native_crop , delivery_after_upscale_and_save ) Call this the truth score. It answers: does the reader end up with more of the real scene?
My 62,21 dB file was a real 512-pixel crop upscaled 4× to 2048 and saved at q100. The encoder did an excellent job on the buffer it was handed. The buffer was a reconstruction, and the reconstruction was not the photograph.
The method, so you can attack it
Seven photographs, one 512-pixel centre crop each, taken from the campaign's data/images/ set — all real photos, no synthetic charts, no test patterns. Pillow and numpy.
The truth for every measurement is the native 512-pixel crop. That is the best detail actually available for that patch of scene, and it is the same image in every arm.
There are two experiments, and they answer different halves of the question.
Experiment 1 — the scoreboard question. Take the native 512 crop, upscale it to 4× (2048 px) with Lanczos, save that buffer at quality q, then block-average the result back down to 512 so it can be compared with the truth at all. This is the file whose arm-local score is 62,21 dB at q100. The block-averaging is necessary and it is also a caveat: an f×f block of the 2048 field covers exactly one pixel of the 512 truth, so averaging is the only like-for-like comparison. It is not the Laplacian of a re-downsampled image; it is per-native-pixel curvature.
Experiment 2 — the delivery question. Build a 512-pixel delivery from a smaller source: Lanczos down to the target size, Lanczos back up to 512, save at q. Three arms:
| arm | what happens to the source |
|---|---|
| native 512 | saved directly at quality q (no resize at all) |
| 2× from 256 | Lanczos down to 256, Lanczos back up to 512, saved at q |
| 4× from 128 | Lanczos down to 128, Lanczos back up to 512, saved at q |
The downscale is how I create the low-resolution source. It is a deliberate simulation, and I will be honest about what it can and cannot model at the end. Experiment 2 is the one that produces the money table, because all three arms deliver the same 512×512 output and differ only in how much detail they had to work with.
For the structural half of the analysis I use the Laplacian field of the luma plane — a 4-neighbour second difference, the same operator as nhip115_jpeg_F.py. It responds to curvature, so it is sensitive to exactly the detail an upscale is supposed to add.
Seven controls, all passing on the run that produced every number below:
| control | what it proves | result |
|---|---|---|
| K1 | this run's 1× save PSNR matches the stored nhip115_jpeg_E.json | 45,93 dB = 45,93 dB |
| K2 | this run's 1× keep_pct matches the same file | 102,79 % = 102,79 % |
| K3 | the encoder is deterministic on this machine | identical bytes twice |
| K4 | the round trip at factor 1 is the identity | true |
| K5 | a flat 128 field at q100 survives exactly | max deviation 0 |
| K6 | no saved arm beats its own resampling round trip | all overshoots ≤ 0 |
| K7 | the native arm's r² matches nhip115_jpeg_H.json at all five q | 5/5 exact |
K6 is the one worth staring at. Adding a lossy step to a pipeline cannot increase fidelity to the original. If any arm had scored above its encoder-free round trip, the measurement would be broken. None did — the largest overshoot was −0,003 dB.
The scoreboard climbs 12,80 dB. The truth climbs 0,85 dB.
Experiment 1, at 4×, saved at five quality settings, measured both ways:
| q | r² vs its own buffer | r² vs the truth | PSNR vs its own buffer | PSNR vs the truth |
|---|---|---|---|---|
| 70 | 0,2920 | 0,0117 | 49,41 dB | 45,731 dB |
| 85 | 0,3752 | 0,0115 | 52,53 dB | 46,307 dB |
| 90 | 0,4320 | 0,0113 | 54,26 dB | 46,468 dB |
| 95 | 0,5384 | 0,0113 | 56,59 dB | 46,531 dB |
| 100 | 0,8378 | 0,0115 | 62,21 dB | 46,578 dB |
Read the PSNR columns together. Going from q70 to q100:
- the scoreboard rises 12,80 dB — a transformation, the kind of number that makes people say "wow, q100 is so much better"
- the truth rises 0,847 dB — three quarters of a dB, invisible
- the reported gap between the two widens from 3,68 dB to 15,63 dB
And the r² column is worse than flat. Against its own buffer the structure correlation climbs from 0,2920 to 0,8378, a 187 % relative improvement, because the encoder is now faithfully reproducing the smoothing artefacts it produced at low q. Against the truth it goes 0,0117 → 0,0115. It drifts down. At q100 you are paying five times the bitrate to reproduce, with exquisite precision, a structure that was already 98,9 % gone.
The sharpest version of that statement needs Experiment 2, because the file whose arm-local r² is highest is the 512-delivery built from 128:
| the same 4× q100 file, 106,9 KB | r² |
|---|---|
| measured against the buffer the encoder was handed (arm-local) | 0,8979 |
| measured against the native crop it was made from (truth) | 0,0286 |
Identical bytes, identical 106,9 KB to the tenth of a KB. A 31× difference in reported structural fidelity, decided entirely by which picture you hold up as the reference. Not one parameter of the encoder changed between those two lines.
Why: the save keeps 0,43 of a signal that is only 0,01 real
The r² numbers above are not a paradox once you separate the two things that happen to a pixel on its way to the reader:
| factor, all saves at q90 | r² truth→upscale | r² upscale→save | r² truth→save | save PSNR (arm-local) |
|---|---|---|---|---|
| 1× | 1,0000 | 0,9122 | 0,9122 | 45,93 dB |
| 2× | 0,2164 | 0,8356 | 0,2114 | 51,27 dB |
| 3× | 0,0244 | 0,6688 | 0,0235 | 53,33 dB |
| 4× | 0,0116 | 0,4320 | 0,0113 | 54,26 dB |
At 1× the resize column is 1,0000, because the "resize" is the identity. The save is the only thing that touches the file, so it takes the whole 0,088 of loss and everything is coherent.
At 4× the columns split apart. The resize round trip destroys structure down to 0,0116. The save then takes that wreckage and preserves 0,4320 of it. The reader receives 0,0113. The save's own honesty — 43 % of the structure survived my encoder — is a percentage of almost nothing. It reads, in a report, as a mid-range result. It is a mid-range result on a quantity whose denominator has already been voided.
The keep_pct column of the energy measurement shows the same trap from a different angle. Absolute high-frequency energy after a q90 save, as a percentage of before:
| factor | HF before save | HF after save | keep % |
|---|---|---|---|
| 1× | 6,108 | 6,279 | 102,79 % |
| 2× | 2,301 | 2,472 | 107,48 % |
| 3× | 1,314 | 1,523 | 116,01 % |
| 4× | 1,021 | 1,149 | 112,53 % |
Every number is over 100 %. The save added high-frequency energy at every single scale. That is not detail: it is quantization noise, which is curvature by definition, summed into a metric that cannot tell curvature from structure. The percentage even rises with the factor — 102,79 % at 1× to 116,01 % at 3× — because the signal being "preserved" is smaller, so the same amount of injected noise is a larger fraction of it. A metric that goes up when you damage the picture more comprehensively is not measuring the picture.
nhip115_jpeg_F.py was written because I did not believe the 102,79 %. It separates the two signals by correlation rather than magnitude, and it confirms the diagnosis: at 1× the save's gain is 0,9609 and the orthogonal residual is 6,017; at 4× the gain falls to 0,7267 while the residual stays substantial. The energy sum was never detail. The flat-field control (F2) settles it: a uniform 128 field saved at q75, q90 and q100 comes back with one distinct value, min = max = 128. There is no curvature to preserve in a flat field, so none appears. Everything measured over 100 % on real photos came from the encoder, not the scene.
The JPEG is innocent. The resize already spent it.
If the save were the problem, the fix would be obvious: raise q, or drop JPEG. Neither works, and the reason is that the bill was paid before the encoder saw the file.
Measure the resampling round trip with no encoder at all — downsample to the target size and upsample back, then compare to the truth:
| arm | resize round trip alone | same arm, best possible JPEG (q100) | what JPEG costs |
|---|---|---|---|
| native 512 | 99,00 dB (identity) | 58,86 dB | 40,14 dB |
| 2× from 256 | 35,567 dB | 35,554 dB | 0,013 dB |
| 4× from 128 | 29,530 dB | 29,527 dB | 0,003 dB |
That is the answer, and it is not the one I expected. At 2× and 4×, the encoder costs one to three hundredths of a decibel. Avalanche, chroma subsampling, rounding, DCT — all of it, together, in seven photos, costs 0,003 dB. The 29,53 dB you get is 29,53 dB before compression is applied.
The arm is capped by its own resampling. No quality setting, no codec, no byte count can move it, because the information was discarded by the downscale and the upscale is reconstructing a plausible smooth field rather than recovering the original. When I checked the ceiling explicitly — the best PSNR each arm achieves at any quality from q70 to q100 — the picture is the same:
| arm | best truth-PSNR (its ceiling) | at q | size there | cheapest q | size there |
|---|---|---|---|---|---|
| native 512 | 58,86 dB | 100 | 135,6 KB | 70 | 24,3 KB (40,76 dB) |
| 2× from 256 | 35,55 dB | 100 | 122,2 KB | 70 | 22,7 KB (34,96 dB) |
| 4× from 128 | 29,53 dB | 100 | 106,9 KB | 70 | 20,0 KB (29,46 dB) |
Look at the last two rows. For the 4× arm, the entire q70-to-q100 range buys 0,07 dB (29,46 → 29,53). For the 2× arm, 0,59 dB (34,96 → 35,55). For the native arm, 18,10 dB (40,76 → 58,86). Compression headroom exists only where there is real detail for the encoder to spend bits on. On an upscaled buffer there is no such detail, so the quality slider is a volume knob wired to nothing.
The money question, at one honest yardstick
Same fidelity yardstick — PSNR against the native truth — for three deliveries:
| delivery | file size | PSNR vs truth | r² vs truth |
|---|---|---|---|
| native 512, q70 | 24,3 KB | 40,76 dB | 0,7578 |
| native 512, q90 | 44,5 KB | 45,93 dB | 0,9122 |
| native 512, q100 | 135,6 KB | 58,86 dB | 0,9958 |
| 2× from 256, q100 | 122,2 KB | 35,55 dB | 0,2551 |
| 4× from 128, q100 | 106,9 KB | 29,53 dB | 0,0286 |
The cheapest native save in the table — q70, 24,3 KB, the setting most people would call "good enough for the web" — beats the most expensive 4× save by 11,23 dB, at 4,40× fewer bytes, with 26× the structural correlation. There is no quality setting at which the upscale catches up, because there is no quality setting that addresses the actual loss.
The r²-per-kilobyte column of nhip115_jpeg_H.json makes the incentive explicit. The native arm falls from 0,03114 r²/KB at q70 to 0,00734 at q100 — diminishing returns, as you would expect. The 4× arm falls from 0,02102 to 0,00840. Both lose efficiency as quality rises. But the 4× arm's starting efficiency is worse than the native arm's ending efficiency, and it never recovers. You are buying a worse product at a worse rate.
Quality 100 is not lossless, and that is a separate bill
Everything above is about the yardstick. This part is about q100 itself, because the "just save it at maximum" advice deserves its own audit.
Save the same seven crops at q95, q100 and q100 with 4:4:4 chroma and compare to the pre-save buffer:
| setting | mean absolute error | max error | mean size | PSNR |
|---|---|---|---|---|
| q95, default 4:2:0 | 0,8386 code levels | 34 | 64,9 KB | 44,974 dB |
| q100, default 4:2:0 | 0,2587 | 28 | 135,6 KB | 49,249 dB |
| q100, 4:4:4 | 0,1281 | 4 | 183,1 KB | 56,164 dB |
Quality 100 is not lossless. It rounds DCT coefficients instead of quantizing them flat, but it still rounds, and 24,82 % of pixels come back changed. A mean error of a quarter of a code level sounds negligible until you remember that it is applied to every pixel in a file you have already paid a generation for. And the max error of 28 at q100 is only 6 less than the max error of 34 at q95 — the tail does not disappear, it thins.
The chroma half is worth knowing separately: switching to 4:4:4 at q100 cuts max error from 28 to 4 and buys 6,9 dB, at 35 % more bytes. If you have a file with saturated colour on a hard edge — signage, product colour, a red logo on white — that is the setting that does something, and it has nothing to do with upscaling.
Progressive JPEG: a free 10 %, until you upscale
nhip115_jpeg.json also settles a related question. Progressive and baseline JPEG at the same quality are pixel-identical — confirmed across the ladder and at every scale factor in F3 — and progressive is smaller:
| q | baseline | progressive | saved | scans | pixels identical |
|---|---|---|---|---|---|
| 70 | 24,3 KB | 24,0 KB | 1,45 % | 1 / 10 | yes |
| 80 | 30,2 KB | 29,7 KB | 1,81 % | 1 / 10 | yes |
| 85 | 35,3 KB | 34,3 KB | 2,58 % | 1 / 10 | yes |
| 90 | 44,5 KB | 42,6 KB | 4,26 % | 1 / 10 | yes |
| 95 | 64,9 KB | 60,3 KB | 7,10 % | 1 / 10 | yes |
| 100 | 135,6 KB | 121,8 KB | 10,16 % | 1 / 10 | yes |
A free 10 % at q100, zero quality change, and the progressive scan structure lets a browser paint something useful before the last scan arrives. There is no argument against it.
But it does not compose with upscaling. Re-run the same comparison on the resized buffers:
| factor at q90 | baseline | progressive | saved |
|---|---|---|---|
| 1× | 44,5 KB | 42,6 KB | 4,26 % |
| 2× | 113,7 KB | 110,5 KB | 2,85 % |
| 4× | 295,0 KB | 286,3 KB | 2,96 % |
The saving drops from 4,26 % to under 3 % once the image has been resized. The bytes-per-pixel column explains why: 0,1736 at native falls to 0,0720 at 4×. Upscaled buffers are already compressible in the trivial sense — they contain little genuine high-frequency content — so there is less for progressive's scan reordering to exploit. You keep the 3 %, and you are still paying 6,6× the bytes of the native file for a worse picture.
What this does NOT show, which matters
I need to be precise about the boundary, because the temptation to overclaim here is enormous.
This measurement compares a delivery against the detail that was genuinely in the scene. My 4× arm is built by discarding detail from a 512 crop and then asking the upscale to put it back. It answers: how much of the removed detail comes back? The answer, measured seven ways, is essentially none — r² 0,0113 against the truth.
It does not measure what a generative upscaler does when there is no ground truth at all — when the 128-pixel source is all anyone ever had except the scene itself, and the model invents plausible texture instead of reconstructing recorded texture. That is a different question with a different answer, and a model that produces convincing skin pores on a 2003 phone photo is not "wrong" because my r² says 0,0113 — my r² has nothing to say about it, because there is no native 512 crop in existence to compare against.
So the honest claim is narrow and it is still useful: an upscaler that reconstructs, rather than one that generates, cannot recover detail that was removed, and no quality setting changes that. When you open a file, upscale it, export at maximum quality and then evaluate the result by comparing it to the buffer you exported from, you are grading the encoder's homework on a question you already failed. If the upscale was reconstructive, moving that same arm from q70 to q100 buys 0,07 dB for 5,35× the bytes, and the result is still 11,23 dB worse than a native save 4,40× smaller.
The practical test takes thirty seconds. Take whatever you upscaled, downscale it back to the original dimensions, and compare that to the original with any PSNR or SSIM tool. If the round trip lands within a couple of dB, the upscale added nothing you can detect and you are paying for bytes. If it lands far higher, something generative happened, and the file is worth its size for reasons my measurement cannot audit.
If you want to run the comparison side by side without installing anything, UpgoLAB's browser upscaler does a 2× in the tab — enough to produce the round-trip pair this article is about, and to look at the patch that actually matters at 100 % before you commit to a file size.
That 28-second clip is a pass through five presets on real product frames — direct link if the embed does not load. It is not the measurement in this article; it is the other half of the same decision, because a preset that generates texture and a preset that reconstructs it produce files that fail in opposite directions, and the round-trip test above tells you which one you got.
The checklist
- Decide which score you are reporting. Arm-local PSNR tells you the encoder worked. Truth PSNR tells you the reader got a better picture. On the 4× q100 file they read 62,21 dB and 46,58 dB — a 15,63 dB gap on identical bytes, growing from 3,68 dB at q70. Publishing the first while claiming the second is the entire error.
- Never trust a
keep_pctor "detail preserved" figure above 100 %. It is quantization noise. Mine read 102,79 % to 116,01 % at q90 and the signal was 0,0113 real. A flat field at q100 returning one distinct value is the control that proves the metric was measuring the encoder. - Measure the resampling round trip with no encoder in the path. At 2× it was 35,567 dB and the encoder cost 0,013 dB; at 4× it was 29,530 dB and the encoder cost 0,003 dB. If those two numbers are close, the quality slider is not your lever.
- Compare q70 to q100 before assuming headroom exists. Native: +18,10 dB. 2×: +0,59 dB. 4×: +0,07 dB. Compression headroom is a function of real detail, and an upscaled buffer has very little.
- Do the 30-second round-trip test on anything you are about to ship: downscale the upscale back to the original size, compare to the original. A couple of dB means you are buying bytes.
- Use progressive JPEG always — pixel-identical, 1,45 % to 10,16 % smaller, and it paints earlier. Expect the saving to shrink to about 3 % after a resize, and expect it not to fix anything else.
- If colour edges matter, that is 4:4:4's job, not q100's. Max error 28 → 4 at the same quality setting. It is a chroma problem and no amount of luma bitrate touches it.
Seven photographs, one 512-pixel centre crop each, Pillow and numpy. Every figure above comes from five files in this campaign's tracking/ directory: nhip127_hf_budget.json (new this run — the truth-referenced panels, the round-trip decomposition and the ceiling table), nhip115_jpeg.json, nhip115_jpeg_E.json, nhip115_jpeg_F.json, nhip115_jpeg_G.json and nhip115_jpeg_H.json. The E/F/G/H files were re-run before writing and reproduce their stored values bit-exact; K1, K2 and K7 are those reproductions asserted inside the new script rather than checked by eye. Baseline and progressive JPEG, scan structure and the quantization tables are specified in ITU-T T.81 and summarised at JPEG; chroma subsampling ratios and the 4:2:0 / 4:4:4 distinction are covered at chroma subsampling. The numbers that contradict the advice are the point — I expected the encoder to be the culprit and it was 0,003 dB of a 70 dB problem.

