<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: celticgemini001</title>
    <description>The latest articles on DEV Community by celticgemini001 (@celticgemini001).</description>
    <link>https://dev.to/celticgemini001</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4233848%2F296f5ea7-82c1-401c-a8f4-96364f651175.png</url>
      <title>DEV Community: celticgemini001</title>
      <link>https://dev.to/celticgemini001</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/celticgemini001"/>
    <language>en</language>
    <item>
      <title>An Upscaler Does Not Remove a Hot Pixel. It Smears It Into Exactly f of Them.</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Sun, 29 Nov 2026 16:21:15 +0000</pubDate>
      <link>https://dev.to/celticgemini001/an-upscaler-does-not-remove-a-hot-pixel-it-smears-it-into-exactly-f2-of-them-53i6</link>
      <guid>https://dev.to/celticgemini001/an-upscaler-does-not-remove-a-hot-pixel-it-smears-it-into-exactly-f2-of-them-53i6</guid>
      <description>&lt;p&gt;My first instrument reported that a 2× upscale removed &lt;strong&gt;99.76 %&lt;/strong&gt; of the salt-and-pepper noise I had injected into seven photographs. That number is real. It is also wrong, and the reason it is wrong is the most useful thing I learned in this whole experiment: the upscaler did not remove the noise, it diluted it below the threshold my instrument was using to call something noise.&lt;/p&gt;

&lt;p&gt;Here is the short version of what actually happens to a single corrupted pixel when you resize by a factor &lt;em&gt;f&lt;/em&gt; with bilinear interpolation. Its total energy is conserved &lt;strong&gt;exactly&lt;/strong&gt;: the sum of the deltas it leaves behind is &lt;code&gt;127 · f²&lt;/code&gt; code levels, no more and no less. What changes is the peak. At 2× the peak drops to 55.9 % of its original height. At 3× it does not drop at all — it is &lt;strong&gt;100 %&lt;/strong&gt;. At 4×, 76.4 %. At 8×, 88.2 %. The sequence is not monotonic and it is not an artefact of any algorithm: it falls out of where the output pixel centres land relative to the source sample, and it can be predicted to within 0.006 of the measured value with one multiplication.&lt;/p&gt;

&lt;p&gt;Everything below comes out of five files in this campaign's &lt;code&gt;tracking/&lt;/code&gt; directory: &lt;code&gt;nhip112_impulse.json&lt;/code&gt;, &lt;code&gt;nhip121_med_cost.json&lt;/code&gt;, &lt;code&gt;nhip121_hotpixel_census.json&lt;/code&gt;, &lt;code&gt;nhip122_crossover.json&lt;/code&gt;, &lt;code&gt;nhip123_geom_exact.json&lt;/code&gt; and &lt;code&gt;nhip123_energy.json&lt;/code&gt;. Seven photographs, 512-pixel centre crops, grayscale, bilinear resize, and injection masks tracked by coordinate rather than by brightness threshold — that last decision is the whole reason the second instrument worked and the first one did not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first instrument found 977 defective pixels that were never defective
&lt;/h2&gt;

&lt;p&gt;I wanted to know how far a point defect spreads after an upscale. The obvious way to measure "did the defect survive" is to count pixels pinned at 0 or 255, because that is what salt-and-pepper noise is: dead black and blown white. So version one counted exactly that. It reported a large, satisfying removal rate.&lt;/p&gt;

&lt;p&gt;Then a control caught it. I ran the same counter on the clean, uncorrupted crops — no noise injected at all — and it found survivors anyway. That is impossible unless the counter is reading something other than my noise.&lt;/p&gt;

&lt;p&gt;So I counted the real thing. In the same seven 512-pixel crops, before any processing:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;crop&lt;/th&gt;
&lt;th&gt;pixels at 0&lt;/th&gt;
&lt;th&gt;pixels at 255&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;med_048d3778&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_1344197c&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_6766a320&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;216&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_792e8b64&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;653&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_ac7b6755&lt;/td&gt;
&lt;td&gt;21&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_b4fd2338&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_c079d084&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;754&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;223&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Nine hundred and seventy-seven genuinely clipped pixels in 1,835,008 samples — about 0.053 %. They are not defects. They are specular highlights, deep shadows, the black inside a lens barrel, and every one of them is a correctly exposed part of a real photograph. A threshold-based defect detector cannot tell them apart from injected noise, because there is nothing to tell apart: both are the value 255.&lt;/p&gt;

&lt;p&gt;Version two replaced the threshold with a mask. When I inject a corrupted pixel, I record its coordinate. When I ask "did it survive", I ask whether the output pixels whose nearest source sample is that coordinate are still pinned. Now "survived" is exact and needs no threshold, and the clean-frame control returns zero for every arm. That control is &lt;code&gt;C1_clean_survivors&lt;/code&gt; in &lt;code&gt;nhip112_impulse.json&lt;/code&gt; and it is the only reason the numbers in this article mean anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  What one bright pixel actually becomes
&lt;/h2&gt;

&lt;p&gt;Take a 64×64 field that is uniformly 128 and set one pixel to 255. Resize it. This is not a photograph and not a JPEG, so nothing you see is a compression artefact — it is the resampler and nothing else.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor&lt;/th&gt;
&lt;th&gt;pixels touched&lt;/th&gt;
&lt;th&gt;bbox (px)&lt;/th&gt;
&lt;th&gt;peak (levels)&lt;/th&gt;
&lt;th&gt;peak ÷ 127&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;71.0&lt;/td&gt;
&lt;td&gt;0.5591&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;127.0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.0000&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;97.0&lt;/td&gt;
&lt;td&gt;0.7638&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6×&lt;/td&gt;
&lt;td&gt;144&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;106.0&lt;/td&gt;
&lt;td&gt;0.8346&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8×&lt;/td&gt;
&lt;td&gt;256&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;112.0&lt;/td&gt;
&lt;td&gt;0.8819&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa528p0mq48kfn0h45xlz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa528p0mq48kfn0h45xlz.png" alt="Left: the peak a single hot pixel retains against upscale factor, with the analytic bilinear weight overlaid. Right: the measured damage extent, against the rule 2f for even factors and 2f − 1 for odd factors, extended to 16×." width="799" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two things in that table are worth stopping on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The peak is not monotonic.&lt;/strong&gt; If upscaling progressively blurred a defect, the peak would fall as the factor rose. It does not: 2× costs you 44 % of the peak and 8× costs you 12 %. 3× costs you nothing at all. Any mental model in which "higher factor = more smoothing of small features" is refuted by the 3× row.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The footprint is 4 pixels at 2×, not 2.&lt;/strong&gt; The naive expectation — one source pixel becomes one 2×2 block — describes which output pixels have that pixel as their &lt;em&gt;nearest&lt;/em&gt; source, not the extent of the damage. The damage bleeds into neighbouring pixels at a peak of 71 levels. That distinction is what broke the first instrument, and it is also what decides which repair filter works later.&lt;/p&gt;

&lt;h2&gt;
  
  
  The peak loss is bilinear weight arithmetic, not an algorithm
&lt;/h2&gt;

&lt;p&gt;Here is the part I expected to be messy and turned out to be exact. Bilinear interpolation at output pixel &lt;em&gt;i&lt;/em&gt; samples the source at coordinate &lt;code&gt;(i + 0.5)/f − 0.5&lt;/code&gt;. If that coordinate lands at fractional distance &lt;em&gt;d&lt;/em&gt; from the nearest source sample, the weight on that sample — in one dimension — is &lt;code&gt;1 − d&lt;/code&gt;, and in two dimensions &lt;code&gt;(1 − dx)(1 − dy)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For an even factor, the pixel centre lands halfway between samples. For an odd factor, it lands exactly on one.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor&lt;/th&gt;
&lt;th&gt;source coord of the peak&lt;/th&gt;
&lt;th&gt;fractional offset&lt;/th&gt;
&lt;th&gt;predicted weight&lt;/th&gt;
&lt;th&gt;measured&lt;/th&gt;
&lt;th&gt;error&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;31.750&lt;/td&gt;
&lt;td&gt;0.25&lt;/td&gt;
&lt;td&gt;0.5625&lt;/td&gt;
&lt;td&gt;0.5591&lt;/td&gt;
&lt;td&gt;−0.0034&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;32.000&lt;/td&gt;
&lt;td&gt;0.00&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.0000&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1.0000&lt;/td&gt;
&lt;td&gt;0.0000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;31.875&lt;/td&gt;
&lt;td&gt;0.125&lt;/td&gt;
&lt;td&gt;0.7656&lt;/td&gt;
&lt;td&gt;0.7638&lt;/td&gt;
&lt;td&gt;−0.0018&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6×&lt;/td&gt;
&lt;td&gt;31.9167&lt;/td&gt;
&lt;td&gt;0.0833&lt;/td&gt;
&lt;td&gt;0.8403&lt;/td&gt;
&lt;td&gt;0.8346&lt;/td&gt;
&lt;td&gt;−0.0057&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8×&lt;/td&gt;
&lt;td&gt;31.9375&lt;/td&gt;
&lt;td&gt;0.0625&lt;/td&gt;
&lt;td&gt;0.8789&lt;/td&gt;
&lt;td&gt;0.8819&lt;/td&gt;
&lt;td&gt;+0.0030&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Largest error across all five factors: &lt;strong&gt;0.0057&lt;/strong&gt;, which is less than one code level out of 127. There is no fitting and no free parameter here — &lt;code&gt;(1 − 1/(2f))²&lt;/code&gt; is the entire model, and it explains a curve that looks arbitrary.&lt;/p&gt;

&lt;p&gt;The 3× case is exact because &lt;code&gt;(3 + 0.5)/3 − 0.5 = 0.6667&lt;/code&gt;, and the nearest integer is 1, at distance 0.3333... no. Let me state it the way it actually computes: the output pixel with the maximum response sits at source coordinate 32.0 exactly, which is the injected pixel itself, at distance zero. Weight 1.0. The impulse passes through a 3× bilinear resize untouched in peak, spread over a 5×5 area.&lt;/p&gt;

&lt;p&gt;The tiny negative bias at 2×, 4× and 6× is quantisation: the operation runs in 8-bit, so a delta of 71 is really 70.9 rounded. That is the whole residual.&lt;/p&gt;

&lt;h2&gt;
  
  
  Energy is conserved exactly, and that is why "removed" was the wrong word
&lt;/h2&gt;

&lt;p&gt;Sum every delta the defect leaves in the output and divide by 127 — the total budget of one full-scale pixel:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor&lt;/th&gt;
&lt;th&gt;Δ sum ÷ 127&lt;/th&gt;
&lt;th&gt;ideal f²&lt;/th&gt;
&lt;th&gt;footprint&lt;/th&gt;
&lt;th&gt;Δ sum ÷ peak&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;4.000&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;7.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;9.000&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;9.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;16.000&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;20.95&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5×&lt;/td&gt;
&lt;td&gt;25.000&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;25.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6×&lt;/td&gt;
&lt;td&gt;36.031&lt;/td&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;43.17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8×&lt;/td&gt;
&lt;td&gt;64.504&lt;/td&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;73.14&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The total is &lt;code&gt;f²&lt;/code&gt; to within 0.8 % at every factor I measured, up to 16×. Bilinear resize distributes a point source over f² units of area — as you would expect from conservation — and does not attenuate it.&lt;/p&gt;

&lt;p&gt;Which means my headline number was describing my instrument, not the image. "99.76 % of injected impulses removed" was computed by counting output pixels still pinned at 0 or 255. At 2× the peak is 71 levels above background, so a salt pixel at 255 becomes 199 and a pepper pixel at 0 becomes 57. Neither is pinned, so neither counts as a survivor, so the instrument reports removal. The defect is still there at a contrast of 71 levels, which on a mid-grey background is obvious to the eye and would be obvious to any sharpening pass downstream. What the upscale did was move the energy below a threshold I chose, and I then reported the threshold as if it were a property of the image.&lt;/p&gt;

&lt;p&gt;The correct statement is: &lt;strong&gt;the upscale reduces the peak contrast of a point defect by 12 % to 44 %, and reduces its detectability by a threshold you picked, while conserving its total energy exactly.&lt;/strong&gt; Between those two sentences is the difference between a measurement and a measurement plus an unstated definition.&lt;/p&gt;

&lt;p&gt;The practical corollary is uncomfortable. At 8× a hot pixel keeps 88 % of its peak, so an upscale makes it &lt;em&gt;more&lt;/em&gt; conspicuous per-pixel than a 2× does. If your pipeline upscales and then looks for dead pixels by brightness, an 8× upscale will hand you 16× as many candidate pixels at nearly full contrast, and you will write a bug report about a sensor that was fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before or after? Both, and the density decides
&lt;/h2&gt;

&lt;p&gt;Now the repair. The obvious ordering is: upscale first (that is the deliverable), then clean up at the end. The less obvious ordering is: clean at native resolution first, then upscale once. Which one wins depends on something nobody puts in a filter preset — how much noise there is.&lt;/p&gt;

&lt;p&gt;Same seven crops, same bilinear 2×, truth defined as the 2× upscale of the &lt;em&gt;clean&lt;/em&gt; crop so every filter is charged for what it changes. Arms: &lt;strong&gt;D&lt;/strong&gt; upscale only; &lt;strong&gt;A3&lt;/strong&gt; median3 at native then 2×; &lt;strong&gt;B3&lt;/strong&gt;/&lt;strong&gt;B5&lt;/strong&gt;/&lt;strong&gt;B7&lt;/strong&gt; 2× then median of that size.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;density p&lt;/th&gt;
&lt;th&gt;D&lt;/th&gt;
&lt;th&gt;A3 (pre)&lt;/th&gt;
&lt;th&gt;B3 (post)&lt;/th&gt;
&lt;th&gt;B5 (post)&lt;/th&gt;
&lt;th&gt;A3 − B3&lt;/th&gt;
&lt;th&gt;images where A3 wins&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0 %&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;42.858&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;50.448&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;43.444&lt;/td&gt;
&lt;td&gt;−7.590&lt;/td&gt;
&lt;td&gt;0/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.05 %&lt;/td&gt;
&lt;td&gt;42.046&lt;/td&gt;
&lt;td&gt;42.767&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;45.742&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;43.211&lt;/td&gt;
&lt;td&gt;−2.975&lt;/td&gt;
&lt;td&gt;1/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.10 %&lt;/td&gt;
&lt;td&gt;39.107&lt;/td&gt;
&lt;td&gt;42.802&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;43.589&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;42.969&lt;/td&gt;
&lt;td&gt;−0.787&lt;/td&gt;
&lt;td&gt;2/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.20 %&lt;/td&gt;
&lt;td&gt;36.018&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.739&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;40.995&lt;/td&gt;
&lt;td&gt;42.593&lt;/td&gt;
&lt;td&gt;+1.744&lt;/td&gt;
&lt;td&gt;4/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.30 %&lt;/td&gt;
&lt;td&gt;34.100&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.597&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;39.192&lt;/td&gt;
&lt;td&gt;42.039&lt;/td&gt;
&lt;td&gt;+3.405&lt;/td&gt;
&lt;td&gt;6/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.50 %&lt;/td&gt;
&lt;td&gt;31.972&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.570&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;37.179&lt;/td&gt;
&lt;td&gt;41.319&lt;/td&gt;
&lt;td&gt;+5.391&lt;/td&gt;
&lt;td&gt;7/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.00 %&lt;/td&gt;
&lt;td&gt;28.879&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.325&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;34.126&lt;/td&gt;
&lt;td&gt;39.648&lt;/td&gt;
&lt;td&gt;+8.199&lt;/td&gt;
&lt;td&gt;7/7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faoapfyd047b29du844zk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faoapfyd047b29du844zk.png" alt="Left: PSNR against injected noise density for the pre-filter and both post-filters, with the crossover between them. Right: the same arms on a clean frame — no noise at all — where the ordering reverses by 7.6 dB." width="800" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The crossover is between 0.1 % and 0.2 %. Below it the post-filter wins, at 0 % by 7.6 dB, because a 3×3 median at native resolution is destructive to real detail: measured against the untouched native crop, it costs 40.2 dB on clean frames. Above 0.2 % the pre-filter wins, at 1 % by 8.2 dB, because it sees each defect at full amplitude and replaces it with a genuine neighbourhood median before any of that energy has been spread.&lt;/p&gt;

&lt;p&gt;And notice the shape of the pre-filter's curve. From 0 % to 1 % density, A3 moves from 42.858 to 42.325 — &lt;strong&gt;0.53 dB&lt;/strong&gt; total. It is almost flat. The post-filter falls 16.3 dB over the same range and the unfiltered upscale falls 20.1 dB. That flatness is not a small effect: it means the pre-filter's worst case is essentially its best case, while every post-filter's quality is a function of a parameter the operator does not control.&lt;/p&gt;

&lt;p&gt;I have to report the weak part of this honestly. At exactly 0.2 %, where the &lt;em&gt;average&lt;/em&gt; says the pre-filter wins by 1.744 dB, &lt;strong&gt;only 4 of the 7 images agree&lt;/strong&gt;. The mean has crossed but the population has not. Below 0.3 % I would not call the ranking settled on this sample; from 0.3 % upward it is 6/7 and then 7/7, and that is where I would put the threshold in practice.&lt;/p&gt;

&lt;p&gt;There is a second, independent result in that table that supports the pre-filter from a different direction: &lt;strong&gt;B5 beats B3 at every density&lt;/strong&gt;, and at 0.005 % density it even beats A3 on two of the seven images. A 5×5 median is a better post-filter than a 3×3. Why, exactly?&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the post-filter needs a bigger window: 4 pixels versus 3
&lt;/h2&gt;

&lt;p&gt;Go back to the footprint table. At 2×, a single hot pixel occupies a &lt;strong&gt;4×4&lt;/strong&gt; area of the output at meaningful contrast. Now apply a 3×3 median at the output. At the centre of the defect, half the window — 5 of 9 samples — is defect; the median of a window that is mostly defect returns something close to defect. The filter is structurally too small to see the edge of the thing it is supposed to remove.&lt;/p&gt;

&lt;p&gt;A 5×5 window gives 9 clean samples against 16 defect samples at the worst position and does only marginally better at the centre, but at the &lt;em&gt;border&lt;/em&gt; of the footprint it works, and that is where most of the perceptible contrast sits. That is the entire explanation for B3 at 26.60 dB and B5 at 32.28 dB at 5 % density — a 5.7 dB gap that has nothing to do with tuning and everything to do with window size versus footprint size.&lt;/p&gt;

&lt;p&gt;And the rule for the footprint has no exceptions. Measured bounding box equals &lt;strong&gt;2f&lt;/strong&gt; at every even factor and &lt;strong&gt;2f − 1&lt;/strong&gt; at every odd factor, from 2× to 16×:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;f&lt;/th&gt;
&lt;th&gt;measured bbox&lt;/th&gt;
&lt;th&gt;2f&lt;/th&gt;
&lt;th&gt;2f − 1&lt;/th&gt;
&lt;th&gt;rule holds&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Eight factors, zero exceptions. The odd-factor case is one pixel narrower because the output centre lands on the source sample and the two nearest neighbours are symmetric, so the bilinear support spans &lt;code&gt;f − 1&lt;/code&gt; on each side plus the centre, rather than &lt;code&gt;f&lt;/code&gt; on each side. This is documented sediment of coordinate convention; the &lt;a href="https://en.wikipedia.org/wiki/Bilinear_interpolation" rel="noopener noreferrer"&gt;bilinear interpolation&lt;/a&gt; article has the general form, and the sampling-offset detail is the part everyone gets wrong when they assume "one pixel becomes f × f".&lt;/p&gt;

&lt;p&gt;So: if you insist on repairing after the resize, your median window must be at least &lt;code&gt;2f + 1&lt;/code&gt; per side to be able to see past the footprint — which for 8× means a 17×17 median, which will demolish every real edge in the frame. That is not a filter choice, that is a reason to move the repair upstream.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should not do any of this
&lt;/h2&gt;

&lt;p&gt;Three cases where the right answer is to leave the pixels alone.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The "defects" are clipped highlights.&lt;/strong&gt; My census found 754 genuinely black and 223 genuinely white pixels in 7 clean crops — specular detail and dark interiors, all of them real. Any median pass, before or after, will round them off. On a product shot with a chrome edge or a light source in frame, this is visible damage for no benefit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The source is already clean and you are going to sharpen afterwards.&lt;/strong&gt; On a clean frame the pre-filter costs 7.6 dB relative to doing nothing but the resize (&lt;code&gt;A3&lt;/code&gt; 42.86 vs &lt;code&gt;B3&lt;/code&gt; 50.45, and &lt;code&gt;D&lt;/code&gt; is by definition the truth). You would be paying for a repair with no defect to repair, and then adding edge enhancement on top of a slightly flattened image, which is how you get halos.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You are upscaling to a fixed target and cannot change the order.&lt;/strong&gt; If the deliverable is already produced — the resize happened upstream, the file is what it is — a 3×3 median at the output is worse than nothing at high factors, because it costs real detail and cannot reach the footprint. Either use &lt;code&gt;2f + 1&lt;/code&gt; and accept the cost, or escalate to the source.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The general principle that survives all of this: &lt;strong&gt;a filter should be applied where the defect is still small enough to be filtered.&lt;/strong&gt; A point defect is one pixel at native resolution and &lt;code&gt;f²&lt;/code&gt; worth of area after a resize. Every extra operation between the defect and the filter makes the filter's job worse by a factor that compounds.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you need the resize itself done
&lt;/h2&gt;

&lt;p&gt;The reason I ran this measurement at all is that the ordering of a repair relative to a resize is a pipeline decision, not a filter setting, and pipeline decisions are the ones that stay wrong for years. In production, resizing should happen once, at an integer factor where possible, from the best available source, and it should consume the cleaned input rather than output something a downstream stage has to fix.&lt;/p&gt;

&lt;p&gt;If the resize half of that is what you need handled, &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;the upscaler at upgolab.com&lt;/a&gt; runs the resize and picks a preset for the content type; the numbers above are the argument for doing your sensor cleanup before you hand it a file rather than after.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That 28-second clip is a pass through five presets on real product frames — &lt;a href="https://youtu.be/tCXoB3uBKm4" rel="noopener noreferrer"&gt;direct link&lt;/a&gt; if the embed does not load. Watch what changes between presets and compare it to the peak table above: the presets differ mostly in how much local contrast survives, which is exactly the axis along which a hot pixel's peak moves from 55.9 % to 88.2 % depending on factor alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers said, including the part that insulted me
&lt;/h2&gt;

&lt;p&gt;I set out to measure the repair radius a point defect needs after an upscale, expecting it to scale with the factor in some smooth way. Three things came back instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My first instrument was measuring clipped highlights, not noise.&lt;/strong&gt; 977 genuinely clipped pixels in seven clean crops. It took a control I nearly skipped — count survivors on a frame where I injected nothing — to notice that the number I was reporting as a removal rate was substantially a measurement of the photographs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The peak loss is arithmetic and the total energy loss is zero.&lt;/strong&gt; &lt;code&gt;(1 − 1/(2f))²&lt;/code&gt; predicts the measured peak fraction to within 0.0057 across 2×, 3×, 4×, 6× and 8×, and the sum of the deltas is &lt;code&gt;f²&lt;/code&gt; to within 0.8 %. The "99.76 % removed" figure that would have made a much better headline is a statement about my threshold. Energy is conserved; only the peak moves; and at odd factors it does not move at all — 3× and 5× pass a hot pixel through at full 127-level contrast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The pre-filter versus post-filter question has no universal answer and that is the answer.&lt;/strong&gt; 7.6 dB in favour of post-filtering on a clean frame, 8.2 dB in favour of pre-filtering at 1 % density, crossover between 0.1 % and 0.2 %, and at 0.2 % the mean has crossed while only 4 of 7 images agree. The pre-filter's curve is flat within 0.53 dB across the entire density range; the post-filter's spans 16.3 dB. If you have to pick one without knowing the density, pick the one whose error does not depend on a parameter you cannot see.&lt;/p&gt;

&lt;p&gt;Two cross-file checks, because they cost nothing and catch everything: the 0 %-density row in the crossover file reproduces the clean-cost file exactly (42.858 and 50.448 in both), and the peak fractions in &lt;code&gt;nhip123_geom_exact.json&lt;/code&gt; reproduce the ones recorded independently by &lt;code&gt;nhip112_impulse.json&lt;/code&gt; to 0.003. The campaign's four arm-level controls all pass: zero survivors on clean frames, bit-identical results on repeated runs, injection counts within 1.5σ of binomial expectation, and a known single impulse removed to 0.0 maximum absolute error by median3 at native.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Count clipped pixels in your own clean frames before trusting any defect detector. If 0.05 % of your samples are already at 0 or 255, a threshold-based detector is measuring your photographs&lt;/li&gt;
&lt;li&gt;[ ] Track defects by coordinate, not by brightness. Record the mask at injection time if you are testing, or use a coordinate-verified map if you are not&lt;/li&gt;
&lt;li&gt;[ ] Expect a footprint of &lt;code&gt;2f&lt;/code&gt; (even factor) or &lt;code&gt;2f − 1&lt;/code&gt; (odd factor) per defect, not &lt;code&gt;f&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[ ] Expect peak contrast of &lt;code&gt;(1 − 1/(2f))²&lt;/code&gt; and total energy of exactly &lt;code&gt;f²&lt;/code&gt; — the defect is redistributed, never attenuated&lt;/li&gt;
&lt;li&gt;[ ] Do not claim a defect is "removed" unless you state the threshold that defines removal&lt;/li&gt;
&lt;li&gt;[ ] Repair at native resolution when density is above ~0.3 %; the pre-filter's error stays within 0.6 dB across two decades of density&lt;/li&gt;
&lt;li&gt;[ ] If repairing after the resize, size the window at &lt;code&gt;2f + 1&lt;/code&gt; or larger, and check what that does to real edges first&lt;/li&gt;
&lt;li&gt;[ ] Skip the median entirely on clean, high-contrast sources — 7.6 dB is a lot to spend on nothing&lt;/li&gt;
&lt;li&gt;[ ] Upscale once, at an integer factor, from the cleaned source, and treat the output as the file of record&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>imageprocessing</category>
      <category>python</category>
      <category>photography</category>
      <category>computervision</category>
    </item>
    <item>
      <title>Your Upscaled JPEG Scores 62 dB Against a Buffer It Invented</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Sun, 29 Nov 2026 11:20:24 +0000</pubDate>
      <link>https://dev.to/celticgemini001/your-upscaled-jpeg-scores-62-db-against-a-buffer-it-invented-8pk</link>
      <guid>https://dev.to/celticgemini001/your-upscaled-jpeg-scores-62-db-against-a-buffer-it-invented-8pk</guid>
      <description>&lt;p&gt;A 4× upscale saved at quality 100 scored &lt;strong&gt;62,21 dB&lt;/strong&gt; against the buffer it came from. The same file, same bytes, same 106,9 KB, scored &lt;strong&gt;46,58 dB&lt;/strong&gt; against the photograph it was made from.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;That gap is the whole subject of this article, and it explains a class of advice you have probably read: &lt;em&gt;"upscale first, then export at high quality, because the file is big anyway."&lt;/em&gt; The byte saving is real. The quality claim attached to it usually is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two yardsticks, and why only one of them is about your picture
&lt;/h2&gt;

&lt;p&gt;When you save a JPEG and then measure PSNR, the obvious reference is the buffer you handed to the encoder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PSNR( buffer_before_save , pixels_after_save )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Call this the &lt;strong&gt;arm-local&lt;/strong&gt; score. It answers one question: &lt;em&gt;how faithfully did the encoder reproduce what I gave it?&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;The other yardstick is the picture as it existed before you started mangling it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PSNR( native_crop , delivery_after_upscale_and_save )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Call this the &lt;strong&gt;truth&lt;/strong&gt; score. It answers: &lt;em&gt;does the reader end up with more of the real scene?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The method, so you can attack it
&lt;/h2&gt;

&lt;p&gt;Seven photographs, one 512-pixel centre crop each, taken from the campaign's &lt;code&gt;data/images/&lt;/code&gt; set — all real photos, no synthetic charts, no test patterns. Pillow and numpy.&lt;/p&gt;

&lt;p&gt;The truth for every measurement is &lt;strong&gt;the native 512-pixel crop&lt;/strong&gt;. That is the best detail actually available for that patch of scene, and it is the same image in every arm.&lt;/p&gt;

&lt;p&gt;There are two experiments, and they answer different halves of the question.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Experiment 1 — the scoreboard question.&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Experiment 2 — the delivery question.&lt;/strong&gt; Build a 512-pixel delivery from a &lt;em&gt;smaller&lt;/em&gt; source: Lanczos down to the target size, Lanczos back up to 512, save at q. Three arms:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;arm&lt;/th&gt;
&lt;th&gt;what happens to the source&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;native 512&lt;/td&gt;
&lt;td&gt;saved directly at quality q (no resize at all)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2× from 256&lt;/td&gt;
&lt;td&gt;Lanczos down to 256, Lanczos back up to 512, saved at q&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4× from 128&lt;/td&gt;
&lt;td&gt;Lanczos down to 128, Lanczos back up to 512, saved at q&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The downscale is how I &lt;em&gt;create&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;nhip115_jpeg_F.py&lt;/code&gt;. It responds to curvature, so it is sensitive to exactly the detail an upscale is supposed to add.&lt;/p&gt;

&lt;p&gt;Seven controls, all passing on the run that produced every number below:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;control&lt;/th&gt;
&lt;th&gt;what it proves&lt;/th&gt;
&lt;th&gt;result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;K1&lt;/td&gt;
&lt;td&gt;this run's 1× save PSNR matches the stored &lt;code&gt;nhip115_jpeg_E.json&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;45,93 dB = 45,93 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;K2&lt;/td&gt;
&lt;td&gt;this run's 1× &lt;code&gt;keep_pct&lt;/code&gt; matches the same file&lt;/td&gt;
&lt;td&gt;102,79 % = 102,79 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;K3&lt;/td&gt;
&lt;td&gt;the encoder is deterministic on this machine&lt;/td&gt;
&lt;td&gt;identical bytes twice&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;K4&lt;/td&gt;
&lt;td&gt;the round trip at factor 1 is the identity&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;K5&lt;/td&gt;
&lt;td&gt;a flat 128 field at q100 survives exactly&lt;/td&gt;
&lt;td&gt;max deviation 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;K6&lt;/td&gt;
&lt;td&gt;no saved arm beats its own resampling round trip&lt;/td&gt;
&lt;td&gt;all overshoots ≤ 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;K7&lt;/td&gt;
&lt;td&gt;the native arm's r² matches &lt;code&gt;nhip115_jpeg_H.json&lt;/code&gt; at all five q&lt;/td&gt;
&lt;td&gt;5/5 exact&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The scoreboard climbs 12,80 dB. The truth climbs 0,85 dB.
&lt;/h2&gt;

&lt;p&gt;Experiment 1, at 4×, saved at five quality settings, measured both ways:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;q&lt;/th&gt;
&lt;th&gt;r² vs its own buffer&lt;/th&gt;
&lt;th&gt;r² vs the truth&lt;/th&gt;
&lt;th&gt;PSNR vs its own buffer&lt;/th&gt;
&lt;th&gt;PSNR vs the truth&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;70&lt;/td&gt;
&lt;td&gt;0,2920&lt;/td&gt;
&lt;td&gt;0,0117&lt;/td&gt;
&lt;td&gt;49,41 dB&lt;/td&gt;
&lt;td&gt;45,731 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;85&lt;/td&gt;
&lt;td&gt;0,3752&lt;/td&gt;
&lt;td&gt;0,0115&lt;/td&gt;
&lt;td&gt;52,53 dB&lt;/td&gt;
&lt;td&gt;46,307 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;td&gt;0,4320&lt;/td&gt;
&lt;td&gt;0,0113&lt;/td&gt;
&lt;td&gt;54,26 dB&lt;/td&gt;
&lt;td&gt;46,468 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;95&lt;/td&gt;
&lt;td&gt;0,5384&lt;/td&gt;
&lt;td&gt;0,0113&lt;/td&gt;
&lt;td&gt;56,59 dB&lt;/td&gt;
&lt;td&gt;46,531 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;0,8378&lt;/td&gt;
&lt;td&gt;0,0115&lt;/td&gt;
&lt;td&gt;62,21 dB&lt;/td&gt;
&lt;td&gt;46,578 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Read the PSNR columns together. Going from q70 to q100:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the &lt;strong&gt;scoreboard&lt;/strong&gt; rises &lt;strong&gt;12,80 dB&lt;/strong&gt; — a transformation, the kind of number that makes people say "wow, q100 is so much better"&lt;/li&gt;
&lt;li&gt;the &lt;strong&gt;truth&lt;/strong&gt; rises &lt;strong&gt;0,847 dB&lt;/strong&gt; — three quarters of a dB, invisible&lt;/li&gt;
&lt;li&gt;the reported gap between the two widens from &lt;strong&gt;3,68 dB to 15,63 dB&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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 &lt;strong&gt;0,0117 → 0,0115&lt;/strong&gt;. It drifts &lt;em&gt;down&lt;/em&gt;. At q100 you are paying five times the bitrate to reproduce, with exquisite precision, a structure that was already 98,9 % gone.&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;the same 4× q100 file, 106,9 KB&lt;/th&gt;
&lt;th&gt;r²&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;measured against the buffer the encoder was handed (arm-local)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0,8979&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;measured against the native crop it was made from (truth)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0,0286&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Identical bytes, identical 106,9 KB to the tenth of a KB. A &lt;strong&gt;31× difference&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxeh4ugpljkpwuecntd15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxeh4ugpljkpwuecntd15.png" alt="The same seven files, saved at five quality settings, scored against two different references. Teal is the arm-local score; gold is the score against the native photograph. The inset zooms the gold line, which does move — by 0.85 dB in total." width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why: the save keeps 0,43 of a signal that is only 0,01 real
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor, all saves at q90&lt;/th&gt;
&lt;th&gt;r² truth→upscale&lt;/th&gt;
&lt;th&gt;r² upscale→save&lt;/th&gt;
&lt;th&gt;r² truth→save&lt;/th&gt;
&lt;th&gt;save PSNR (arm-local)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1×&lt;/td&gt;
&lt;td&gt;1,0000&lt;/td&gt;
&lt;td&gt;0,9122&lt;/td&gt;
&lt;td&gt;0,9122&lt;/td&gt;
&lt;td&gt;45,93 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;0,2164&lt;/td&gt;
&lt;td&gt;0,8356&lt;/td&gt;
&lt;td&gt;0,2114&lt;/td&gt;
&lt;td&gt;51,27 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;0,0244&lt;/td&gt;
&lt;td&gt;0,6688&lt;/td&gt;
&lt;td&gt;0,0235&lt;/td&gt;
&lt;td&gt;53,33 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;0,0116&lt;/td&gt;
&lt;td&gt;0,4320&lt;/td&gt;
&lt;td&gt;0,0113&lt;/td&gt;
&lt;td&gt;54,26 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;At 4× the columns split apart. The resize round trip destroys structure down to &lt;strong&gt;0,0116&lt;/strong&gt;. The save then takes that wreckage and preserves &lt;strong&gt;0,4320&lt;/strong&gt; of it. The reader receives &lt;strong&gt;0,0113&lt;/strong&gt;. 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.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;keep_pct&lt;/code&gt; 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:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor&lt;/th&gt;
&lt;th&gt;HF before save&lt;/th&gt;
&lt;th&gt;HF after save&lt;/th&gt;
&lt;th&gt;keep %&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1×&lt;/td&gt;
&lt;td&gt;6,108&lt;/td&gt;
&lt;td&gt;6,279&lt;/td&gt;
&lt;td&gt;102,79 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;2,301&lt;/td&gt;
&lt;td&gt;2,472&lt;/td&gt;
&lt;td&gt;107,48 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;1,314&lt;/td&gt;
&lt;td&gt;1,523&lt;/td&gt;
&lt;td&gt;116,01 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;1,021&lt;/td&gt;
&lt;td&gt;1,149&lt;/td&gt;
&lt;td&gt;112,53 %&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every number is over 100 %. The save &lt;em&gt;added&lt;/em&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nhip115_jpeg_F.py&lt;/code&gt; 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 &lt;strong&gt;one distinct value, min = max = 128&lt;/strong&gt;. 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The JPEG is innocent. The resize already spent it.
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Measure the resampling round trip &lt;strong&gt;with no encoder at all&lt;/strong&gt; — downsample to the target size and upsample back, then compare to the truth:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;arm&lt;/th&gt;
&lt;th&gt;resize round trip alone&lt;/th&gt;
&lt;th&gt;same arm, best possible JPEG (q100)&lt;/th&gt;
&lt;th&gt;what JPEG costs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;native 512&lt;/td&gt;
&lt;td&gt;99,00 dB (identity)&lt;/td&gt;
&lt;td&gt;58,86 dB&lt;/td&gt;
&lt;td&gt;40,14 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2× from 256&lt;/td&gt;
&lt;td&gt;35,567 dB&lt;/td&gt;
&lt;td&gt;35,554 dB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0,013 dB&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4× from 128&lt;/td&gt;
&lt;td&gt;29,530 dB&lt;/td&gt;
&lt;td&gt;29,527 dB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0,003 dB&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That is the answer, and it is not the one I expected. At 2× and 4×, the encoder costs &lt;strong&gt;one to three hundredths of a decibel&lt;/strong&gt;. 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 &lt;em&gt;before&lt;/em&gt; compression is applied.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flrn6gb7aim2be8rdvr68.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flrn6gb7aim2be8rdvr68.png" alt="Panel A: each arm's best attainable PSNR at q100, next to the PSNR of the same arm's resampling round trip with no JPEG in the path. At 2× and 4× the two heights are identical to two decimals. Panel B: the structure decomposition — what the resize destroys, what the save preserves, and what actually ships." width="799" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;em&gt;any&lt;/em&gt; quality from q70 to q100 — the picture is the same:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;arm&lt;/th&gt;
&lt;th&gt;best truth-PSNR (its ceiling)&lt;/th&gt;
&lt;th&gt;at q&lt;/th&gt;
&lt;th&gt;size there&lt;/th&gt;
&lt;th&gt;cheapest q&lt;/th&gt;
&lt;th&gt;size there&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;native 512&lt;/td&gt;
&lt;td&gt;58,86 dB&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;135,6 KB&lt;/td&gt;
&lt;td&gt;70&lt;/td&gt;
&lt;td&gt;24,3 KB (40,76 dB)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2× from 256&lt;/td&gt;
&lt;td&gt;35,55 dB&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;122,2 KB&lt;/td&gt;
&lt;td&gt;70&lt;/td&gt;
&lt;td&gt;22,7 KB (34,96 dB)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4× from 128&lt;/td&gt;
&lt;td&gt;29,53 dB&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;106,9 KB&lt;/td&gt;
&lt;td&gt;70&lt;/td&gt;
&lt;td&gt;20,0 KB (29,46 dB)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Look at the last two rows. For the 4× arm, the entire q70-to-q100 range buys &lt;strong&gt;0,07 dB&lt;/strong&gt; (29,46 → 29,53). For the 2× arm, &lt;strong&gt;0,59 dB&lt;/strong&gt; (34,96 → 35,55). For the native arm, &lt;strong&gt;18,10 dB&lt;/strong&gt; (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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The money question, at one honest yardstick
&lt;/h2&gt;

&lt;p&gt;Same fidelity yardstick — PSNR against the native truth — for three deliveries:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;delivery&lt;/th&gt;
&lt;th&gt;file size&lt;/th&gt;
&lt;th&gt;PSNR vs truth&lt;/th&gt;
&lt;th&gt;r² vs truth&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;native 512, q70&lt;/td&gt;
&lt;td&gt;24,3 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;40,76 dB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0,7578&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;native 512, q90&lt;/td&gt;
&lt;td&gt;44,5 KB&lt;/td&gt;
&lt;td&gt;45,93 dB&lt;/td&gt;
&lt;td&gt;0,9122&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;native 512, q100&lt;/td&gt;
&lt;td&gt;135,6 KB&lt;/td&gt;
&lt;td&gt;58,86 dB&lt;/td&gt;
&lt;td&gt;0,9958&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2× from 256, q100&lt;/td&gt;
&lt;td&gt;122,2 KB&lt;/td&gt;
&lt;td&gt;35,55 dB&lt;/td&gt;
&lt;td&gt;0,2551&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4× from 128, q100&lt;/td&gt;
&lt;td&gt;106,9 KB&lt;/td&gt;
&lt;td&gt;29,53 dB&lt;/td&gt;
&lt;td&gt;0,0286&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The cheapest native save in the table — q70, 24,3 KB, the setting most people would call "good enough for the web" — beats the &lt;em&gt;most expensive&lt;/em&gt; 4× save by &lt;strong&gt;11,23 dB&lt;/strong&gt;, at &lt;strong&gt;4,40× fewer bytes&lt;/strong&gt;, 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.&lt;/p&gt;

&lt;p&gt;The r²-per-kilobyte column of &lt;code&gt;nhip115_jpeg_H.json&lt;/code&gt; 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 &lt;em&gt;starting&lt;/em&gt; efficiency is worse than the native arm's &lt;em&gt;ending&lt;/em&gt; efficiency, and it never recovers. You are buying a worse product at a worse rate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quality 100 is not lossless, and that is a separate bill
&lt;/h2&gt;

&lt;p&gt;Everything above is about the yardstick. This part is about q100 itself, because the "just save it at maximum" advice deserves its own audit.&lt;/p&gt;

&lt;p&gt;Save the same seven crops at q95, q100 and q100 with 4:4:4 chroma and compare to the pre-save buffer:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;setting&lt;/th&gt;
&lt;th&gt;mean absolute error&lt;/th&gt;
&lt;th&gt;max error&lt;/th&gt;
&lt;th&gt;mean size&lt;/th&gt;
&lt;th&gt;PSNR&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;q95, default 4:2:0&lt;/td&gt;
&lt;td&gt;0,8386 code levels&lt;/td&gt;
&lt;td&gt;34&lt;/td&gt;
&lt;td&gt;64,9 KB&lt;/td&gt;
&lt;td&gt;44,974 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;q100, default 4:2:0&lt;/td&gt;
&lt;td&gt;0,2587&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;td&gt;135,6 KB&lt;/td&gt;
&lt;td&gt;49,249 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;q100, 4:4:4&lt;/td&gt;
&lt;td&gt;0,1281&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;183,1 KB&lt;/td&gt;
&lt;td&gt;56,164 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Quality 100 is not lossless. It rounds DCT coefficients instead of quantizing them flat, but it still rounds, and &lt;strong&gt;24,82 %&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;The chroma half is worth knowing separately: switching to 4:4:4 at q100 cuts max error from 28 to &lt;strong&gt;4&lt;/strong&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Progressive JPEG: a free 10 %, until you upscale
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;nhip115_jpeg.json&lt;/code&gt; also settles a related question. Progressive and baseline JPEG at the same quality are &lt;strong&gt;pixel-identical&lt;/strong&gt; — confirmed across the ladder and at every scale factor in F3 — and progressive is smaller:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;q&lt;/th&gt;
&lt;th&gt;baseline&lt;/th&gt;
&lt;th&gt;progressive&lt;/th&gt;
&lt;th&gt;saved&lt;/th&gt;
&lt;th&gt;scans&lt;/th&gt;
&lt;th&gt;pixels identical&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;70&lt;/td&gt;
&lt;td&gt;24,3 KB&lt;/td&gt;
&lt;td&gt;24,0 KB&lt;/td&gt;
&lt;td&gt;1,45 %&lt;/td&gt;
&lt;td&gt;1 / 10&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;80&lt;/td&gt;
&lt;td&gt;30,2 KB&lt;/td&gt;
&lt;td&gt;29,7 KB&lt;/td&gt;
&lt;td&gt;1,81 %&lt;/td&gt;
&lt;td&gt;1 / 10&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;85&lt;/td&gt;
&lt;td&gt;35,3 KB&lt;/td&gt;
&lt;td&gt;34,3 KB&lt;/td&gt;
&lt;td&gt;2,58 %&lt;/td&gt;
&lt;td&gt;1 / 10&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;td&gt;44,5 KB&lt;/td&gt;
&lt;td&gt;42,6 KB&lt;/td&gt;
&lt;td&gt;4,26 %&lt;/td&gt;
&lt;td&gt;1 / 10&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;95&lt;/td&gt;
&lt;td&gt;64,9 KB&lt;/td&gt;
&lt;td&gt;60,3 KB&lt;/td&gt;
&lt;td&gt;7,10 %&lt;/td&gt;
&lt;td&gt;1 / 10&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;135,6 KB&lt;/td&gt;
&lt;td&gt;121,8 KB&lt;/td&gt;
&lt;td&gt;10,16 %&lt;/td&gt;
&lt;td&gt;1 / 10&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;But it does not compose with upscaling. Re-run the same comparison on the resized buffers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor at q90&lt;/th&gt;
&lt;th&gt;baseline&lt;/th&gt;
&lt;th&gt;progressive&lt;/th&gt;
&lt;th&gt;saved&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1×&lt;/td&gt;
&lt;td&gt;44,5 KB&lt;/td&gt;
&lt;td&gt;42,6 KB&lt;/td&gt;
&lt;td&gt;4,26 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;113,7 KB&lt;/td&gt;
&lt;td&gt;110,5 KB&lt;/td&gt;
&lt;td&gt;2,85 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;295,0 KB&lt;/td&gt;
&lt;td&gt;286,3 KB&lt;/td&gt;
&lt;td&gt;2,96 %&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;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 &lt;em&gt;already&lt;/em&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this does NOT show, which matters
&lt;/h2&gt;

&lt;p&gt;I need to be precise about the boundary, because the temptation to overclaim here is enormous.&lt;/p&gt;

&lt;p&gt;This measurement compares a delivery against &lt;strong&gt;the detail that was genuinely in the scene&lt;/strong&gt;. My 4× arm is built by discarding detail from a 512 crop and then asking the upscale to put it back. It answers: &lt;em&gt;how much of the removed detail comes back?&lt;/em&gt; The answer, measured seven ways, is essentially none — r² 0,0113 against the truth.&lt;/p&gt;

&lt;p&gt;It does &lt;strong&gt;not&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;So the honest claim is narrow and it is still useful: &lt;strong&gt;an upscaler that reconstructs, rather than one that generates, cannot recover detail that was removed, and no quality setting changes that.&lt;/strong&gt; 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 &lt;strong&gt;0,07 dB&lt;/strong&gt; for &lt;strong&gt;5,35× the bytes&lt;/strong&gt;, and the result is still &lt;strong&gt;11,23 dB&lt;/strong&gt; worse than a native save &lt;strong&gt;4,40× smaller&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;If you want to run the comparison side by side without installing anything, &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;UpgoLAB's browser upscaler&lt;/a&gt; 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.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That 28-second clip is a pass through five presets on real product frames — &lt;a href="https://youtu.be/tCXoB3uBKm4" rel="noopener noreferrer"&gt;direct link&lt;/a&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Decide which score you are reporting.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never trust a &lt;code&gt;keep_pct&lt;/code&gt; or "detail preserved" figure above 100 %.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure the resampling round trip with no encoder in the path.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compare q70 to q100 before assuming headroom exists.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do the 30-second round-trip test&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use progressive JPEG always&lt;/strong&gt; — 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If colour edges matter, that is 4:4:4's job, not q100's.&lt;/strong&gt; Max error 28 → 4 at the same quality setting. It is a chroma problem and no amount of luma bitrate touches it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Seven photographs, one 512-pixel centre crop each, Pillow and numpy. Every figure above comes from five files in this campaign's &lt;code&gt;tracking/&lt;/code&gt; directory: &lt;code&gt;nhip127_hf_budget.json&lt;/code&gt; (new this run — the truth-referenced panels, the round-trip decomposition and the ceiling table), &lt;code&gt;nhip115_jpeg.json&lt;/code&gt;, &lt;code&gt;nhip115_jpeg_E.json&lt;/code&gt;, &lt;code&gt;nhip115_jpeg_F.json&lt;/code&gt;, &lt;code&gt;nhip115_jpeg_G.json&lt;/code&gt; and &lt;code&gt;nhip115_jpeg_H.json&lt;/code&gt;. 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 &lt;a href="https://www.itu.int/rec/T-REC-T.81/en" rel="noopener noreferrer"&gt;ITU-T T.81&lt;/a&gt; and summarised at &lt;a href="https://en.wikipedia.org/wiki/JPEG" rel="noopener noreferrer"&gt;JPEG&lt;/a&gt;; chroma subsampling ratios and the 4:2:0 / 4:4:4 distinction are covered at &lt;a href="https://en.wikipedia.org/wiki/Chroma_subsampling" rel="noopener noreferrer"&gt;chroma subsampling&lt;/a&gt;. 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.&lt;/p&gt;

</description>
      <category>imageprocessing</category>
      <category>python</category>
      <category>photography</category>
      <category>computervision</category>
    </item>
    <item>
      <title>Median Before or After the Upscale? The Crossover Is 0.2%, and Real Photos Never Get There</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Sat, 28 Nov 2026 17:38:57 +0000</pubDate>
      <link>https://dev.to/celticgemini001/median-before-or-after-the-upscale-the-crossover-is-02-and-real-photos-never-get-there-4kim</link>
      <guid>https://dev.to/celticgemini001/median-before-or-after-the-upscale-the-crossover-is-02-and-real-photos-never-get-there-4kim</guid>
      <description>&lt;p&gt;Every "denoise before you upscale" tutorial says the same thing, and so did I: strip the noise first, because enlarging a spike into four fat spikes only makes it worse. Then I measured the case where nobody has added noise — a clean photograph — and the ranking flipped. Median-3 &lt;em&gt;after&lt;/em&gt; the 2× upscale beat median-3 &lt;em&gt;before&lt;/em&gt; it by &lt;strong&gt;7.59 dB&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Both statements cannot be the rule. One of them has to be a special case, and finding out which one tells you whether the advice applies to your file at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two numbers that contradicted each other
&lt;/h2&gt;

&lt;p&gt;Seven photographs, 512-pixel centre crops, one bilinear 2× upscale. The same seven crops in every arm. The "truth" image is the bilinear 2× of the &lt;em&gt;clean&lt;/em&gt; crop, so an arm that does nothing to the image scores the resize error alone, and every filter is charged for whatever it changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clean frames, nothing injected.&lt;/strong&gt; Median-3 applied at native resolution before the resize (call it A3), median-3 applied to the 2× output (B3), median-5 and median-7 likewise:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;arm&lt;/th&gt;
&lt;th&gt;where the filter runs&lt;/th&gt;
&lt;th&gt;mean PSNR&lt;/th&gt;
&lt;th&gt;min&lt;/th&gt;
&lt;th&gt;max&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A3&lt;/td&gt;
&lt;td&gt;median-3 at 1×, then 2×&lt;/td&gt;
&lt;td&gt;42.858 dB&lt;/td&gt;
&lt;td&gt;39.080&lt;/td&gt;
&lt;td&gt;49.394&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B3&lt;/td&gt;
&lt;td&gt;2×, then median-3&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;50.448 dB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;48.404&lt;/td&gt;
&lt;td&gt;52.953&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B5&lt;/td&gt;
&lt;td&gt;2×, then median-5&lt;/td&gt;
&lt;td&gt;43.444 dB&lt;/td&gt;
&lt;td&gt;40.662&lt;/td&gt;
&lt;td&gt;46.753&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B7&lt;/td&gt;
&lt;td&gt;2×, then median-7&lt;/td&gt;
&lt;td&gt;39.740 dB&lt;/td&gt;
&lt;td&gt;36.068&lt;/td&gt;
&lt;td&gt;44.370&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A3 loses to B3 on all seven crops, between 3.56 and 9.36 dB. It is not a tie broken by one bad image. And the bill is easy to read off a fifth column I measured for exactly this purpose: median-3 at native resolution differs from the untouched crop by &lt;strong&gt;40.200 dB&lt;/strong&gt;. That is a real change to the picture, paid before the upscale even happens, and then enlarged.&lt;/p&gt;

&lt;p&gt;So on a clean file the order is unambiguous: &lt;strong&gt;do not median-filter before the resize.&lt;/strong&gt; The pre-filter costs 7.6 dB and buys nothing, because there is no spike to remove.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the pre-filter starts winning
&lt;/h2&gt;

&lt;p&gt;Now inject salt-and-pepper noise at known densities, using the same 0.5%/1%/2%/5% logic anyone would use to demo a median filter, and sweep the low end between 0 and 1%:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;injected&lt;/th&gt;
&lt;th&gt;pixels in a 512² crop&lt;/th&gt;
&lt;th&gt;D: no filter&lt;/th&gt;
&lt;th&gt;A3: median-3 pre&lt;/th&gt;
&lt;th&gt;B3: median-3 post&lt;/th&gt;
&lt;th&gt;B5: median-5 post&lt;/th&gt;
&lt;th&gt;crops where A3 &amp;gt; B3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;99.000&lt;/td&gt;
&lt;td&gt;42.858&lt;/td&gt;
&lt;td&gt;50.448&lt;/td&gt;
&lt;td&gt;43.444&lt;/td&gt;
&lt;td&gt;0/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.05%&lt;/td&gt;
&lt;td&gt;131&lt;/td&gt;
&lt;td&gt;42.046&lt;/td&gt;
&lt;td&gt;42.767&lt;/td&gt;
&lt;td&gt;45.742&lt;/td&gt;
&lt;td&gt;43.211&lt;/td&gt;
&lt;td&gt;1/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.10%&lt;/td&gt;
&lt;td&gt;262&lt;/td&gt;
&lt;td&gt;39.107&lt;/td&gt;
&lt;td&gt;42.802&lt;/td&gt;
&lt;td&gt;43.589&lt;/td&gt;
&lt;td&gt;42.969&lt;/td&gt;
&lt;td&gt;2/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;0.20%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;524&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;36.018&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.739&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;40.995&lt;/td&gt;
&lt;td&gt;42.593&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;4/7&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.30%&lt;/td&gt;
&lt;td&gt;786&lt;/td&gt;
&lt;td&gt;34.100&lt;/td&gt;
&lt;td&gt;42.597&lt;/td&gt;
&lt;td&gt;39.192&lt;/td&gt;
&lt;td&gt;42.039&lt;/td&gt;
&lt;td&gt;6/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.50%&lt;/td&gt;
&lt;td&gt;1 311&lt;/td&gt;
&lt;td&gt;31.972&lt;/td&gt;
&lt;td&gt;42.570&lt;/td&gt;
&lt;td&gt;37.179&lt;/td&gt;
&lt;td&gt;41.319&lt;/td&gt;
&lt;td&gt;7/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.00%&lt;/td&gt;
&lt;td&gt;2 621&lt;/td&gt;
&lt;td&gt;28.879&lt;/td&gt;
&lt;td&gt;42.325&lt;/td&gt;
&lt;td&gt;34.126&lt;/td&gt;
&lt;td&gt;39.648&lt;/td&gt;
&lt;td&gt;7/7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4p5j7wfqsub0mwcv3wac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4p5j7wfqsub0mwcv3wac.png" alt="Two panels from nhip122_crossover.json and nhip121_med_cost.json. Left: four PSNR curves against injected salt-and-pepper density — median-3 after the upscale starts highest and falls furthest, median-3 before it starts lower and stays flat, and the vertical line marks where the two swap. Right: the same four arms on clean frames as bars, with the post-filter 7.59 dB above the pre-filter." width="799" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The mean crosses at &lt;strong&gt;0.2%&lt;/strong&gt;, but the per-image count is the more honest number: at 0.2% only 4 of 7 crops prefer the pre-filter, and it takes 0.5% before all seven agree. Anywhere below 0.1%, the post-filter is still ahead on the average, and at 0.05% it is ahead by 2.98 dB.&lt;/p&gt;

&lt;p&gt;Two things in that table deserve a sentence each, because they are the reason the whole comparison is trustworthy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arm A3 barely moves.&lt;/strong&gt; From 0% to 1% corruption it loses &lt;strong&gt;0.533 dB&lt;/strong&gt;, and its floor stays at 42.3 dB. A median filter at native resolution is nearly immune to density: it either removes a spike or it does not, and the spikes it misses are the ones with a neighbour, which are rare at these densities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arm B3 collapses.&lt;/strong&gt; From 0% to 1% it loses &lt;strong&gt;16.322 dB&lt;/strong&gt; — from 50.448 to 34.126. It wins the clean frame by 7.59 dB and loses the dirty frame by 8.20 dB. Everything about that arm depends on how many of its input pixels are not spikes, and after the upscale every spike has been smeared into a 2×2 block of them.&lt;/p&gt;

&lt;p&gt;Arm D, for scale: upscale-only falls from 42.046 dB at the lowest tested density to 28.879 dB at 1%.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the crossover exists at all
&lt;/h2&gt;

&lt;p&gt;The reason is geometric, and it is measurable without touching a single image pixel. Take the injected 0/1 mask alone and bilinear-upscale it with exactly the same kernel:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;injected&lt;/th&gt;
&lt;th&gt;duplicated output px ≥ 0.5 per impulse&lt;/th&gt;
&lt;th&gt;output px ≥ 0.1 per impulse&lt;/th&gt;
&lt;th&gt;corrupt area in source&lt;/th&gt;
&lt;th&gt;same damage in 2× output&lt;/th&gt;
&lt;th&gt;ratio&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0.05%&lt;/td&gt;
&lt;td&gt;4.000&lt;/td&gt;
&lt;td&gt;11.976&lt;/td&gt;
&lt;td&gt;0.0508%&lt;/td&gt;
&lt;td&gt;0.1521%&lt;/td&gt;
&lt;td&gt;2.994×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.10%&lt;/td&gt;
&lt;td&gt;4.000&lt;/td&gt;
&lt;td&gt;11.975&lt;/td&gt;
&lt;td&gt;0.0982%&lt;/td&gt;
&lt;td&gt;0.2940%&lt;/td&gt;
&lt;td&gt;2.994×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.20%&lt;/td&gt;
&lt;td&gt;4.000&lt;/td&gt;
&lt;td&gt;11.962&lt;/td&gt;
&lt;td&gt;0.1965%&lt;/td&gt;
&lt;td&gt;0.5877%&lt;/td&gt;
&lt;td&gt;2.991×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.50%&lt;/td&gt;
&lt;td&gt;4.000&lt;/td&gt;
&lt;td&gt;11.920&lt;/td&gt;
&lt;td&gt;0.5011%&lt;/td&gt;
&lt;td&gt;1.4933%&lt;/td&gt;
&lt;td&gt;2.980×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.00%&lt;/td&gt;
&lt;td&gt;4.000&lt;/td&gt;
&lt;td&gt;11.871&lt;/td&gt;
&lt;td&gt;1.0044%&lt;/td&gt;
&lt;td&gt;2.9806%&lt;/td&gt;
&lt;td&gt;2.968×&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every impulse becomes exactly &lt;strong&gt;4 full-height copies&lt;/strong&gt; and touches about &lt;strong&gt;11.9 output pixels&lt;/strong&gt; once you count anything carrying at least ten percent of the mask weight. Because the impulses are spread randomly, the covered &lt;em&gt;area&lt;/em&gt; grows by 2.98×, not 4×: some of the duplicated pixels land on a neighbour that was already corrupted. The ratio drifts slowly downward with density for the same reason — at 1% the newly-created blocks start overlapping each other.&lt;/p&gt;

&lt;p&gt;Now put the two facts together. A post-filter is a 3×3 median in the &lt;em&gt;output&lt;/em&gt; grid, so an impulse that has been duplicated into a 2×2 block is no longer an isolated outlier — it is a small cluster with three identical neighbours, and a 3×3 median cannot remove it. That is the 16.3 dB collapse in one sentence. A larger post-filter gets closer: at 1% B5 reaches 39.648 dB, and median-7 measured on the same crops in the earlier sweep in &lt;code&gt;nhip112_impulse.json&lt;/code&gt; reaches 38.631 dB — but neither approaches A3's 42.325 dB, and both of them pay a heavy price on clean frames (43.444 and 39.740 dB against B3's 50.448).&lt;/p&gt;

&lt;h2&gt;
  
  
  Then I asked how much real clipping exists, and the answer reframed the question
&lt;/h2&gt;

&lt;p&gt;The crossover is defined on injected salt-and-pepper, which is the easy case: an impulse at a random location surrounded by intact pixels. Real photographs clip differently. A blown highlight is a &lt;em&gt;region&lt;/em&gt;, not a spike, and a 3×3 median cannot move a pixel whose eight neighbours are all 255 either.&lt;/p&gt;

&lt;p&gt;So I counted. In the same seven 512-pixel crops, every pixel at exactly 0 or exactly 255, then asked how many of its 8 neighbours are also clipped:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;crop&lt;/th&gt;
&lt;th&gt;clipped px&lt;/th&gt;
&lt;th&gt;% of crop&lt;/th&gt;
&lt;th&gt;isolated&lt;/th&gt;
&lt;th&gt;clustered (≥1 clipped neighbour)&lt;/th&gt;
&lt;th&gt;at 255&lt;/th&gt;
&lt;th&gt;255 and isolated&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;#0&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;0.0153%&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;24&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;#1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0.0000%&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;#2&lt;/td&gt;
&lt;td&gt;216&lt;/td&gt;
&lt;td&gt;0.0824%&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;211&lt;/td&gt;
&lt;td&gt;216&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;#3&lt;/td&gt;
&lt;td&gt;654&lt;/td&gt;
&lt;td&gt;0.2495%&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;637&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;#4&lt;/td&gt;
&lt;td&gt;27&lt;/td&gt;
&lt;td&gt;0.0103%&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;#5&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;0.0069%&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;#6&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;0.0084%&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;977&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.0532%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;63&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;914&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;223&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;9&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Across 1 835 008 pixels there are 977 clipped. Of those, &lt;strong&gt;63 are isolated — 6.45%&lt;/strong&gt;. At the white end it is worse: of 223 pixels at 255, only 9 have no clipped neighbour. The other 214 are part of a blown highlight, which is exactly the shape a median filter cannot repair. The most clipping-heavy crop (#3, 0.2495%) is 97% clustered.&lt;/p&gt;

&lt;p&gt;The counts reconcile with the earlier census of the same crops to four decimal places on every image, which is the control that says I counted the same thing twice rather than two different things.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F53wbhmmgx1gni960smvw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F53wbhmmgx1gni960smvw.png" alt="Two panels from nhip124_medisolation.json and nhip125_impulse_bloom.json. Left: stacked bars per crop showing how many clipped pixels are isolated against how many have at least one clipped neighbour; teal slivers are barely visible against coral. Right: the injected mask upscaled on its own — the covered area in the source and the same damage in the 2× output, diverging by a factor of about three." width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the part that reframed the article for me. The crossover table says a median pre-filter starts paying at 0.2% corruption. The census says real photographs in this set carry &lt;strong&gt;0.0532%&lt;/strong&gt; clipping on average, and only &lt;strong&gt;0.0034%&lt;/strong&gt; of pixels are isolated spikes (63 of 1 835 008, or 0.0034%). The injected densities where the pre-filter wins are not just above the real clipping rate — they are above it by an order of magnitude, and dominated by a corruption shape real files do not have.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So the honest answer is: for these files, neither.&lt;/strong&gt; Not "denoise before upscaling" and not "denoise after". A median filter is not the tool the data picks, because the thing it removes is not what is actually there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the order actually costs, in milliseconds
&lt;/h2&gt;

&lt;p&gt;If you do decide to run the post-filter, it runs on 4× as many pixels. Wall-clock, minimum of 7 repetitions on one machine, same 512-pixel crop and its bilinear 2× output:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;filter&lt;/th&gt;
&lt;th&gt;at 512×512 (1×)&lt;/th&gt;
&lt;th&gt;at 1024×1024 (2×)&lt;/th&gt;
&lt;th&gt;ratio&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;median-3&lt;/td&gt;
&lt;td&gt;14.0 ms&lt;/td&gt;
&lt;td&gt;40.1 ms&lt;/td&gt;
&lt;td&gt;2.87×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;median-5&lt;/td&gt;
&lt;td&gt;51.4 ms&lt;/td&gt;
&lt;td&gt;161.3 ms&lt;/td&gt;
&lt;td&gt;3.14×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;median-7&lt;/td&gt;
&lt;td&gt;97.5 ms&lt;/td&gt;
&lt;td&gt;323.3 ms&lt;/td&gt;
&lt;td&gt;3.32×&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The ratio is not 4 because a 1024² image has a smaller border fraction and the per-pixel cost scales with kernel area, not with pixel count alone. Scaled by pixel count alone the median-3 post-filter would land near 1 s on a 24-megapixel photograph — an extrapolation, not a measurement, which is not a disaster but is not free either — and it is being spent to fix something that, per the census above, is mostly not there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two smaller things the numbers forced me to say
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A3 never recovers to clean.&lt;/strong&gt; Its ceiling in the noisy sweep is 42.802 dB at 0.10%, against 42.858 dB when nothing was injected at all — dropping as corruption rises, not rising. The pre-filter is not "removing noise and preserving the rest"; it is paying 40.2 dB of native-resolution change up front and then holding roughly still. Because that change is applied &lt;em&gt;before&lt;/em&gt; a 2× upscale, it is applied to the resolution the image actually has, which is the only reason it holds up better than a filter applied to invented pixels.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B5 looks like a good compromise in the noisy arms and is not one.&lt;/strong&gt; At 1% corruption it scores 39.648 dB, better than B3's 34.126 dB. But on clean frames B5 costs 7.004 dB relative to B3 (43.444 against 50.448), so it wins the case you were testing and loses the case you actually have. If you must pick one arm for unknown input, that trade is the one to look at, not the noisy-frame ranking.&lt;/p&gt;

&lt;h2&gt;
  
  
  A reproduction note about honesty
&lt;/h2&gt;

&lt;p&gt;The crossover result reproduces to 0.000 dB across two files. The clean arm of the noisy sweep (&lt;code&gt;nhip122_crossover.json&lt;/code&gt;, p = 0) and the clean-frame measurement (&lt;code&gt;nhip121_med_cost.json&lt;/code&gt;) were computed by different scripts at different times from the source images, and they agree on all four arms to three decimals — A3 42.858, B3 50.448, B5 43.444. That is a cross-file control, not a check inside one script, and it is the reason I am willing to quote the 7.59 dB figure at all.&lt;/p&gt;

&lt;p&gt;Both scripts re-ran today in 4.7 s and 13.1 s respectively and printed the stored numbers unchanged. The isolation census and the mask bloom were written for this article and are new files.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should still run the median filter
&lt;/h2&gt;

&lt;p&gt;None of this says a median filter is a bad tool. It says this measurement does not support using it as a fixed pre- or post-step in an upscaling pipeline, and here are the cases where the reasoning does not cover it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sensor dead pixels.&lt;/strong&gt; A stuck pixel is by definition isolated and at 0 or 255. That is the impulse case, and A3's near-invariance to density is exactly the property you want — one pass before the resize, at native resolution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Film scratches and dust on a scan.&lt;/strong&gt; Isolated, high-contrast, three-dimensional; generally not clipped at 255, so a median-3 at native resolution before the upscale will touch it and the upscale will not have smeared it yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Video from a failing sensor or a very noisy compact camera.&lt;/strong&gt; Here the corruption really is impulse-shaped and dense, and the 0.5%–1% rows of the table are the régime you are in. Measure a representative frame first; if the impulse density is above 0.2%, pre-filter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You are printing.&lt;/strong&gt; A 40 dB change at native resolution (the A3 bill) is visible on a 300 dpi print even when it is invisible at fit-to-window. Do not spend it unless there is a spike to remove.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And the cases where this data says don't:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A clean transfer from a modern camera. There is nothing to filter; B3's 50.448 dB is available and A3 throws away 7.59 dB.&lt;/li&gt;
&lt;li&gt;A photograph whose only defect is a blown highlight. The census says that is 97% of the clipping in one of these seven crops. A median filter will leave it alone and charge you 7.6 dB anyway.&lt;/li&gt;
&lt;li&gt;Anything where you were about to apply median-7 "to be safe". B7 costs 10.71 dB against B3 on clean frames and does not recover it on dirty ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A method note
&lt;/h2&gt;

&lt;p&gt;The truth image in the noisy sweep is the bilinear 2× of the &lt;em&gt;clean&lt;/em&gt; crop, not the clean crop upscaled by a better kernel. That choice penalises every filter for what it changes and gives the resize arm a 99.000 dB floor, which is what makes the crossover a comparison of filters rather than a comparison of kernels. The cost is that all absolute numbers in these tables are relative to bilinear at 2× and should not be quoted against Lanczos or a neural model. I have not measured those, and I am not going to guess.&lt;/p&gt;

&lt;p&gt;The 7 crops are 512-pixel centre crops from real photographs, not synthetic gradients. Crop #1 carries no clipped pixel at all, which is why one row of the census table is all zeros and one bar in the chart is empty — that is the file, not a bug in the counting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist before you reach for the median filter
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Count the clipped pixels in your own file. If the number is near 0.05% of the frame and mostly clustered, a median filter is the wrong tool — the crossover table does not apply to your input.&lt;/li&gt;
&lt;li&gt;If the corruption is genuinely isolated (dead pixels, dust, impulse noise), filter at &lt;strong&gt;native resolution before the resize&lt;/strong&gt;. A3 is the only arm that barely moves with density.&lt;/li&gt;
&lt;li&gt;If you are filtering after the resize anyway, understand that a 3×3 median can no longer see an impulse as isolated: it is a 2×2 block, and B3's 16.3 dB collapse from 0% to 1% is what that costs.&lt;/li&gt;
&lt;li&gt;Measure your own frame's impulse density before choosing. Below 0.1% the post-filter still wins the average; above 0.5% all seven crops agree on the pre-filter; between the two it depends on the image.&lt;/li&gt;
&lt;li&gt;Do not use median-5 or median-7 as a hedge. They cost more on clean frames than they recover on dirty ones.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you want to run the same two upscales side by side on your own file before deciding, &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;UpgoLAB's browser upscaler&lt;/a&gt; does a 2× without an install, which is enough to compare a pre-filtered and a post-filtered output at 100% on the patch that actually matters.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That 28-second clip is a pass through five presets on real product frames — &lt;a href="https://youtu.be/tCXoB3uBKm4" rel="noopener noreferrer"&gt;direct link&lt;/a&gt; if the embed does not load. The preset comparison is not what this article measures, but it is the same question in a different tool: where in the pipeline a filter runs, and what it is being asked to remove.&lt;/p&gt;

&lt;p&gt;Every figure above comes from four files in this campaign's &lt;code&gt;tracking/&lt;/code&gt; directory: &lt;code&gt;nhip121_med_cost.json&lt;/code&gt; (clean-frame arms), &lt;code&gt;nhip122_crossover.json&lt;/code&gt; (the density sweep), &lt;code&gt;nhip124_medisolation.json&lt;/code&gt; (the 8-neighbour clipping census) and &lt;code&gt;nhip125_impulse_bloom.json&lt;/code&gt; (the mask-only bloom). The median-7 figure at 1% is quoted from &lt;code&gt;nhip112_impulse.json&lt;/code&gt;, where only the p = 0.5/1/2/5% points were swept. Seven photographs, 512-pixel centre crops, bilinear 2×, Pillow and numpy. Median filtering as a definition is standard and documented, e.g. &lt;a href="https://en.wikipedia.org/wiki/Median_filter" rel="noopener noreferrer"&gt;the median filter article&lt;/a&gt;; salt-and-pepper noise is likewise standard reading, and the reason it is the wrong model for this problem is &lt;a href="https://en.wikipedia.org/wiki/Salt-and-pepper_noise" rel="noopener noreferrer"&gt;its definition&lt;/a&gt; — it is a per-pixel random process, and real clipping is not.&lt;/p&gt;

</description>
      <category>imageprocessing</category>
      <category>python</category>
      <category>photography</category>
      <category>computervision</category>
    </item>
    <item>
      <title>Twenty Resize Round Trips Fade a Photo by 8.6 Code Levels — but Only If You Use Bilinear</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Fri, 27 Nov 2026 17:31:00 +0000</pubDate>
      <link>https://dev.to/celticgemini001/twenty-resize-round-trips-fade-a-photo-by-86-code-levels-but-only-if-you-use-bilinear-4hj2</link>
      <guid>https://dev.to/celticgemini001/twenty-resize-round-trips-fade-a-photo-by-86-code-levels-but-only-if-you-use-bilinear-4hj2</guid>
      <description>&lt;p&gt;I resized seven photographs up to 2× and back down to 1× twenty times, using the same kernel for both legs, and then measured how far the mean brightness had moved. With bilinear it had moved &lt;strong&gt;+8.60 code values&lt;/strong&gt; out of 255. With bicubic it had moved &lt;strong&gt;+0.076&lt;/strong&gt;. With Lanczos it had moved &lt;strong&gt;+0.016&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That ordering is the opposite of what I expected, and it is not a rounding curiosity. Over the same twenty trips, bilinear also lost &lt;strong&gt;12 % of the image's standard deviation&lt;/strong&gt; (88.0 % of the original), while Lanczos &lt;em&gt;gained&lt;/em&gt; 0.66 %. The cheapest kernel in the toolbox is the one that quietly washes a photo out, and the expensive one is not merely stable, it slowly drifts the other way.&lt;/p&gt;

&lt;p&gt;Everything below comes out of this campaign's &lt;code&gt;tracking/&lt;/code&gt; directory: &lt;code&gt;nhip111_resize_drift.json&lt;/code&gt; (the main sweep), &lt;code&gt;nhip111_char.json&lt;/code&gt; (content and brightness characterisation), &lt;code&gt;nhip111_diag.json&lt;/code&gt; (clipping), &lt;code&gt;nhip111_legs.json&lt;/code&gt; (which leg carries the bias) and &lt;code&gt;nhip111_rounding.json&lt;/code&gt; (the hypothesis I had to throw away). Seven real photographs, 512-pixel centre crops. The sweep was recorded under Pillow 12.2.0 / numpy 1.26.4 and I re-ran all five of its controls today under Pillow 13.0.0 / numpy 2.5.5 — every one reproduced the stored numbers exactly, which is the only reason I am willing to quote them. Nothing here is synthetic except where I say so.&lt;/p&gt;

&lt;h2&gt;
  
  
  The measurement, and the five controls I had to pass first
&lt;/h2&gt;

&lt;p&gt;A "round trip" is: resize 512×512 to 1024×1024 with kernel &lt;em&gt;K&lt;/em&gt;, then resize 1024×1024 back to 512×512 with the same &lt;em&gt;K&lt;/em&gt;. Repeat &lt;em&gt;N&lt;/em&gt; times. Compare the final array's mean to the original's mean. The only thing that changes between arms is &lt;em&gt;K&lt;/em&gt; and &lt;em&gt;N&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Before trusting any of it I ran five controls, and I re-ran all five independently while writing this, from the source images rather than from the stored numbers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;NEAREST must be bit-exact.&lt;/strong&gt; It is, at every &lt;em&gt;N&lt;/em&gt;, for all seven photographs. A resampler that copies its nearest neighbour and loses nothing is the sanity floor: if NEAREST moved, my harness was broken, not the kernel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A flat field must not move.&lt;/strong&gt; Fields of 0, 100, 127, 128, 129, 200 and 255 all come back unchanged after twenty round trips, on all three kernels. This kills "the kernel is not normalised to unit sum", which would shift a constant.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The same run twice must give the same answer.&lt;/strong&gt; It does, byte for byte.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A monotonic ramp must not drift.&lt;/strong&gt; It does not — and I will come back to why that is the most informative single result in the set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The identity comparison must read 99.0 dB&lt;/strong&gt;, the ceiling I use for "no difference at all", not &lt;code&gt;inf&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All five pass. The controls are not decoration: one of them is what forced me to abandon the explanation I had already written up.&lt;/p&gt;

&lt;h2&gt;
  
  
  What twenty trips actually do, kernel by kernel
&lt;/h2&gt;

&lt;p&gt;Mean level drift, averaged over the seven images, in code values:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;round trips&lt;/th&gt;
&lt;th&gt;BILINEAR&lt;/th&gt;
&lt;th&gt;BICUBIC&lt;/th&gt;
&lt;th&gt;LANCZOS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;+0.342&lt;/td&gt;
&lt;td&gt;+0.016&lt;/td&gt;
&lt;td&gt;−0.002&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;+0.692&lt;/td&gt;
&lt;td&gt;+0.026&lt;/td&gt;
&lt;td&gt;−0.002&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;+1.808&lt;/td&gt;
&lt;td&gt;+0.041&lt;/td&gt;
&lt;td&gt;−0.003&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;+3.888&lt;/td&gt;
&lt;td&gt;+0.056&lt;/td&gt;
&lt;td&gt;0.000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;+8.598&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;+0.076&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;+0.016&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The bilinear column is not linear in &lt;em&gt;N&lt;/em&gt;. At &lt;em&gt;N&lt;/em&gt;=1 it costs 0.34 per trip; at &lt;em&gt;N&lt;/em&gt;=20 the average rate is 0.43 per trip. Six of the seven photographs drift further than a straight line through the origin and the &lt;em&gt;N&lt;/em&gt;=1 point would predict (that line lands at 6.83 after twenty trips), so the per-trip cost itself is creeping upward. The one that does not overshoot is the darkest image in the set (mean level 75.36), at +6.63.&lt;/p&gt;

&lt;p&gt;Per-image spread at &lt;em&gt;N&lt;/em&gt;=20 for bilinear is &lt;strong&gt;+6.63 to +10.86&lt;/strong&gt;. No single photograph is carrying the average. Whatever this is, it is a property of the kernel meeting real image content, not of one unlucky file.&lt;/p&gt;

&lt;p&gt;Bicubic's worst image drifts +0.102 after twenty trips. Lanczos spans −0.393 to +0.135, which is to say it wanders in both directions around zero and never commits.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same runs, read as contrast
&lt;/h2&gt;

&lt;p&gt;Brightness is only half the story, and the other half points the same way. Standard deviation — how much tonal range is left — expressed as a percentage of the untouched original:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;round trips&lt;/th&gt;
&lt;th&gt;BILINEAR&lt;/th&gt;
&lt;th&gt;BICUBIC&lt;/th&gt;
&lt;th&gt;LANCZOS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;98.10 %&lt;/td&gt;
&lt;td&gt;99.56 %&lt;/td&gt;
&lt;td&gt;99.98 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;94.83 %&lt;/td&gt;
&lt;td&gt;98.78 %&lt;/td&gt;
&lt;td&gt;100.22 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;92.34 %&lt;/td&gt;
&lt;td&gt;98.32 %&lt;/td&gt;
&lt;td&gt;100.66 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;88.00 %&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;97.84 %&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;101.80 %&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(These four are the 256-pixel crops in &lt;code&gt;nhip111_char.json&lt;/code&gt;; the 512-pixel sweep reads the same shape, going 99.01 % → 93.34 % for bilinear and 99.95 % → 100.66 % for Lanczos. Two crops, one conclusion.)&lt;/p&gt;

&lt;p&gt;So bilinear brightens the image &lt;em&gt;while&lt;/em&gt; flattening it. That is the exact signature people describe as "washed out", and here it is as two numbers moving in opposite directions on the same pixels. Lanczos does the reverse: it gains contrast, because its negative lobes ring, and the ringing adds local swing that the smoothing removed. That is not a compliment to Lanczos — it is a warning that "more contrast" and "more detail" are not the same measurement, and PSNR will tell you which one you actually bought.&lt;/p&gt;

&lt;p&gt;PSNR against the untouched original says the same thing in a single column, over the same twenty trips:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;N=1&lt;/th&gt;
&lt;th&gt;N=5&lt;/th&gt;
&lt;th&gt;N=20&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;BILINEAR&lt;/td&gt;
&lt;td&gt;35.55 dB&lt;/td&gt;
&lt;td&gt;28.61 dB&lt;/td&gt;
&lt;td&gt;22.92 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BICUBIC&lt;/td&gt;
&lt;td&gt;42.45 dB&lt;/td&gt;
&lt;td&gt;34.57 dB&lt;/td&gt;
&lt;td&gt;31.31 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LANCZOS&lt;/td&gt;
&lt;td&gt;47.37 dB&lt;/td&gt;
&lt;td&gt;39.18 dB&lt;/td&gt;
&lt;td&gt;32.63 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Between the first round trip and the twentieth, bilinear loses 12.6 dB — an enormous loss for an operation that is, in theory, supposed to be approximately identity. Bicubic loses 11.1 dB and Lanczos 14.7 dB over the same span, so the PSNR gap closes as &lt;em&gt;N&lt;/em&gt; grows; but the &lt;em&gt;absolute&lt;/em&gt; positions never swap, and bilinear's 22.92 dB after twenty trips is worse than a fairly aggressive JPEG.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxmc8cf5fqrrja5oye9m4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxmc8cf5fqrrja5oye9m4.png" alt="Two panels from nhip111_resize_drift.json. Left: mean level drift against round-trip count for three kernels, with the bilinear band showing the min/max spread across the seven photographs. Right: the same runs read as standard deviation against each image's own untouched value." width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The hypothesis I had to throw away
&lt;/h2&gt;

&lt;p&gt;My first explanation was rounding. Bilinear 2× then 1× averages pairs of pixels; if the integer sum of a pair is odd, the half-value has to be rounded one way or the other, and a resampler that rounds half-up should add a systematic +0.5 per pair per trip. That predicts a drift that grows linearly with &lt;em&gt;N&lt;/em&gt;, which is roughly the shape I was seeing.&lt;/p&gt;

&lt;p&gt;So I built two fields to test it. In the first, every 2×2 pair sums to an odd number, so every pair must round up: the model predicts +0.5 per trip. In the second, every pair sums to an even number and nothing needs rounding: the model predicts exactly 0.&lt;/p&gt;

&lt;p&gt;Measured:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;field&lt;/th&gt;
&lt;th&gt;predicted at N=1&lt;/th&gt;
&lt;th&gt;measured at N=1&lt;/th&gt;
&lt;th&gt;predicted at N=20&lt;/th&gt;
&lt;th&gt;measured at N=20&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;all-odd pairs&lt;/td&gt;
&lt;td&gt;+0.5&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;+0.5&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;all-even pairs&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;+0.5&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;+0.5&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both came back the wrong way round. The odd field, which must round, did not move at all. The even field, which must not round, moved by half a code level immediately and stayed there. The rounding model is dead, and I could not replace it with another one from the evidence: what I have is a characterisation, not a mechanism, and I would rather publish it that way than dress up a guess.&lt;/p&gt;

&lt;p&gt;What survives is a smaller, solid fact about &lt;em&gt;where&lt;/em&gt; the bias lives. Isolating the two legs on a 256-pixel crop:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;up leg&lt;/th&gt;
&lt;th&gt;down leg&lt;/th&gt;
&lt;th&gt;full round trip&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;BILINEAR&lt;/td&gt;
&lt;td&gt;+0.2058&lt;/td&gt;
&lt;td&gt;+0.1312&lt;/td&gt;
&lt;td&gt;+0.3676&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BICUBIC&lt;/td&gt;
&lt;td&gt;+0.0098&lt;/td&gt;
&lt;td&gt;+0.0089&lt;/td&gt;
&lt;td&gt;+0.0181&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LANCZOS&lt;/td&gt;
&lt;td&gt;−0.0001&lt;/td&gt;
&lt;td&gt;−0.0043&lt;/td&gt;
&lt;td&gt;−0.0007&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both legs contribute for bilinear; neither of the other two kernels does anything of consequence on either leg. (The two legs sum to 0.3370, not to the round trip's 0.3676 — they are separate one-shot measurements on the same crop, not a decomposition, and I am not going to pretend otherwise.)&lt;/p&gt;

&lt;h2&gt;
  
  
  What the drift needs in order to happen
&lt;/h2&gt;

&lt;p&gt;Three facts narrow this down considerably, and they are the reason I trust the result even without a mechanism.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A monotonic ramp does not drift. At all.&lt;/strong&gt; A 256-pixel horizontal ramp running 0 to 255 exactly once across the width — every code value present, perfectly flat histogram, no repeated values — measures &lt;strong&gt;0.00&lt;/strong&gt; on bilinear, bicubic and Lanczos after twenty round trips. Not "small". Zero. Twenty trips also leave its maximum absolute error at 0.&lt;/p&gt;

&lt;p&gt;That is a strange result until you notice what the ramp lacks: repeated values. A histogram that is perfectly flat gives the resampler no majority to round toward, so nothing accumulates. The drift needs &lt;em&gt;variance and repetition&lt;/em&gt;, not just interpolation error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Uniform noise drifts as much as photographs do.&lt;/strong&gt; At &lt;em&gt;N&lt;/em&gt;=20, bilinear moves photographs by +10.797 and full-amplitude uniform noise by +10.722. The worst plausible objection — "you are measuring your particular seven photos" — fails at the first test. Meanwhile a checkerboard, which has the highest frequency content of anything I could construct, drifts only +1.83. So it is not "high frequency" either. It is something about the distribution of values the kernel is averaging, and a two-valued image has almost no distribution to bias.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is not clipping, and it is not the histogram.&lt;/strong&gt; The clipping story is easy to state and easy to kill. On &lt;code&gt;med_1344&lt;/code&gt;, the image with the most saturated pixels, bilinear's round trip &lt;em&gt;reduces&lt;/em&gt; the number of pixels sitting at 255 from 1586 down to 255 while the mean &lt;em&gt;rises&lt;/em&gt; by +9.81. Fewer clipped whites cannot make an image brighter. The bias is also spread evenly: interior pixels move +9.64, border pixels +10.36, so it is not edge handling either.&lt;/p&gt;

&lt;p&gt;The histogram story dies the same way. Shifting the whole image's mean input level from 90.09 up to 165.54 — 75 code values of actual movement, from an offset sweep spanning −40 to +40 — changes bilinear's twenty-trip drift from 10.63 to 10.01. It is essentially flat in mean level. Whatever the kernel is doing, it is not a function of how bright the image is.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn8tslicr8ao58r5igscp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn8tslicr8ao58r5igscp.png" alt="Panel A: drift after twenty round trips for four content types on a log axis — photograph and noise drift roughly ten times further than a checkerboard, and the monotonic ramp is exactly zero on all three kernels. Panel B: the same photograph at five brightness offsets, showing drift barely moves as the mean input level sweeps 80 code values." width="799" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it starts to matter
&lt;/h2&gt;

&lt;p&gt;The crossing points are the number I would actually put in a workflow doc. Bilinear's drift against zero is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Under one code value&lt;/strong&gt; for the first two round trips; it crosses 1.0 at &lt;em&gt;N&lt;/em&gt;=3.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Over two code values&lt;/strong&gt; at &lt;em&gt;N&lt;/em&gt;=5.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Over eight&lt;/strong&gt; at &lt;em&gt;N&lt;/em&gt;=20.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Neither bicubic nor Lanczos crosses one code value at any &lt;em&gt;N&lt;/em&gt; I tested, up to twenty.&lt;/p&gt;

&lt;p&gt;So a single upscale-then-downscale does not damage an image in any way you can see, in any kernel. Two of them still do not. It is the repeated pass — the derive-a-thumbnail-then-derive-from-the-thumbnail, the export-preview-reexport loop, the batch script that normalises to a fixed size on every run — where bilinear starts to show. And +8.6 code values on a skin tone is visible: it is the difference between two adjacent shades in a gradient sky, and on a product shot it is a visible lightening against a colour-managed reference.&lt;/p&gt;

&lt;p&gt;It also survives compression. On the uniform-noise field, re-encoding after twenty trips at JPEG quality 92 leaves bilinear's drift at 10.784 against 10.793 before the encode — the artefact is in the file, not in the codec's head.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should not use this
&lt;/h2&gt;

&lt;p&gt;Three honest limits, because the data does not support more than this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not use twenty round trips as a stand-in for a real pipeline.&lt;/strong&gt; A real pipeline is not the same kernel both ways. Upscale with Lanczos, downscale with a box filter, and the drift changes by an amount I did not measure. I am reporting the composition of one kernel with itself because that is the case I can attribute; do not extrapolate the +8.60 to a pipeline that mixes kernels.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not conclude that Lanczos is safe to re-apply forever.&lt;/strong&gt; Lanczos wins on brightness and PSNR here, and gains contrast, and that contrast gain is ringing. Twenty round trips of ringing on a high-contrast edge is a halo that grows. PSNR above 30 dB is compatible with a very ugly edge; this table cannot see it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not use this as a quality metric.&lt;/strong&gt; PSNR after twenty trips says bilinear is worst, and it is, on mean level and PSNR both. But a single 4× upscale — the operation you actually care about — is a different measurement with a different winner depending on content, and this experiment says nothing about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would actually change in a pipeline
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Never use bilinear in a loop the user does not see.&lt;/strong&gt; One resize, fine. A resize that runs on every export, or on every thumbnail regeneration, is where the 0.43-codes-per-trip rate compounds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pick the kernel by how many times it will run, not by how it looks once.&lt;/strong&gt; Bicubic's twenty-trip drift is 0.076 and its twenty-trip PSNR is 31.3 dB — roughly 8 dB better than bilinear at the same trip count, for a kernel that costs a few more taps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If you must re-derive, derive from the original every time.&lt;/strong&gt; Twenty trips is bad; twenty trips with an &lt;em&gt;N&lt;/em&gt;=1 intermediate that is already +0.34 is how you get to +8.6 without anyone noticing, because each individual step looks like nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test with a ramp and a flat field before you trust any number.&lt;/strong&gt; My ramp and my flat fields are what told me the kernel was fine and the drift was real, in that order. If flat 128 moves, you are measuring your harness.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure the mean, not just PSNR.&lt;/strong&gt; PSNR cannot distinguish "shifted brighter" from "smeared", and those need different fixes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you would rather not run the loop at all, that is the sane default: &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;the upscaler at upgolab.com&lt;/a&gt; takes the source file and produces the output size in one pass with a preset chosen for the content type, which removes the repeated-derivation pattern entirely. The measurements above are the argument for one pass from the original rather than a chain of small ones — the arithmetic is the same arithmetic whether you write the loop yourself or not.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That clip is a pass through five presets on real product frames — &lt;a href="https://youtu.be/tCXoB3uBKm4" rel="noopener noreferrer"&gt;direct link&lt;/a&gt; if the embed does not load. Watch the skin and the product edge as the preset changes; the point of the table above is that those two regions respond to different things, and a single sharpening amount applied to both is the same category of mistake as running one kernel twenty times.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Count your resizes, not your megapixels.&lt;/strong&gt; A 24-megapixel file resized once is not the risk. A 1-megapixel file resized twenty times is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the kernel identity per leg.&lt;/strong&gt; Same kernel both ways is what these numbers describe; a mixed pipeline needs its own measurement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run the ramp control.&lt;/strong&gt; Monotonic ramp, every value once — if it drifts, your measurement is wrong, not your resampler.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run the flat-field control.&lt;/strong&gt; 0/127/128/200 after twenty trips must be bit-identical. If they are not, the kernel is not normalised.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run NEAREST.&lt;/strong&gt; Bit-exact or the harness is lying to you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Look at the standard deviation, not only the mean.&lt;/strong&gt; Bilinear's 88.0 % at twenty trips is the contrast you actually lose; the +8.60 is the brightness you gain. They are the same event.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop at two round trips if you are using bilinear.&lt;/strong&gt; Under one code value, no visible cost. Past three, you are in territory the eye can find.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The interesting part of this experiment is not that bilinear is cheap and bicubic is good. It is that the cheap kernel fails in a direction — brighter &lt;em&gt;and&lt;/em&gt; flatter — that mimics a bad exposure rather than a bad resize, which is exactly the failure mode people blame on their camera instead of their export script. The rounding explanation I wanted was wrong, and the evidence for that is in &lt;code&gt;nhip111_rounding.json&lt;/code&gt; alongside the numbers that killed it. What is left is a control-verified characterisation: twenty bilinear round trips, +8.60 code values, 88 % of the contrast, 22.9 dB. That is enough to change how I would wire a batch job, and it is all the data supports.&lt;/p&gt;

</description>
      <category>imageprocessing</category>
      <category>python</category>
      <category>photography</category>
      <category>computervision</category>
    </item>
    <item>
      <title>An Upscaler Does Not Remove a Hot Pixel. It Smears It Into Exactly f-squared of Them.</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Fri, 27 Nov 2026 12:38:08 +0000</pubDate>
      <link>https://dev.to/celticgemini001/an-upscaler-does-not-remove-a-hot-pixel-it-smears-it-into-exactly-f2-of-them-2e64</link>
      <guid>https://dev.to/celticgemini001/an-upscaler-does-not-remove-a-hot-pixel-it-smears-it-into-exactly-f2-of-them-2e64</guid>
      <description>&lt;p&gt;My first instrument reported that a 2× upscale removed &lt;strong&gt;99.76 %&lt;/strong&gt; of the salt-and-pepper noise I had injected into seven photographs. That number is real. It is also wrong, and the reason it is wrong is the most useful thing I learned in this whole experiment: the upscaler did not remove the noise, it diluted it below the threshold my instrument was using to call something noise.&lt;/p&gt;

&lt;p&gt;Here is the short version of what actually happens to a single corrupted pixel when you resize by a factor &lt;em&gt;f&lt;/em&gt; with bilinear interpolation. Its total energy is conserved &lt;strong&gt;exactly&lt;/strong&gt;: the sum of the deltas it leaves behind is &lt;code&gt;127 · f²&lt;/code&gt; code levels, no more and no less. What changes is the peak. At 2× the peak drops to 55.9 % of its original height. At 3× it does not drop at all — it is &lt;strong&gt;100 %&lt;/strong&gt;. At 4×, 76.4 %. At 8×, 88.2 %. The sequence is not monotonic and it is not an artefact of any algorithm: it falls out of where the output pixel centres land relative to the source sample, and it can be predicted to within 0.006 of the measured value with one multiplication.&lt;/p&gt;

&lt;p&gt;Everything below comes out of five files in this campaign's &lt;code&gt;tracking/&lt;/code&gt; directory: &lt;code&gt;nhip112_impulse.json&lt;/code&gt;, &lt;code&gt;nhip121_med_cost.json&lt;/code&gt;, &lt;code&gt;nhip121_hotpixel_census.json&lt;/code&gt;, &lt;code&gt;nhip122_crossover.json&lt;/code&gt;, &lt;code&gt;nhip123_geom_exact.json&lt;/code&gt; and &lt;code&gt;nhip123_energy.json&lt;/code&gt;. Seven photographs, 512-pixel centre crops, grayscale, bilinear resize, and injection masks tracked by coordinate rather than by brightness threshold — that last decision is the whole reason the second instrument worked and the first one did not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first instrument found 977 defective pixels that were never defective
&lt;/h2&gt;

&lt;p&gt;I wanted to know how far a point defect spreads after an upscale. The obvious way to measure "did the defect survive" is to count pixels pinned at 0 or 255, because that is what salt-and-pepper noise is: dead black and blown white. So version one counted exactly that. It reported a large, satisfying removal rate.&lt;/p&gt;

&lt;p&gt;Then a control caught it. I ran the same counter on the clean, uncorrupted crops — no noise injected at all — and it found survivors anyway. That is impossible unless the counter is reading something other than my noise.&lt;/p&gt;

&lt;p&gt;So I counted the real thing. In the same seven 512-pixel crops, before any processing:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;crop&lt;/th&gt;
&lt;th&gt;pixels at 0&lt;/th&gt;
&lt;th&gt;pixels at 255&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;med_048d3778&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_1344197c&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_6766a320&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;216&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_792e8b64&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;653&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_ac7b6755&lt;/td&gt;
&lt;td&gt;21&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_b4fd2338&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;med_c079d084&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;754&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;223&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Nine hundred and seventy-seven genuinely clipped pixels in 1,835,008 samples — about 0.053 %. They are not defects. They are specular highlights, deep shadows, the black inside a lens barrel, and every one of them is a correctly exposed part of a real photograph. A threshold-based defect detector cannot tell them apart from injected noise, because there is nothing to tell apart: both are the value 255.&lt;/p&gt;

&lt;p&gt;Version two replaced the threshold with a mask. When I inject a corrupted pixel, I record its coordinate. When I ask "did it survive", I ask whether the output pixels whose nearest source sample is that coordinate are still pinned. Now "survived" is exact and needs no threshold, and the clean-frame control returns zero for every arm. That control is &lt;code&gt;C1_clean_survivors&lt;/code&gt; in &lt;code&gt;nhip112_impulse.json&lt;/code&gt; and it is the only reason the numbers in this article mean anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  What one bright pixel actually becomes
&lt;/h2&gt;

&lt;p&gt;Take a 64×64 field that is uniformly 128 and set one pixel to 255. Resize it. This is not a photograph and not a JPEG, so nothing you see is a compression artefact — it is the resampler and nothing else.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor&lt;/th&gt;
&lt;th&gt;pixels touched&lt;/th&gt;
&lt;th&gt;bbox (px)&lt;/th&gt;
&lt;th&gt;peak (levels)&lt;/th&gt;
&lt;th&gt;peak ÷ 127&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;71.0&lt;/td&gt;
&lt;td&gt;0.5591&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;127.0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.0000&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;97.0&lt;/td&gt;
&lt;td&gt;0.7638&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6×&lt;/td&gt;
&lt;td&gt;144&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;106.0&lt;/td&gt;
&lt;td&gt;0.8346&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8×&lt;/td&gt;
&lt;td&gt;256&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;112.0&lt;/td&gt;
&lt;td&gt;0.8819&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa528p0mq48kfn0h45xlz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa528p0mq48kfn0h45xlz.png" alt="Left: the peak a single hot pixel retains against upscale factor, with the analytic bilinear weight overlaid. Right: the measured damage extent, against the rule 2f for even factors and 2f − 1 for odd factors, extended to 16×." width="799" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two things in that table are worth stopping on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The peak is not monotonic.&lt;/strong&gt; If upscaling progressively blurred a defect, the peak would fall as the factor rose. It does not: 2× costs you 44 % of the peak and 8× costs you 12 %. 3× costs you nothing at all. Any mental model in which "higher factor = more smoothing of small features" is refuted by the 3× row.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The footprint is 4 pixels at 2×, not 2.&lt;/strong&gt; The naive expectation — one source pixel becomes one 2×2 block — describes which output pixels have that pixel as their &lt;em&gt;nearest&lt;/em&gt; source, not the extent of the damage. The damage bleeds into neighbouring pixels at a peak of 71 levels. That distinction is what broke the first instrument, and it is also what decides which repair filter works later.&lt;/p&gt;

&lt;h2&gt;
  
  
  The peak loss is bilinear weight arithmetic, not an algorithm
&lt;/h2&gt;

&lt;p&gt;Here is the part I expected to be messy and turned out to be exact. Bilinear interpolation at output pixel &lt;em&gt;i&lt;/em&gt; samples the source at coordinate &lt;code&gt;(i + 0.5)/f − 0.5&lt;/code&gt;. If that coordinate lands at fractional distance &lt;em&gt;d&lt;/em&gt; from the nearest source sample, the weight on that sample — in one dimension — is &lt;code&gt;1 − d&lt;/code&gt;, and in two dimensions &lt;code&gt;(1 − dx)(1 − dy)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For an even factor, the pixel centre lands halfway between samples. For an odd factor, it lands exactly on one.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor&lt;/th&gt;
&lt;th&gt;source coord of the peak&lt;/th&gt;
&lt;th&gt;fractional offset&lt;/th&gt;
&lt;th&gt;predicted weight&lt;/th&gt;
&lt;th&gt;measured&lt;/th&gt;
&lt;th&gt;error&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;31.750&lt;/td&gt;
&lt;td&gt;0.25&lt;/td&gt;
&lt;td&gt;0.5625&lt;/td&gt;
&lt;td&gt;0.5591&lt;/td&gt;
&lt;td&gt;−0.0034&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;32.000&lt;/td&gt;
&lt;td&gt;0.00&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.0000&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1.0000&lt;/td&gt;
&lt;td&gt;0.0000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;31.875&lt;/td&gt;
&lt;td&gt;0.125&lt;/td&gt;
&lt;td&gt;0.7656&lt;/td&gt;
&lt;td&gt;0.7638&lt;/td&gt;
&lt;td&gt;−0.0018&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6×&lt;/td&gt;
&lt;td&gt;31.9167&lt;/td&gt;
&lt;td&gt;0.0833&lt;/td&gt;
&lt;td&gt;0.8403&lt;/td&gt;
&lt;td&gt;0.8346&lt;/td&gt;
&lt;td&gt;−0.0057&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8×&lt;/td&gt;
&lt;td&gt;31.9375&lt;/td&gt;
&lt;td&gt;0.0625&lt;/td&gt;
&lt;td&gt;0.8789&lt;/td&gt;
&lt;td&gt;0.8819&lt;/td&gt;
&lt;td&gt;+0.0030&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Largest error across all five factors: &lt;strong&gt;0.0057&lt;/strong&gt;, which is less than one code level out of 127. There is no fitting and no free parameter here — &lt;code&gt;(1 − 1/(2f))²&lt;/code&gt; is the entire model, and it explains a curve that looks arbitrary.&lt;/p&gt;

&lt;p&gt;The 3× case is exact because &lt;code&gt;(3 + 0.5)/3 − 0.5 = 0.6667&lt;/code&gt;, and the nearest integer is 1, at distance 0.3333... no. Let me state it the way it actually computes: the output pixel with the maximum response sits at source coordinate 32.0 exactly, which is the injected pixel itself, at distance zero. Weight 1.0. The impulse passes through a 3× bilinear resize untouched in peak, spread over a 5×5 area.&lt;/p&gt;

&lt;p&gt;The tiny negative bias at 2×, 4× and 6× is quantisation: the operation runs in 8-bit, so a delta of 71 is really 70.9 rounded. That is the whole residual.&lt;/p&gt;

&lt;h2&gt;
  
  
  Energy is conserved exactly, and that is why "removed" was the wrong word
&lt;/h2&gt;

&lt;p&gt;Sum every delta the defect leaves in the output and divide by 127 — the total budget of one full-scale pixel:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor&lt;/th&gt;
&lt;th&gt;Δ sum ÷ 127&lt;/th&gt;
&lt;th&gt;ideal f²&lt;/th&gt;
&lt;th&gt;footprint&lt;/th&gt;
&lt;th&gt;Δ sum ÷ peak&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;4.000&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;7.15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;9.000&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;9.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;16.000&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;20.95&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5×&lt;/td&gt;
&lt;td&gt;25.000&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;25.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6×&lt;/td&gt;
&lt;td&gt;36.031&lt;/td&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;43.17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8×&lt;/td&gt;
&lt;td&gt;64.504&lt;/td&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;73.14&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The total is &lt;code&gt;f²&lt;/code&gt; to within 0.8 % at every factor I measured, up to 16×. Bilinear resize distributes a point source over f² units of area — as you would expect from conservation — and does not attenuate it.&lt;/p&gt;

&lt;p&gt;Which means my headline number was describing my instrument, not the image. "99.76 % of injected impulses removed" was computed by counting output pixels still pinned at 0 or 255. At 2× the peak is 71 levels above background, so a salt pixel at 255 becomes 199 and a pepper pixel at 0 becomes 57. Neither is pinned, so neither counts as a survivor, so the instrument reports removal. The defect is still there at a contrast of 71 levels, which on a mid-grey background is obvious to the eye and would be obvious to any sharpening pass downstream. What the upscale did was move the energy below a threshold I chose, and I then reported the threshold as if it were a property of the image.&lt;/p&gt;

&lt;p&gt;The correct statement is: &lt;strong&gt;the upscale reduces the peak contrast of a point defect by 12 % to 44 %, and reduces its detectability by a threshold you picked, while conserving its total energy exactly.&lt;/strong&gt; Between those two sentences is the difference between a measurement and a measurement plus an unstated definition.&lt;/p&gt;

&lt;p&gt;The practical corollary is uncomfortable. At 8× a hot pixel keeps 88 % of its peak, so an upscale makes it &lt;em&gt;more&lt;/em&gt; conspicuous per-pixel than a 2× does. If your pipeline upscales and then looks for dead pixels by brightness, an 8× upscale will hand you 16× as many candidate pixels at nearly full contrast, and you will write a bug report about a sensor that was fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before or after? Both, and the density decides
&lt;/h2&gt;

&lt;p&gt;Now the repair. The obvious ordering is: upscale first (that is the deliverable), then clean up at the end. The less obvious ordering is: clean at native resolution first, then upscale once. Which one wins depends on something nobody puts in a filter preset — how much noise there is.&lt;/p&gt;

&lt;p&gt;Same seven crops, same bilinear 2×, truth defined as the 2× upscale of the &lt;em&gt;clean&lt;/em&gt; crop so every filter is charged for what it changes. Arms: &lt;strong&gt;D&lt;/strong&gt; upscale only; &lt;strong&gt;A3&lt;/strong&gt; median3 at native then 2×; &lt;strong&gt;B3&lt;/strong&gt;/&lt;strong&gt;B5&lt;/strong&gt;/&lt;strong&gt;B7&lt;/strong&gt; 2× then median of that size.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;density p&lt;/th&gt;
&lt;th&gt;D&lt;/th&gt;
&lt;th&gt;A3 (pre)&lt;/th&gt;
&lt;th&gt;B3 (post)&lt;/th&gt;
&lt;th&gt;B5 (post)&lt;/th&gt;
&lt;th&gt;A3 − B3&lt;/th&gt;
&lt;th&gt;images where A3 wins&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0 %&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;42.858&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;50.448&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;43.444&lt;/td&gt;
&lt;td&gt;−7.590&lt;/td&gt;
&lt;td&gt;0/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.05 %&lt;/td&gt;
&lt;td&gt;42.046&lt;/td&gt;
&lt;td&gt;42.767&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;45.742&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;43.211&lt;/td&gt;
&lt;td&gt;−2.975&lt;/td&gt;
&lt;td&gt;1/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.10 %&lt;/td&gt;
&lt;td&gt;39.107&lt;/td&gt;
&lt;td&gt;42.802&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;43.589&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;42.969&lt;/td&gt;
&lt;td&gt;−0.787&lt;/td&gt;
&lt;td&gt;2/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.20 %&lt;/td&gt;
&lt;td&gt;36.018&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.739&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;40.995&lt;/td&gt;
&lt;td&gt;42.593&lt;/td&gt;
&lt;td&gt;+1.744&lt;/td&gt;
&lt;td&gt;4/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.30 %&lt;/td&gt;
&lt;td&gt;34.100&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.597&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;39.192&lt;/td&gt;
&lt;td&gt;42.039&lt;/td&gt;
&lt;td&gt;+3.405&lt;/td&gt;
&lt;td&gt;6/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.50 %&lt;/td&gt;
&lt;td&gt;31.972&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.570&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;37.179&lt;/td&gt;
&lt;td&gt;41.319&lt;/td&gt;
&lt;td&gt;+5.391&lt;/td&gt;
&lt;td&gt;7/7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.00 %&lt;/td&gt;
&lt;td&gt;28.879&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;42.325&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;34.126&lt;/td&gt;
&lt;td&gt;39.648&lt;/td&gt;
&lt;td&gt;+8.199&lt;/td&gt;
&lt;td&gt;7/7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faoapfyd047b29du844zk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faoapfyd047b29du844zk.png" alt="Left: PSNR against injected noise density for the pre-filter and both post-filters, with the crossover between them. Right: the same arms on a clean frame — no noise at all — where the ordering reverses by 7.6 dB." width="800" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The crossover is between 0.1 % and 0.2 %. Below it the post-filter wins, at 0 % by 7.6 dB, because a 3×3 median at native resolution is destructive to real detail: measured against the untouched native crop, it costs 40.2 dB on clean frames. Above 0.2 % the pre-filter wins, at 1 % by 8.2 dB, because it sees each defect at full amplitude and replaces it with a genuine neighbourhood median before any of that energy has been spread.&lt;/p&gt;

&lt;p&gt;And notice the shape of the pre-filter's curve. From 0 % to 1 % density, A3 moves from 42.858 to 42.325 — &lt;strong&gt;0.53 dB&lt;/strong&gt; total. It is almost flat. The post-filter falls 16.3 dB over the same range and the unfiltered upscale falls 20.1 dB. That flatness is not a small effect: it means the pre-filter's worst case is essentially its best case, while every post-filter's quality is a function of a parameter the operator does not control.&lt;/p&gt;

&lt;p&gt;I have to report the weak part of this honestly. At exactly 0.2 %, where the &lt;em&gt;average&lt;/em&gt; says the pre-filter wins by 1.744 dB, &lt;strong&gt;only 4 of the 7 images agree&lt;/strong&gt;. The mean has crossed but the population has not. Below 0.3 % I would not call the ranking settled on this sample; from 0.3 % upward it is 6/7 and then 7/7, and that is where I would put the threshold in practice.&lt;/p&gt;

&lt;p&gt;There is a second, independent result in that table that supports the pre-filter from a different direction: &lt;strong&gt;B5 beats B3 at every density&lt;/strong&gt;, and at 0.005 % density it even beats A3 on two of the seven images. A 5×5 median is a better post-filter than a 3×3. Why, exactly?&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the post-filter needs a bigger window: 4 pixels versus 3
&lt;/h2&gt;

&lt;p&gt;Go back to the footprint table. At 2×, a single hot pixel occupies a &lt;strong&gt;4×4&lt;/strong&gt; area of the output at meaningful contrast. Now apply a 3×3 median at the output. At the centre of the defect, half the window — 5 of 9 samples — is defect; the median of a window that is mostly defect returns something close to defect. The filter is structurally too small to see the edge of the thing it is supposed to remove.&lt;/p&gt;

&lt;p&gt;A 5×5 window gives 9 clean samples against 16 defect samples at the worst position and does only marginally better at the centre, but at the &lt;em&gt;border&lt;/em&gt; of the footprint it works, and that is where most of the perceptible contrast sits. That is the entire explanation for B3 at 26.60 dB and B5 at 32.28 dB at 5 % density — a 5.7 dB gap that has nothing to do with tuning and everything to do with window size versus footprint size.&lt;/p&gt;

&lt;p&gt;And the rule for the footprint has no exceptions. Measured bounding box equals &lt;strong&gt;2f&lt;/strong&gt; at every even factor and &lt;strong&gt;2f − 1&lt;/strong&gt; at every odd factor, from 2× to 16×:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;f&lt;/th&gt;
&lt;th&gt;measured bbox&lt;/th&gt;
&lt;th&gt;2f&lt;/th&gt;
&lt;th&gt;2f − 1&lt;/th&gt;
&lt;th&gt;rule holds&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;✓&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Eight factors, zero exceptions. The odd-factor case is one pixel narrower because the output centre lands on the source sample and the two nearest neighbours are symmetric, so the bilinear support spans &lt;code&gt;f − 1&lt;/code&gt; on each side plus the centre, rather than &lt;code&gt;f&lt;/code&gt; on each side. This is documented sediment of coordinate convention; the &lt;a href="https://en.wikipedia.org/wiki/Bilinear_interpolation" rel="noopener noreferrer"&gt;bilinear interpolation&lt;/a&gt; article has the general form, and the sampling-offset detail is the part everyone gets wrong when they assume "one pixel becomes f × f".&lt;/p&gt;

&lt;p&gt;So: if you insist on repairing after the resize, your median window must be at least &lt;code&gt;2f + 1&lt;/code&gt; per side to be able to see past the footprint — which for 8× means a 17×17 median, which will demolish every real edge in the frame. That is not a filter choice, that is a reason to move the repair upstream.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should not do any of this
&lt;/h2&gt;

&lt;p&gt;Three cases where the right answer is to leave the pixels alone.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The "defects" are clipped highlights.&lt;/strong&gt; My census found 754 genuinely black and 223 genuinely white pixels in 7 clean crops — specular detail and dark interiors, all of them real. Any median pass, before or after, will round them off. On a product shot with a chrome edge or a light source in frame, this is visible damage for no benefit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The source is already clean and you are going to sharpen afterwards.&lt;/strong&gt; On a clean frame the pre-filter costs 7.6 dB relative to doing nothing but the resize (&lt;code&gt;A3&lt;/code&gt; 42.86 vs &lt;code&gt;B3&lt;/code&gt; 50.45, and &lt;code&gt;D&lt;/code&gt; is by definition the truth). You would be paying for a repair with no defect to repair, and then adding edge enhancement on top of a slightly flattened image, which is how you get halos.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You are upscaling to a fixed target and cannot change the order.&lt;/strong&gt; If the deliverable is already produced — the resize happened upstream, the file is what it is — a 3×3 median at the output is worse than nothing at high factors, because it costs real detail and cannot reach the footprint. Either use &lt;code&gt;2f + 1&lt;/code&gt; and accept the cost, or escalate to the source.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The general principle that survives all of this: &lt;strong&gt;a filter should be applied where the defect is still small enough to be filtered.&lt;/strong&gt; A point defect is one pixel at native resolution and &lt;code&gt;f²&lt;/code&gt; worth of area after a resize. Every extra operation between the defect and the filter makes the filter's job worse by a factor that compounds.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you need the resize itself done
&lt;/h2&gt;

&lt;p&gt;The reason I ran this measurement at all is that the ordering of a repair relative to a resize is a pipeline decision, not a filter setting, and pipeline decisions are the ones that stay wrong for years. In production, resizing should happen once, at an integer factor where possible, from the best available source, and it should consume the cleaned input rather than output something a downstream stage has to fix.&lt;/p&gt;

&lt;p&gt;If the resize half of that is what you need handled, &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;the upscaler at upgolab.com&lt;/a&gt; runs the resize and picks a preset for the content type; the numbers above are the argument for doing your sensor cleanup before you hand it a file rather than after.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That 28-second clip is a pass through five presets on real product frames — &lt;a href="https://youtu.be/tCXoB3uBKm4" rel="noopener noreferrer"&gt;direct link&lt;/a&gt; if the embed does not load. Watch what changes between presets and compare it to the peak table above: the presets differ mostly in how much local contrast survives, which is exactly the axis along which a hot pixel's peak moves from 55.9 % to 88.2 % depending on factor alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers said, including the part that insulted me
&lt;/h2&gt;

&lt;p&gt;I set out to measure the repair radius a point defect needs after an upscale, expecting it to scale with the factor in some smooth way. Three things came back instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My first instrument was measuring clipped highlights, not noise.&lt;/strong&gt; 977 genuinely clipped pixels in seven clean crops. It took a control I nearly skipped — count survivors on a frame where I injected nothing — to notice that the number I was reporting as a removal rate was substantially a measurement of the photographs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The peak loss is arithmetic and the total energy loss is zero.&lt;/strong&gt; &lt;code&gt;(1 − 1/(2f))²&lt;/code&gt; predicts the measured peak fraction to within 0.0057 across 2×, 3×, 4×, 6× and 8×, and the sum of the deltas is &lt;code&gt;f²&lt;/code&gt; to within 0.8 %. The "99.76 % removed" figure that would have made a much better headline is a statement about my threshold. Energy is conserved; only the peak moves; and at odd factors it does not move at all — 3× and 5× pass a hot pixel through at full 127-level contrast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The pre-filter versus post-filter question has no universal answer and that is the answer.&lt;/strong&gt; 7.6 dB in favour of post-filtering on a clean frame, 8.2 dB in favour of pre-filtering at 1 % density, crossover between 0.1 % and 0.2 %, and at 0.2 % the mean has crossed while only 4 of 7 images agree. The pre-filter's curve is flat within 0.53 dB across the entire density range; the post-filter's spans 16.3 dB. If you have to pick one without knowing the density, pick the one whose error does not depend on a parameter you cannot see.&lt;/p&gt;

&lt;p&gt;Two cross-file checks, because they cost nothing and catch everything: the 0 %-density row in the crossover file reproduces the clean-cost file exactly (42.858 and 50.448 in both), and the peak fractions in &lt;code&gt;nhip123_geom_exact.json&lt;/code&gt; reproduce the ones recorded independently by &lt;code&gt;nhip112_impulse.json&lt;/code&gt; to 0.003. The campaign's four arm-level controls all pass: zero survivors on clean frames, bit-identical results on repeated runs, injection counts within 1.5σ of binomial expectation, and a known single impulse removed to 0.0 maximum absolute error by median3 at native.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Count clipped pixels in your own clean frames before trusting any defect detector. If 0.05 % of your samples are already at 0 or 255, a threshold-based detector is measuring your photographs&lt;/li&gt;
&lt;li&gt;[ ] Track defects by coordinate, not by brightness. Record the mask at injection time if you are testing, or use a coordinate-verified map if you are not&lt;/li&gt;
&lt;li&gt;[ ] Expect a footprint of &lt;code&gt;2f&lt;/code&gt; (even factor) or &lt;code&gt;2f − 1&lt;/code&gt; (odd factor) per defect, not &lt;code&gt;f&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[ ] Expect peak contrast of &lt;code&gt;(1 − 1/(2f))²&lt;/code&gt; and total energy of exactly &lt;code&gt;f²&lt;/code&gt; — the defect is redistributed, never attenuated&lt;/li&gt;
&lt;li&gt;[ ] Do not claim a defect is "removed" unless you state the threshold that defines removal&lt;/li&gt;
&lt;li&gt;[ ] Repair at native resolution when density is above ~0.3 %; the pre-filter's error stays within 0.6 dB across two decades of density&lt;/li&gt;
&lt;li&gt;[ ] If repairing after the resize, size the window at &lt;code&gt;2f + 1&lt;/code&gt; or larger, and check what that does to real edges first&lt;/li&gt;
&lt;li&gt;[ ] Skip the median entirely on clean, high-contrast sources — 7.6 dB is a lot to spend on nothing&lt;/li&gt;
&lt;li&gt;[ ] Upscale once, at an integer factor, from the cleaned source, and treat the output as the file of record&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>imageprocessing</category>
      <category>python</category>
      <category>photography</category>
      <category>computervision</category>
    </item>
    <item>
      <title>I Built a Detector That Separates Native Photos From 4 Upscales. Then I Fed It a Blurry Photo.</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Fri, 27 Nov 2026 10:41:42 +0000</pubDate>
      <link>https://dev.to/celticgemini001/i-built-a-detector-that-separates-native-photos-from-4x-upscales-then-i-fed-it-a-blurry-photo-1b67</link>
      <guid>https://dev.to/celticgemini001/i-built-a-detector-that-separates-native-photos-from-4x-upscales-then-i-fed-it-a-blurry-photo-1b67</guid>
      <description>&lt;p&gt;Two numbers describe the same measurement, and the gap between them is the whole article: &lt;strong&gt;24.1×&lt;/strong&gt; if I window the transform with a Hann taper, &lt;strong&gt;4.3×&lt;/strong&gt; if I use a rectangular one. I had written the first number down as the headline. My own control said the second number was just as true.&lt;/p&gt;

&lt;p&gt;Here is the claim I started with. A real photograph is band-limited by its optics, so it has a hard spectral wall somewhere below Nyquist. An upscaled photograph has a wall too — but the upscaler put it there deliberately, with a low-pass filter, and it sits at exactly &lt;code&gt;0.5 / factor&lt;/code&gt; cycles per pixel. Above that cutoff an upscale is nearly empty. Below it, it is a smooth interpolation of the source. So the ratio of energy above the cutoff to total energy should separate the two by a wide margin.&lt;/p&gt;

&lt;p&gt;That reasoning is correct. The separation is real. And it is still not enough to answer the question "was this image upscaled?" — because a photo that is merely out of focus does the same thing to the metric, and out-of-focus is dramatically more common than a 4× upscale you didn't ask for.&lt;/p&gt;

&lt;p&gt;Everything below is read out of one file, &lt;code&gt;nhip117_detect.json&lt;/code&gt;. Seven photographs, 512-pixel crops, 2-D FFT, one metric: &lt;strong&gt;AC energy above &lt;code&gt;fc&lt;/code&gt; divided by total AC energy&lt;/strong&gt;, where &lt;code&gt;fc = 0.5 / factor&lt;/code&gt;. The native arm in every comparison is measured at the &lt;em&gt;same&lt;/em&gt; cutoff as the upscaled arm it is compared against — not at full band versus reduced band, which would make the gap look larger than it is for free.&lt;/p&gt;

&lt;h2&gt;
  
  
  The wall is there, and it is 11.4× to 37× wide
&lt;/h2&gt;

&lt;p&gt;Five upscale factors, three kernels each, native measured at the matching cutoff:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;factor&lt;/th&gt;
&lt;th&gt;cutoff fc&lt;/th&gt;
&lt;th&gt;native&lt;/th&gt;
&lt;th&gt;bilinear&lt;/th&gt;
&lt;th&gt;bicubic&lt;/th&gt;
&lt;th&gt;Lanczos&lt;/th&gt;
&lt;th&gt;native ÷ bilinear&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;0.250&lt;/td&gt;
&lt;td&gt;0.0111&lt;/td&gt;
&lt;td&gt;0.00040&lt;/td&gt;
&lt;td&gt;0.00083&lt;/td&gt;
&lt;td&gt;0.00062&lt;/td&gt;
&lt;td&gt;27.7×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;0.1667&lt;/td&gt;
&lt;td&gt;0.0207&lt;/td&gt;
&lt;td&gt;0.00182&lt;/td&gt;
&lt;td&gt;0.00181&lt;/td&gt;
&lt;td&gt;0.00136&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;11.4×&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;0.125&lt;/td&gt;
&lt;td&gt;0.0370&lt;/td&gt;
&lt;td&gt;0.00153&lt;/td&gt;
&lt;td&gt;0.00230&lt;/td&gt;
&lt;td&gt;0.00206&lt;/td&gt;
&lt;td&gt;24.2×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6×&lt;/td&gt;
&lt;td&gt;0.0833&lt;/td&gt;
&lt;td&gt;0.0596&lt;/td&gt;
&lt;td&gt;0.00161&lt;/td&gt;
&lt;td&gt;0.00189&lt;/td&gt;
&lt;td&gt;0.00156&lt;/td&gt;
&lt;td&gt;37.0×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8×&lt;/td&gt;
&lt;td&gt;0.0625&lt;/td&gt;
&lt;td&gt;0.0701&lt;/td&gt;
&lt;td&gt;0.00191&lt;/td&gt;
&lt;td&gt;0.00216&lt;/td&gt;
&lt;td&gt;0.00160&lt;/td&gt;
&lt;td&gt;36.7×&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhn07mpenx9nx47z0f98s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhn07mpenx9nx47z0f98s.png" alt="Left: native energy and each kernel's residual energy on a log axis across factors 2 to 8. Right: the separation ratio per factor, weakest at 3×." width="800" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Three things in that table surprised me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, the separation is not monotonic in the factor.&lt;/strong&gt; It would be tidy if 2× were the hardest case to detect — least upscaling, least evidence. It isn't. 2× separates by 27.7× and 3× separates by 11.4×. The reason is arithmetic, not physics: the cutoff &lt;code&gt;0.5/factor&lt;/code&gt; has to land between two FFT bins, and at 3× it lands badly relative to the bin grid of a 512-pixel crop. The upscaled arm's residual is a floor set by the window's own leakage, and that floor does not move smoothly with the cutoff. So the weakest point of the whole detector is a &lt;em&gt;bin alignment artefact&lt;/em&gt;, not a property of upscaling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second, the kernel choice barely matters.&lt;/strong&gt; Within any row, bilinear, bicubic and Lanczos are within a factor of &lt;strong&gt;2.08&lt;/strong&gt; of each other at worst (at 2×: 0.00040 bilinear against 0.00083 bicubic), and at 3× they are nearly indistinguishable — 0.00182, 0.00181, 0.00136. The gap to the native arm in the same row is 11× to 37×. What the metric is responding to is the &lt;em&gt;existence of the low-pass filter&lt;/em&gt;, not its shape. That is a useful thing to know and a bad thing for attribution: the metric can tell you a filter exists, but it cannot tell you which one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third — and this is the correction I have to make to my own earlier draft — the separation number changes with the window.&lt;/strong&gt; The &lt;code&gt;native ÷ up&lt;/code&gt; column above is computed under a Hann window. I ran the same pairing under a rectangular window and got 4.3× where Hann gave 24.1×.&lt;/p&gt;

&lt;h2&gt;
  
  
  My control refuted my headline, and that is the useful part
&lt;/h2&gt;

&lt;p&gt;I wrote the control before I wrote the article, which is the only reason I caught this. It said: &lt;em&gt;the ratio must stay above 5× under both windows, because a window changes the leakage floor but not the underlying fact that one signal is band-limited and the other is not.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;C4b: Hann &lt;code&gt;native ÷ up4&lt;/code&gt; = &lt;strong&gt;24.1×&lt;/strong&gt;. Rectangular = &lt;strong&gt;4.3×&lt;/strong&gt;. Prediction: &amp;gt;5× under both. &lt;strong&gt;Failed.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcbul62tmilw6ya326xhr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcbul62tmilw6ya326xhr.png" alt="Left: energy above the 0.125 cutoff as a function of Gaussian blur on a native photo, against the 4× upscale level. Right: the same native-to-upscale ratio under two different windows." width="799" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The absolute value of this metric is a property of the window, not of the image. A Hann taper concentrates energy into a narrow main lobe and suppresses sidelobes; a rectangular window does the opposite, smearing energy across the spectrum and filling the region above the cutoff with leakage. That is textbook &lt;a href="https://en.wikipedia.org/wiki/Spectral_leakage" rel="noopener noreferrer"&gt;spectral leakage&lt;/a&gt;, and the choice of taper is a real engineering decision, not a formality — which is exactly why &lt;a href="https://en.wikipedia.org/wiki/Window_function" rel="noopener noreferrer"&gt;window functions&lt;/a&gt; get their own chapter in every DSP text.&lt;/p&gt;

&lt;p&gt;The practical rule that comes out of the failure: &lt;strong&gt;quote the ratio with the window named, or don't quote it.&lt;/strong&gt; A bare "24× separation" is not a measurement, it is a measurement plus an unstated taper. Every number below therefore says Hann.&lt;/p&gt;

&lt;p&gt;The same control run showed the window is not close to neutral even on the &lt;em&gt;input&lt;/em&gt; side. Control C4 measured the same image's in-band energy at 0.037 under Hann and 0.0139 under rectangular — a factor of &lt;strong&gt;2.66&lt;/strong&gt; with no upscaling involved at all. When the taper alone can move a reading by 2.66×, a 2.08× spread between kernels cannot be read as "this kernel removes more detail."&lt;/p&gt;

&lt;p&gt;Two more controls, for completeness, both pass: the measurement is deterministic (0.037037 on two consecutive runs of the same image), and a synthetic perfectly band-limited signal returns 0.005535 above its cutoff rather than zero — the floor of the estimator, which is why 0.0004 is the smallest number that means anything here.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test that ends the argument: blur
&lt;/h2&gt;

&lt;p&gt;Up to this point the detector looks good. Here is the experiment that took it apart.&lt;/p&gt;

&lt;p&gt;Take a &lt;strong&gt;native&lt;/strong&gt; photograph — never upscaled, straight out of the camera pipeline — and apply a Gaussian blur of σ pixels. Measure the same metric at the 4× cutoff, 0.125.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;σ (px, on a native photo)&lt;/th&gt;
&lt;th&gt;energy above 0.125&lt;/th&gt;
&lt;th&gt;says "upscaled"?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;td&gt;0.03704&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;td&gt;0.02302&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.7&lt;/td&gt;
&lt;td&gt;0.01696&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;td&gt;0.00993&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.5&lt;/td&gt;
&lt;td&gt;0.00320&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.0&lt;/td&gt;
&lt;td&gt;0.00076&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3.0&lt;/td&gt;
&lt;td&gt;0.00002&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;yes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A Gaussian of σ = 1.0 px on a native file produces a reading &lt;em&gt;below&lt;/em&gt; the 4× upscale's own reading of 0.00153. The detector cannot tell them apart, because at this cutoff they are not different: both are band-limited, both have had their finest detail removed, and the metric asks only whether the detail is gone.&lt;/p&gt;

&lt;p&gt;σ = 1.0 px is not an exotic amount of blur. It is what you get from a cheap lens at full aperture, a plastic window on a phone case, a scanner with the lid slightly open, or one pass of noise reduction on a high-ISO file. It is &lt;em&gt;ordinary softness&lt;/em&gt;, and this test flags it as an upscale.&lt;/p&gt;

&lt;p&gt;Run the confusion count honestly. Five arms came back flagged — four blurs (σ = 1.0, 1.5, 2.0, 3.0) and one 4× upscale — and only one of those five really was an upscale. &lt;strong&gt;Precision: 20%.&lt;/strong&gt; On the native side, four of seven arms were wrongly flagged, so &lt;strong&gt;specificity is 42.9%&lt;/strong&gt;. A method with 24× separation on its headline metric and 20% precision on the question people actually ask is not a detector. It is a softness meter wearing a costume.&lt;/p&gt;

&lt;p&gt;The log-log slope above the cutoff — a second, independent statistic — does not save it either:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;arm&lt;/th&gt;
&lt;th&gt;slope above 0.125 (dB/oct)&lt;/th&gt;
&lt;th&gt;flagged&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;native&lt;/td&gt;
&lt;td&gt;−6.0&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;blur 0.5 px&lt;/td&gt;
&lt;td&gt;−7.05&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;blur 0.7 px&lt;/td&gt;
&lt;td&gt;−8.06&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;blur 1.0 px&lt;/td&gt;
&lt;td&gt;−10.2&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;blur 1.5 px&lt;/td&gt;
&lt;td&gt;−15.45&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;blur 2.0 px&lt;/td&gt;
&lt;td&gt;−22.79&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;upscale 4×&lt;/td&gt;
&lt;td&gt;−19.17&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The 4× upscale's slope sits between blur 1.5 and blur 2.0. There is no threshold on this statistic that admits the upscale and rejects the blurs, because the upscale &lt;em&gt;is&lt;/em&gt; a blur with a particular transfer function. That is not a coincidence to be worked around. It is the mechanism: resampling is low-pass filtering, and the metric measures low-pass filtering. Any statistic that measures "how much high-frequency energy is missing" will be confused by anything else that removes high-frequency energy. Which is most of the things that happen to photographs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two more statistics that cannot do the job
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Level occupancy.&lt;/strong&gt; An upscale interpolates, so it should produce fewer distinct 8-bit values and a lower histogram entropy than the original. It doesn't, meaningfully. Across seven images, distinct values moved 252→252, 250→246, 251→250, 256→250, 256→254, 254→239, 250→227; Shannon entropy moved by at most &lt;strong&gt;0.051 bits&lt;/strong&gt; — rising on five images and falling on two (the largest fall, 7.251 → 7.231, is 0.020 bits). An image with 227 distinct levels instead of 250 is not evidence of anything a viewer would see. Histogram-based "is this upscaled" checks are not measuring what they claim.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JPEG.&lt;/strong&gt; I re-encoded both arms at quality 70, 85 and 95 to see whether compression noise flattens the separation. It doesn't — separation stayed at 1.0 (flagged) for all three images at all three qualities. But that is not the detector succeeding. JPEG quantisation removes high-frequency detail from &lt;em&gt;both&lt;/em&gt; arms, so the native arm's residual falls toward the upscale's floor at the same time. The gap survives, but its meaning degrades: at q70 the 4× residual on one image rose from 0.00153 to 0.00176 while separation was still "1.0," which is the metric becoming &lt;em&gt;more&lt;/em&gt; confident after the evidence got worse.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what is the ratio good for?
&lt;/h2&gt;

&lt;p&gt;It is a good &lt;em&gt;screening&lt;/em&gt; test and a bad &lt;em&gt;verdict&lt;/em&gt;. Used that way, it earns its keep:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the ratio (Hann, named cutoff, same-cutoff native baseline) is &lt;strong&gt;above ~20×&lt;/strong&gt;, the image has a great deal of genuine fine detail and is very unlikely to be a straightforward 4× upscale of a smaller file. That is a useful negative.&lt;/li&gt;
&lt;li&gt;If the ratio is &lt;strong&gt;below ~5×&lt;/strong&gt;, the image has been low-pass filtered by &lt;em&gt;something&lt;/em&gt; — an upscale, a lens, a denoiser, a JPEG chain, or a resize — and you now know to ask which.&lt;/li&gt;
&lt;li&gt;Anything in between is not information. Do not report it as one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reason the negative is trustworthy and the positive is not is asymmetry of evidence. Fine detail that survives at 0.125 and above cannot be manufactured by an interpolator. Its absence can be manufactured by a dozen unrelated things. A test whose positive result has many causes and whose negative result has one cause is only valid in one direction.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should not run this at all
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single image, unknown provenance.&lt;/strong&gt; The metric has no absolute scale. Without a same-cutoff native baseline from a comparable file, the number means nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anything that has been resized, ever.&lt;/strong&gt; A file that was downscaled for the web and then upscaled back has two low-pass filters in it. You will measure the sum and attribute it to one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Screenshots, renders, and anything with synthetic edges.&lt;/strong&gt; The bandlimit assumption is about optics. A render has no optics and no wall, and a screenshot has pixel-aligned edges that will read as maximum detail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heavily denoised files.&lt;/strong&gt; Modern denoisers are trained to preserve edges and remove texture, which produces exactly the signature this metric calls "upscaled." You will get a confident wrong answer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Any question where the answer changes a decision about a person.&lt;/strong&gt; 25% specificity is a fun fact in a notebook and a serious problem in a moderation queue.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A procedure that follows from the numbers
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fix the window before you look at anything.&lt;/strong&gt; Hann, and write it down. If you use rectangular windows for speed, re-run one image under Hann and see how far the ratio moves — on my data it moved 24.1 to 4.3, which is enough to change any conclusion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compare like with like.&lt;/strong&gt; Native energy must be measured at the &lt;em&gt;same&lt;/em&gt; cutoff as the upscaled arm. An earlier version of my own control divided the minimum native residual by the maximum upscale floor &lt;em&gt;across different factors&lt;/em&gt; and printed 3.1× — a cross-factor mismatch that looked like a weak detector and was actually a broken comparison. Pairing each factor with its own cutoff gives 11.4× to 42×.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run the blur null before you trust a positive.&lt;/strong&gt; Take a known-native image, blur it at σ = 1.0 px, and measure. If the blurred native and the suspect land within a factor of ~2, you have learned nothing about the suspect's history.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Report the weakest factor, not the average.&lt;/strong&gt; The 3× case gave 11.4× where 6× gave 37×. The 3× number is the one that governs whether the method works on an arbitrary file, because you do not get to choose the upscale factor of a file someone else made.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Convert a positive into a question, not an accusation.&lt;/strong&gt; "This file's high-frequency content is consistent with a resize" is supportable. "This file was upscaled" is not, and the difference costs one sentence.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Where this feeds into an actual pipeline
&lt;/h2&gt;

&lt;p&gt;The reason I care about the measurement at all is that upscaling decisions upstream decide whether this test is even meaningful later. If a resize is going to happen, it should happen once, at an integer factor, from the best source available, with the kernel chosen for the output rather than inherited from a default — and then the result should be the file of record, not a file that gets resized again somewhere downstream. Every extra low-pass filter in the chain makes provenance unrecoverable, and this experiment is a demonstration of exactly how quickly that happens.&lt;/p&gt;

&lt;p&gt;If the resize half is what you need handled, &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;the upscaler at upgolab.com&lt;/a&gt; runs the resize and selects a preset for the content type; the checklist above is what to run afterwards if you care whether anyone can later tell what happened to the file.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That 28-second video is a pass through five presets on real product frames — &lt;a href="https://youtu.be/tCXoB3uBKm4" rel="noopener noreferrer"&gt;watch it here&lt;/a&gt; if the embed does not load. Watch it with this article in mind: what changes between presets is mostly edge contrast, which is precisely the quantity the blur test above showed is not diagnostic of provenance.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers actually said
&lt;/h2&gt;

&lt;p&gt;I set out to build a native-versus-upscaled detector and expected to report a wide margin and a clean threshold. The margin is real — 11.4× to 37× depending on the factor, under a Hann window — and the threshold does not exist. A Gaussian blur of σ = 1.0 px on a native photograph reads &lt;em&gt;below&lt;/em&gt; the 4× upscale on the identical metric, which means the statistic measures softness and not history. Precision on the arms I tested was 20%; specificity, 42.9%.&lt;/p&gt;

&lt;p&gt;The refutation that stings more is the one about my own headline. I had a ratio of 24.1× that I was going to print without qualification. The control I wrote to protect it — "this ratio should hold under both windows" — failed, and the honest version of the number is "24.1× under Hann, 4.3× under rectangular." Both are in &lt;code&gt;nhip117_detect.json&lt;/code&gt;. The difference between those two sentences is the difference between a measurement and a claim.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Window named and fixed (Hann) before any comparison&lt;/li&gt;
&lt;li&gt;[ ] Native baseline measured at the same cutoff as the upscaled arm&lt;/li&gt;
&lt;li&gt;[ ] Ratio reported per factor, with the weakest factor quoted&lt;/li&gt;
&lt;li&gt;[ ] Blur null run at σ = 1.0 px on a known-native image&lt;/li&gt;
&lt;li&gt;[ ] Kernel spread (2.08× here) checked — it bounds any "this kernel" claim&lt;/li&gt;
&lt;li&gt;[ ] Level-occupancy and histogram statistics kept out of the verdict&lt;/li&gt;
&lt;li&gt;[ ] Positive result phrased as consistency with a resize, not proof of one&lt;/li&gt;
&lt;li&gt;[ ] Decided explicitly whether 20% precision is acceptable for the decision at hand&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>imageprocessing</category>
      <category>python</category>
      <category>photography</category>
    </item>
    <item>
      <title>A Halftone Screen Is a Ruler: Upscaling a Print Divides the Dot Frequency by Exactly the Scale Factor</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Fri, 27 Nov 2026 05:15:14 +0000</pubDate>
      <link>https://dev.to/celticgemini001/a-halftone-screen-is-a-ruler-upscaling-a-print-divides-the-dot-frequency-by-exactly-the-scale-3dln</link>
      <guid>https://dev.to/celticgemini001/a-halftone-screen-is-a-ruler-upscaling-a-print-divides-the-dot-frequency-by-exactly-the-scale-3dln</guid>
      <description>&lt;p&gt;A magazine scan at 300 ppi, upscaled 4×, does not develop new edge detail and it does not develop new dot detail either. The dots that survive are the same dots, printed bigger, with a dot 0.68 mm wide where the print had one 0.17 mm across (a 150 lpi dot at 4×). I measured this on fifteen synthetic screens across five pitches and three scale factors, and the output pitch matched &lt;code&gt;p × F&lt;/code&gt; with a worst-case error of &lt;strong&gt;0.56%&lt;/strong&gt; — smaller than the quantisation of the measurement itself.&lt;/p&gt;

&lt;p&gt;That single number explains most of what goes wrong when people enlarge printed material. It also destroys two things I assumed going in, which I'll show before I get to the advice.&lt;/p&gt;

&lt;p&gt;Everything below comes from one measurement file, &lt;code&gt;halftone_data.json&lt;/code&gt;, produced by &lt;code&gt;halftone_measure_v2.py&lt;/code&gt;. Screens are modelled as an AM clustered-dot lattice: dot area fraction equals tone, radius &lt;code&gt;p·√(tone/π)&lt;/code&gt;, lattice rotated 45°, pitch &lt;code&gt;p&lt;/code&gt; pixels at the source resolution. At 300 ppi a 150 lpi screen gives &lt;code&gt;p = 2&lt;/code&gt;.&lt;br&gt;
That AM clustered-dot geometry — dots of varying area on a fixed lattice, rotated so the four process colours sit on different angles — is the classic screening model described in &lt;a href="https://en.wikipedia.org/wiki/Halftone" rel="noopener noreferrer"&gt;the halftone literature&lt;/a&gt; and why the lattice angle is chosen at all (&lt;a href="https://en.wikipedia.org/wiki/Screen_angle" rel="noopener noreferrer"&gt;screen angle&lt;/a&gt;). Every figure in this article is read out of that file — nothing is estimated.&lt;/p&gt;
&lt;h2&gt;
  
  
  The screen is a clock, and the upscaler only changes the tick rate
&lt;/h2&gt;

&lt;p&gt;A halftone screen is a periodic structure. Periodic structures have a frequency, and resampling is a frequency operation. So the question "what happens to the dots when I upscale" has a one-line answer: the dot frequency divides by the scale factor, and the dot pitch multiplies by it.&lt;/p&gt;

&lt;p&gt;I built five screens on flat 50% grey — &lt;code&gt;p&lt;/code&gt; = 2, 3, 4, 6, 8 pixels — and upscaled each at 2×, 3× and 4× with Lanczos. Then I located the dominant radial frequency in the spectrum, took its reciprocal, and compared it to the prediction.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;source pitch p&lt;/th&gt;
&lt;th&gt;factor F&lt;/th&gt;
&lt;th&gt;predicted pitch (px)&lt;/th&gt;
&lt;th&gt;measured pitch (px)&lt;/th&gt;
&lt;th&gt;error&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;4.00&lt;/td&gt;
&lt;td&gt;3.99&lt;/td&gt;
&lt;td&gt;+0.17%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;8.00&lt;/td&gt;
&lt;td&gt;7.99&lt;/td&gt;
&lt;td&gt;+0.17%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;6.00&lt;/td&gt;
&lt;td&gt;5.97&lt;/td&gt;
&lt;td&gt;+0.54%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;12.00&lt;/td&gt;
&lt;td&gt;11.94&lt;/td&gt;
&lt;td&gt;+0.54%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;8.00&lt;/td&gt;
&lt;td&gt;7.99&lt;/td&gt;
&lt;td&gt;+0.17%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;12.00&lt;/td&gt;
&lt;td&gt;12.07&lt;/td&gt;
&lt;td&gt;−0.56%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;24.00&lt;/td&gt;
&lt;td&gt;24.14&lt;/td&gt;
&lt;td&gt;−0.56%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;32.00&lt;/td&gt;
&lt;td&gt;31.94&lt;/td&gt;
&lt;td&gt;+0.17%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All fifteen runs. Three distinct error values appear in the whole table — +0.17%, +0.54%, −0.56% — and they are grouped by source pitch, not by scale factor. That is the signature of a discrete measurement: the peak-frequency bin is quantised, so a &lt;code&gt;p = 3&lt;/code&gt; screen is measured with a coarser relative resolution than a &lt;code&gt;p = 2&lt;/code&gt; screen. The error is in my estimator, not in the resampler. The resampler is doing exactly &lt;code&gt;p × F&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhbfunx26c8ix1ye2mhxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhbfunx26c8ix1ye2mhxh.png" alt="Residual of measured output pitch against p × F, and dot contrast versus descreen sigma" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The panel on the left plots the residual rather than the two curves on top of each other, because when the fit is this tight the overlay is a single line and tells you nothing. The panel on the right is the part that matters for a workflow: dot contrast as a function of how much Gaussian blur you apply before the resize. Hold that thought; it becomes the central trade-off of this article.&lt;/p&gt;

&lt;p&gt;Here is the uncomfortable consequence. A 4× upscale of a 150 lpi screen produces a 37.5 lpi screen at the output. At 37.5 lpi, the individual dots are visible as dots — not as texture, as &lt;strong&gt;objects&lt;/strong&gt;, at arm's length. You have not removed the screen. You have magnified it into something a person can point at.&lt;/p&gt;
&lt;h2&gt;
  
  
  What I expected: moiré clumping on flat grey
&lt;/h2&gt;

&lt;p&gt;Before running the second experiment I wrote down the prediction. Resampling a periodic lattice at ratios that are not integer multiples should produce beat frequencies: screen pitch 3 at factor 2.5 is exactly the kind of non-commensurate ratio that generates &lt;a href="https://en.wikipedia.org/wiki/Moir%C3%A9_pattern" rel="noopener noreferrer"&gt;moiré&lt;/a&gt; in print. A flat 50% grey is the harshest test, because there is no image content to hide the artefact behind. I expected envelope roughness in the several-percent range at 1.5× and 2.5×.&lt;/p&gt;

&lt;p&gt;That is not what the data says. I averaged each output over three dot pitches — which cancels the dots themselves and leaves only the low-frequency envelope — then measured how much that envelope still moved. A perfect screen on flat grey gives 0. Across forty runs, nothing exceeded &lt;strong&gt;2.98%&lt;/strong&gt;, and the mean sat between 0.94% and 1.58%.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;kernel&lt;/th&gt;
&lt;th&gt;mean envelope roughness&lt;/th&gt;
&lt;th&gt;max&lt;/th&gt;
&lt;th&gt;mean dot contrast&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;nearest&lt;/td&gt;
&lt;td&gt;1.58%&lt;/td&gt;
&lt;td&gt;2.98%&lt;/td&gt;
&lt;td&gt;68.41&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bilinear&lt;/td&gt;
&lt;td&gt;0.94%&lt;/td&gt;
&lt;td&gt;0.98%&lt;/td&gt;
&lt;td&gt;46.46&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bicubic&lt;/td&gt;
&lt;td&gt;1.07%&lt;/td&gt;
&lt;td&gt;1.16%&lt;/td&gt;
&lt;td&gt;61.02&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;lanczos&lt;/td&gt;
&lt;td&gt;1.13%&lt;/td&gt;
&lt;td&gt;1.23%&lt;/td&gt;
&lt;td&gt;68.02&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(Values for &lt;code&gt;p = 3&lt;/code&gt;; the &lt;code&gt;p = 6&lt;/code&gt; screen behaves the same way, 1.28% to 1.40%, because at that pitch the output pitch after resampling is large enough that no beat falls inside the analysis window.)&lt;/p&gt;

&lt;p&gt;Two findings, both against my expectation:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, there is no clumping to speak of.&lt;/strong&gt; Nearest-neighbour is the worst offender at 2.98%, and it earns that number for a mundane reason — it duplicates pixels, so a 50% grey screen at 1.5× becomes an uneven mix of 1-pixel and 2-pixel runs. That is pixel duplication, not moiré. Every interpolating kernel stays at or below 1.23%.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second, bilinear is not the "soft" kernel in this test — it is the kernel that already descreened the image.&lt;/strong&gt; Nearest and Lanczos both keep dot contrast at 68 levels. Bilinear drops it to 46.46. A 1.5× bilinear resize of a screened image is, in effect, a partial descreen: it averages the dot into its neighbours and returns a flatter result. That is a cost when you want the dots gone and a catastrophe when you wanted the texture, and it happens whether you asked for it or not.&lt;/p&gt;

&lt;p&gt;So the moiré story is not the story. The story is contrast, and the next two experiments pin down what contrast costs.&lt;/p&gt;
&lt;h2&gt;
  
  
  Descreening costs edge width, and the price is set by the screen pitch
&lt;/h2&gt;

&lt;p&gt;If the dots are the problem, the obvious move is to blur them out before the resize. The question is what that blur does to the content you were trying to keep.&lt;/p&gt;

&lt;p&gt;I built a screened step — solid ink at 0.90 on the left, near-paper at 0.10 on the right — which is a stand-in for any hard boundary in a printed photo: a product edge, a table line, the join between a suit and a wall. Then I applied a Gaussian of σ = 0 to 3.0 px, upscaled 2× with Lanczos, and measured two things on the output: the dot-band contrast left in the flat ink region, and the 10–90% rise width of the step.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;screen pitch&lt;/th&gt;
&lt;th&gt;dot contrast at σ=0&lt;/th&gt;
&lt;th&gt;σ needed for dot contrast &amp;lt; 6&lt;/th&gt;
&lt;th&gt;edge width at σ=0 (src px)&lt;/th&gt;
&lt;th&gt;edge width after that σ (src px)&lt;/th&gt;
&lt;th&gt;edge widened&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2 px&lt;/td&gt;
&lt;td&gt;52.35&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;td&gt;0.52&lt;/td&gt;
&lt;td&gt;2.57&lt;/td&gt;
&lt;td&gt;4.9×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3 px&lt;/td&gt;
&lt;td&gt;69.41&lt;/td&gt;
&lt;td&gt;1.5&lt;/td&gt;
&lt;td&gt;0.49&lt;/td&gt;
&lt;td&gt;3.37&lt;/td&gt;
&lt;td&gt;6.9×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4 px&lt;/td&gt;
&lt;td&gt;80.22&lt;/td&gt;
&lt;td&gt;2.0&lt;/td&gt;
&lt;td&gt;0.68&lt;/td&gt;
&lt;td&gt;4.45&lt;/td&gt;
&lt;td&gt;6.5×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6 px&lt;/td&gt;
&lt;td&gt;95.70&lt;/td&gt;
&lt;td&gt;2.5&lt;/td&gt;
&lt;td&gt;0.33&lt;/td&gt;
&lt;td&gt;5.53&lt;/td&gt;
&lt;td&gt;16.8×&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The 6-level threshold is my own: below roughly six levels of contrast a periodic structure stops reading as texture and starts reading as noise, and on an 8-bit file it is close to the point where JPEG quantisation would finish it off anyway.&lt;/p&gt;

&lt;p&gt;The pattern is clean and it is bad. A coarser screen needs more blur to kill, and a coarser screen also has thinner recorded edges, because the same scan resolution that produced a &lt;code&gt;p = 6&lt;/code&gt; screen produced it from a coarser halftone that had already thrown the detail away. So the two numbers move against you together: the screen that is hardest to remove is the screen attached to the softest content. At &lt;code&gt;p = 6&lt;/code&gt; you pay a &lt;strong&gt;16.8×&lt;/strong&gt; widening of every edge in the file to make the dots go away.&lt;/p&gt;

&lt;p&gt;A 0.33-pixel edge becomes a 5.53-pixel edge. In a 300 ppi scan, 5.53 pixels is 0.47 mm — visible as a soft halo around every boundary at normal viewing distance. That is not restoration. That is trading one artefact for a different one, and the second artefact is harder to explain to a client.&lt;/p&gt;
&lt;h2&gt;
  
  
  On real photographs the screen comes back louder than the paper ever had it
&lt;/h2&gt;

&lt;p&gt;Synthetic steps are clean. Real photographs are not, so I repeated the comparison on three product images from the preset set — a clear-rendering shot, a cinema-vivid shot, and a true-texture shot — cropping the same 512×512 region from each, screening it at &lt;code&gt;p&lt;/code&gt; = 2, 3, 4, upscaling 2×, and measuring three things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tone error&lt;/strong&gt; — does the local average still match the original tone, in 0–255 levels;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dot amplitude&lt;/strong&gt; — the standard deviation of the dot-band component (the perceptual "screen" you see);&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;structure&lt;/strong&gt; — gradient energy above the dot band, as a percentage of the &lt;em&gt;unscreened&lt;/em&gt; 2× reference. 100% means "as much real edge as the clean image had"; above 100% means the resize invented edge energy.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;arm&lt;/th&gt;
&lt;th&gt;mean dot amplitude&lt;/th&gt;
&lt;th&gt;mean tone error (levels)&lt;/th&gt;
&lt;th&gt;mean structure kept&lt;/th&gt;
&lt;th&gt;structure range&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;reference (unscreened)&lt;/td&gt;
&lt;td&gt;7.40&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bilinear, raw&lt;/td&gt;
&lt;td&gt;38.94&lt;/td&gt;
&lt;td&gt;24.79&lt;/td&gt;
&lt;td&gt;97.2%&lt;/td&gt;
&lt;td&gt;67.0–152.6%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bilinear, descreen&lt;/td&gt;
&lt;td&gt;5.99&lt;/td&gt;
&lt;td&gt;23.03&lt;/td&gt;
&lt;td&gt;51.4%&lt;/td&gt;
&lt;td&gt;46.3–63.9%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lanczos, raw&lt;/td&gt;
&lt;td&gt;57.20&lt;/td&gt;
&lt;td&gt;25.61&lt;/td&gt;
&lt;td&gt;129.6%&lt;/td&gt;
&lt;td&gt;95.4–186.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lanczos, descreen&lt;/td&gt;
&lt;td&gt;8.46&lt;/td&gt;
&lt;td&gt;23.02&lt;/td&gt;
&lt;td&gt;54.5%&lt;/td&gt;
&lt;td&gt;47.4–69.2%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Read the first data row against the reference row. The unscreened image has a dot-band amplitude of 7.40 levels — that is the natural fine texture of the photograph itself. Bilinear on the raw screen returns &lt;strong&gt;38.94&lt;/strong&gt;, 5.4× the reference once you average the per-run amplitude ratios. Lanczos returns &lt;strong&gt;57.20&lt;/strong&gt;, 8.2× on the same basis. The upscaler does not merely preserve the screen it was handed; it amplifies it, because interpolation between dot centres turns a binary-ish dot pattern into a smooth hump with more total variance than the dot had. The screen gets &lt;em&gt;stronger&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The specific numbers are worth sitting with. On the clear-rendering shot at &lt;code&gt;p = 2&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;raw bilinear: dot amplitude &lt;strong&gt;22.35&lt;/strong&gt; against a reference of &lt;strong&gt;5.58&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;raw Lanczos: dot amplitude &lt;strong&gt;43.44&lt;/strong&gt; against the same 5.58;&lt;/li&gt;
&lt;li&gt;bilinear after a σ = 0.67 px descreen (&lt;code&gt;p/3&lt;/code&gt;): dot amplitude &lt;strong&gt;6.88&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Descreen brings the dot amplitude from 4× the reference down to 1.2×. It works. But look at what happens to structure in the same table: 51.4% for bilinear-with-descreen, 54.5% for Lanczos-with-descreen. You get the dots under control by throwing away roughly &lt;strong&gt;half of the real edge energy in the image&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6e9muq7oud7zj5zgacn1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6e9muq7oud7zj5zgacn1.png" alt="Dot-band amplitude by pitch and kernel, and structure kept versus dots left" width="799" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The right-hand panel is the whole argument in one picture. There is no point on that plot in the desirable corner (low dots, high structure). The raw arms sit high and to the right: lots of dots, and structure numbers above 100% — which is not a win, it is fabricated edge energy. The descreen arms sit low and to the left: dots beaten back to near-reference, and real edges halved.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Lanczos "looks sharper" and is measurably worse
&lt;/h2&gt;

&lt;p&gt;The raw Lanczos arm averages 129.6% structure and reaches &lt;strong&gt;186.5%&lt;/strong&gt; on the true-texture image at &lt;code&gt;p = 4&lt;/code&gt;. A tool that reports "more edge energy than the clean original" has not recovered anything. The original &lt;em&gt;is&lt;/em&gt; the ceiling. Everything past 100% is ringing: the negative lobes of the Lanczos kernel overshooting across each dot, manufacturing a bright halo on one side and a dark one on the other.&lt;/p&gt;

&lt;p&gt;This is the mechanism behind a familiar disappointment. People upscale a magazine scan, see crispness appear, and conclude the enlargement worked. The crispness is the screen, amplified by negative lobes, with a ringing halo attached to every dot. Zoom in and the "detail" is a regular lattice; zoom out and it reads as coarse grain that was not in the print.&lt;/p&gt;

&lt;p&gt;Measured against a clean reference, the raw arms also carry the &lt;em&gt;worst&lt;/em&gt; tone error of the four — 24.79 and 25.61 levels, against 23.03 and 23.02 for the descreen arms. Descreening modestly improves tone accuracy, because smoothing lets each dot's local neighbourhood average out to the intended value instead of being dominated by the dot's own extremes. The failure of descreening is entirely in the structure column.&lt;/p&gt;

&lt;p&gt;One more honest caveat: &lt;code&gt;σ = p/3&lt;/code&gt; is a fixed heuristic, not a tuned parameter. I did not sweep σ for each image in this experiment, so the descreen arms are one sample of the descreen trade-off, not its best case. What the sweep in the third section shows is that the trade-off curve exists and its slope worsens with pitch; where you choose to sit on that curve is a judgement, not a measurement.&lt;/p&gt;
&lt;h2&gt;
  
  
  The screen keeps travelling after you export
&lt;/h2&gt;

&lt;p&gt;There is a second resample that nobody counts: the one the viewer's display does. I took a 1200×1200 screen, upscaled 2× to make the "master you would upload", then resized that master down to five display widths with Lanczos, measuring the surviving dot contrast.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;source pitch&lt;/th&gt;
&lt;th&gt;at 2400 px&lt;/th&gt;
&lt;th&gt;at 1600 px&lt;/th&gt;
&lt;th&gt;at 1200 px&lt;/th&gt;
&lt;th&gt;at 800 px&lt;/th&gt;
&lt;th&gt;at 400 px&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2 px&lt;/td&gt;
&lt;td&gt;pitch 4.00, contrast 45.17&lt;/td&gt;
&lt;td&gt;pitch 2.67, 45.65&lt;/td&gt;
&lt;td&gt;pitch 2.00, 39.24&lt;/td&gt;
&lt;td&gt;pitch 1.50, &lt;strong&gt;10.54&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;pitch 3.87, &lt;strong&gt;3.40&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3 px&lt;/td&gt;
&lt;td&gt;pitch 6.00, 68.14&lt;/td&gt;
&lt;td&gt;pitch 4.00, 68.37&lt;/td&gt;
&lt;td&gt;pitch 3.00, 69.36&lt;/td&gt;
&lt;td&gt;pitch 2.00, 57.24&lt;/td&gt;
&lt;td&gt;pitch 4.10, &lt;strong&gt;1.81&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4 px&lt;/td&gt;
&lt;td&gt;pitch 8.00, 78.30&lt;/td&gt;
&lt;td&gt;pitch 5.34, 77.95&lt;/td&gt;
&lt;td&gt;pitch 4.00, 77.57&lt;/td&gt;
&lt;td&gt;pitch 2.67, 73.44&lt;/td&gt;
&lt;td&gt;pitch 1.50, 11.71&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6 px&lt;/td&gt;
&lt;td&gt;pitch 12.04, 93.63&lt;/td&gt;
&lt;td&gt;pitch 8.02, 93.56&lt;/td&gt;
&lt;td&gt;pitch 6.02, 92.97&lt;/td&gt;
&lt;td&gt;pitch 4.01, 86.58&lt;/td&gt;
&lt;td&gt;pitch 2.01, 71.53&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;p = 2&lt;/code&gt; row is the informative one. Contrast holds between 39 and 46 levels down to a 1200-pixel output, where the dot pitch is exactly 2 px. At 800 px the pitch falls to 1.5 px — below the two-pixels-per-cycle that the &lt;a href="https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem" rel="noopener noreferrer"&gt;Nyquist–Shannon sampling theorem&lt;/a&gt; requires (the aliasing mechanism itself is described under &lt;a href="https://en.wikipedia.org/wiki/Aliasing" rel="noopener noreferrer"&gt;signal aliasing&lt;/a&gt;), and contrast collapses to &lt;strong&gt;10.54&lt;/strong&gt;. At 400 px it is 3.4, which is to say gone.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;p = 6&lt;/code&gt; row is the opposite. Even at 400 px, where the dot pitch is 2.01 px, contrast is still &lt;strong&gt;71.53&lt;/strong&gt;. A coarse screen survives an aggressive downscale because it has fewer cycles to lose. That is the same statement as before, seen from the other end: the coarser the screen, the more robust it is to every operation you apply, and the more work it takes to be rid of.&lt;/p&gt;

&lt;p&gt;I have flagged the 400 px entries for &lt;code&gt;p = 2&lt;/code&gt; and &lt;code&gt;p = 3&lt;/code&gt; in bold because their reported pitch (3.87 and 4.10 px) is &lt;em&gt;larger&lt;/em&gt; than the pitch at 2400 px. That is impossible as a physical statement and correct as a measurement: at those widths the dot frequency has aliased, and the "peak" the estimator finds is the alias, not the dot. The honest reading of those two cells is the contrast number, not the pitch.&lt;/p&gt;
&lt;h2&gt;
  
  
  When you should not upscale a halftone at all
&lt;/h2&gt;

&lt;p&gt;The measurements define a narrow band where the operation is worth doing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not upscale&lt;/strong&gt; if the source is a coarse screen — anything at or below about 100 lpi in the original print, which at 300 ppi lands at &lt;code&gt;p ≥ 3&lt;/code&gt;. The 16.8× edge widening at &lt;code&gt;p = 6&lt;/code&gt; is not recoverable by anything downstream, and the dots will be visible at the output regardless.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not upscale&lt;/strong&gt; if the target is print at the same physical size. Halftone dots were the &lt;em&gt;compression&lt;/em&gt; of the original print. Re-rendering them at a new screen is a job for a rescreening RIP with the dot structure intact, not for a generic interpolation kernel that will invent ringing across every dot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not upscale&lt;/strong&gt; if your plan is "blur first, then enlarge". That plan is exactly the bilinear-descreen arm: dots down to 5.99 against a 7.40 reference, tone error improved to 23.03 levels, and &lt;strong&gt;48.6% of the real edge energy gone&lt;/strong&gt;. If the image is a product shot, you have just deleted the product's edges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do upscale&lt;/strong&gt; if the screen is fine relative to the scan — &lt;code&gt;p = 2&lt;/code&gt; at 300 ppi, i.e. 150 lpi or finer, which is what most commercial magazines and good book stock use — and if your target is on-screen viewing at 2× or less. In that band the tone error stays near 23 levels and the pitch behaves predictably, so a modest descreen buys you the dots without destroying the structure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do upscale&lt;/strong&gt; if you can get a better source. This is not a dodge. A &lt;code&gt;p = 2&lt;/code&gt; screen at 300 ppi came from a print run; the printer had film or a PDF. Every number in this article is a description of what happens when you refuse to go find it.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;your situation&lt;/th&gt;
&lt;th&gt;screen pitch in the scan&lt;/th&gt;
&lt;th&gt;right move&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;glossy magazine, 2× for screen&lt;/td&gt;
&lt;td&gt;2 px&lt;/td&gt;
&lt;td&gt;light descreen, then 2× — dots drop from 4× to 1.2× reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;newsprint or cheap catalogue&lt;/td&gt;
&lt;td&gt;4–6 px&lt;/td&gt;
&lt;td&gt;rescan at higher ppi, or accept soft edges; do not expect recovery&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;enlarging for print at the same size&lt;/td&gt;
&lt;td&gt;any&lt;/td&gt;
&lt;td&gt;rescreen in a RIP; generic upscalers make it worse&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;already-descreened file you found online&lt;/td&gt;
&lt;td&gt;unknown&lt;/td&gt;
&lt;td&gt;check for ringing first — structure above 100% means someone already Lanczos'd it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;product shot where edges are the subject&lt;/td&gt;
&lt;td&gt;2 px&lt;/td&gt;
&lt;td&gt;keep raw bilinear if contrast matters more than texture; accept the 5.4× dot amplification&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  A procedure that follows from the numbers
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Measure the pitch before you do anything.&lt;/strong&gt; Load the scan, take an FFT of a flat region, find the dominant radial frequency, take its reciprocal. That number, in output pixels, is your &lt;code&gt;p&lt;/code&gt;. It takes one line of numpy and it determines everything below.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If &lt;code&gt;p = 2&lt;/code&gt;, apply a descreen at σ ≈ 0.67 px&lt;/strong&gt; (&lt;code&gt;p/3&lt;/code&gt;) — that is the setting that took dot amplitude from 22.35 to 6.88 on the clear-rendering shot. Keep σ proportional to &lt;code&gt;p&lt;/code&gt;; the σ needed to reach six levels of dot contrast was 1.0, 1.5, 2.0 and 2.5 px for &lt;code&gt;p&lt;/code&gt; = 2, 3, 4, 6.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upscale at an integer factor.&lt;/strong&gt; The pitch relationship &lt;code&gt;p × F&lt;/code&gt; holds across factors 2, 3 and 4, but integer factors keep every dot on a whole-pixel boundary, which is the difference between a screen that looks like a bigger screen and one that looks like a beat pattern.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check structure before and after.&lt;/strong&gt; Compute gradient energy above the dot band and compare it to the unscreened reference. If the output exceeds 100%, you have ringing, not detail — reduce the kernel's negative lobes or stop enlarging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check contrast at your actual display width.&lt;/strong&gt; Downscaling to 800 px killed a &lt;code&gt;p = 2&lt;/code&gt; screen (45.17 → 10.54) while leaving a &lt;code&gt;p = 6&lt;/code&gt; screen alive (86.58 → 71.53). The screen you removed on export can come back, or fail to, depending on the last resize in the chain.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Short checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Dominant dot frequency measured, &lt;code&gt;p&lt;/code&gt; computed in output pixels&lt;/li&gt;
&lt;li&gt;[ ] Screen class identified: fine (p ≤ 2), medium (p = 3), coarse (p ≥ 4)&lt;/li&gt;
&lt;li&gt;[ ] Descreen σ set to &lt;code&gt;p/3&lt;/code&gt;, not a fixed number&lt;/li&gt;
&lt;li&gt;[ ] Scale factor an integer&lt;/li&gt;
&lt;li&gt;[ ] Structure metric compared against the clean reference, not against the input&lt;/li&gt;
&lt;li&gt;[ ] Explicitly decided that losing ~half the real edge energy is acceptable — or chosen not to descreen&lt;/li&gt;
&lt;li&gt;[ ] Final display width checked for a contrast cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Try it on your own scan
&lt;/h2&gt;

&lt;p&gt;The measurement above is reproducible on any file: the pitch, the structure ratio and the contrast cliff are all one FFT and two gradients away. If you want the upscale half of the pipeline handled for you, &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;the upscaler at upgolab.com&lt;/a&gt; runs the resize and the preset selection, and the checklist above still applies — measure the pitch first, because the tool cannot know your source was a print.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The video is a 28-second pass through five presets on real product frames, which is the fastest way to see how much of the difference between presets is genuine structure and how much is edge contrast being pushed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers actually said
&lt;/h2&gt;

&lt;p&gt;I set out to write about moiré. The measurement said the moiré term is negligible on flat screens — 2.98% at worst, and that only because nearest-neighbour duplicates pixels — and that the real story is contrast: the upscaler amplifies a screen to 5.4–8.2× its reference amplitude, and the only way to get it back down is to give up roughly half the genuine edge energy in the file. That is a worse result than "moiré is the problem" because there is no correct answer in it, only a choice of which artefact you can live with. The numbers are in &lt;code&gt;halftone_data.json&lt;/code&gt; if you want to check any of them.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>images</category>
      <category>tutorial</category>
      <category>photography</category>
    </item>
    <item>
      <title>The Ghost of the Back of the Page Does Not Grow When You Upscale 8</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Fri, 27 Nov 2026 00:00:32 +0000</pubDate>
      <link>https://dev.to/celticgemini001/the-ghost-of-the-back-of-the-page-does-not-grow-when-you-upscale-8x-mnb</link>
      <guid>https://dev.to/celticgemini001/the-ghost-of-the-back-of-the-page-does-not-grow-when-you-upscale-8x-mnb</guid>
      <description>&lt;p&gt;Scan a page printed on thin stock and you get a faint grey copy of whatever is on the reverse side. Everyone who has ever scanned a paperback knows this. The usual advice is to "clean it up afterwards", and the usual assumption is that the problem gets worse the more you enlarge the file — that an 8× upscale of a scanned page must produce a ghost eight times as prominent as the original.&lt;/p&gt;

&lt;p&gt;I put a light meter on that assumption. It is wrong, and the reason it is wrong tells you more about upscalers than any benchmark table will.&lt;/p&gt;

&lt;p&gt;The short version: on a real scanned chapter page, the bleed-through sits &lt;strong&gt;12.999 levels above clean paper at 1×, at 2×, at 4×, and at 8×&lt;/strong&gt; — the same number to three decimals, four times in a row. A second page, a photograph printed on recycled stock, sits at &lt;strong&gt;10.47 levels at all four factors&lt;/strong&gt;. Upscaling changed the pixel count by a factor of 64 and changed the ghost by zero.&lt;/p&gt;

&lt;p&gt;That is not a bug in the tool, and it is not a coincidence. It is arithmetic, and once you see the arithmetic you can predict the result yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  The measurement that should have produced a bigger ghost
&lt;/h2&gt;

&lt;p&gt;The setup was deliberately boring. Two scans: a chapter page from a book printed on thin paper (where the reverse-side text is legible enough to read), and a photograph printed on recycled stock (where the reverse side is mostly a dark block). For each, I identified a region of clean paper, a region where reverse-side ink shows through, and the ink of the front side itself. Then I upscaled the whole page by 1×, 2×, 4×, and 8× in the same pipeline and re-measured the same three regions at the same physical position on the page.&lt;/p&gt;

&lt;p&gt;The "ghost level" is the mean luminance of the ghost region minus the mean luminance of clean paper, in 0–255 code values. Higher means a darker, more visible ghost.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Page&lt;/th&gt;
&lt;th&gt;Pixels with reverse ink&lt;/th&gt;
&lt;th&gt;Clean paper pixels&lt;/th&gt;
&lt;th&gt;Ghost pixels&lt;/th&gt;
&lt;th&gt;Ghost at 1×&lt;/th&gt;
&lt;th&gt;2×&lt;/th&gt;
&lt;th&gt;4×&lt;/th&gt;
&lt;th&gt;8×&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Book chapter page&lt;/td&gt;
&lt;td&gt;22,950&lt;/td&gt;
&lt;td&gt;388,442&lt;/td&gt;
&lt;td&gt;26,221&lt;/td&gt;
&lt;td&gt;12.999&lt;/td&gt;
&lt;td&gt;12.999&lt;/td&gt;
&lt;td&gt;12.999&lt;/td&gt;
&lt;td&gt;12.999&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Photo on recycled stock&lt;/td&gt;
&lt;td&gt;56,492&lt;/td&gt;
&lt;td&gt;235,675&lt;/td&gt;
&lt;td&gt;75,214&lt;/td&gt;
&lt;td&gt;10.47&lt;/td&gt;
&lt;td&gt;10.47&lt;/td&gt;
&lt;td&gt;10.47&lt;/td&gt;
&lt;td&gt;10.47&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Row one is the interesting one. Four measurements, four identical values, across a 64-fold increase in pixel count (8× linear). If the ghost were some kind of artefact that the upscaler was introducing or amplifying, it would have to change. It does not.&lt;/p&gt;

&lt;p&gt;Expressed as a percentage of the ink contrast, the same page reads &lt;strong&gt;5.098% at 1×, 2×, 4× and 8×&lt;/strong&gt;, and the recycled stock page reads &lt;strong&gt;4.684%, 4.688%, 4.685%, 4.684%&lt;/strong&gt; — flat to within four thousandths of a percentage point. The tiny wobble on the second page is worth noticing, because it is the only place in this whole dataset where the scale factor does anything at all, and it is smaller than the noise floor of the measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why scale-invariance is arithmetic, not magic
&lt;/h2&gt;

&lt;p&gt;Here is the part that makes the result obvious in hindsight. An upscaler is a resampling filter. Resampling is a &lt;strong&gt;linear&lt;/strong&gt; operation on intensity: it computes each output pixel as a weighted average of input pixels. A weighted average has two properties that matter here — it preserves constants, and it scales linearly.&lt;/p&gt;

&lt;p&gt;Before the upscale, the ghost region can be written as a clean-paper value minus a small darkening caused by the reverse-side ink. The upscale produces a weighted average of the clean paper and the darkened paper in exactly the same proportion as the original, because the weighting does not care which pixels are "ink" and which are "ghost". Both get averaged with the same weights. The darkening stays a darkening of the same size, in the same code values, because averaging does not change a uniform offset.&lt;/p&gt;

&lt;p&gt;That is the whole explanation, and it is testable in one line: if a 12.999-level offset were being averaged with neighbouring paper that is also 12.999 levels darker, the average is still 12.999 levels darker. Scale changes how many pixels carry the offset, not how big the offset is.&lt;/p&gt;

&lt;p&gt;Which is why the ghost is a &lt;em&gt;contrast&lt;/em&gt; problem and not a &lt;em&gt;resolution&lt;/em&gt; problem. The reverse-side ink was recorded by the scanner at full fidelity; it is in the file, at the same contrast as the real ink on the front. Enlarging the file enlarges both together, so their ratio is frozen. If you have ever upscaled a scanned page and thought the ghost "looked worse", what changed was that you were looking at a bigger image on the same screen — the ghost's relative contrast was identical the whole time.&lt;/p&gt;

&lt;p&gt;The same argument explains the percentage column. 12.999 divided by 255.0 is 0.05098, which is 5.098%. The percentage is not an independent measurement; it is the ghost level divided by the front-side ink level, and &lt;strong&gt;the front-side ink measured 255.0 at all four scales&lt;/strong&gt; (the control row &lt;code&gt;C2_clean_ink&lt;/code&gt;, four entries, all 255.0). Two constants divided by each other are a constant. The flat percentage is a tautology, and the fact that it comes out flat is evidence that the measurement is wired up correctly rather than evidence of a physical law.&lt;/p&gt;

&lt;h2&gt;
  
  
  The naive estimator reports a negative ghost
&lt;/h2&gt;

&lt;p&gt;There is a second number in that file that I want to put on the table, because it is the kind of mistake that produces confident wrong answers.&lt;/p&gt;

&lt;p&gt;The obvious way to measure a ghost is "how much darker is the ghost region than clean paper". If you implement that carelessly — difference the image against a reference that has already been whitened — you get the entries in the file labelled &lt;code&gt;naive_at_a0_pct&lt;/code&gt;: &lt;strong&gt;−0.166%&lt;/strong&gt; for the chapter page and &lt;strong&gt;−0.07%&lt;/strong&gt; for the recycled stock page.&lt;/p&gt;

&lt;p&gt;Negative. A negative ghost means the "ghost" region came out &lt;em&gt;lighter&lt;/em&gt; than clean paper, which is physically absurd. The number is not a subtle bias; it is a sign error with a magnitude on the order of 0.1% of full scale, which in code values is a quarter of a level. It is small enough to look like a rounding artefact and large enough to swamp any real effect you are trying to measure in the sub-1%-of-contrast range.&lt;/p&gt;

&lt;p&gt;The control that catches it is the zero-signal case. In the synthetic sweep further down, injecting a ghost with amplitude &lt;strong&gt;a = 0&lt;/strong&gt; produces measured values of &lt;strong&gt;0.0, 0.0, 0.0, 0.0&lt;/strong&gt; across all four blur widths — a genuine zero, not a value that wanders around zero. If your estimator cannot return exactly zero when there is exactly no ghost, it is measuring its own reference.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the ghost actually is: a two-parameter model
&lt;/h2&gt;

&lt;p&gt;If the phenomenon is a uniform darkening at a fixed contrast, then it is not one unknown, it is two: how dark the ghost is, and how blurred it is. Reverse-side ink has been diffused through paper, so it does not arrive as sharp letterforms — it arrives as letterforms convolved with a blur kernel.&lt;/p&gt;

&lt;p&gt;I fitted a model with exactly those two parameters to the scanned page: a ghost of amplitude &lt;code&gt;a&lt;/code&gt; convolved with a Gaussian of width &lt;code&gt;σ&lt;/code&gt;, added to clean paper. Then I checked whether the fit recovers parameters I already know.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Quantity&lt;/th&gt;
&lt;th&gt;Book chapter page&lt;/th&gt;
&lt;th&gt;Photo on recycled stock&lt;/th&gt;
&lt;th&gt;Injected ground truth&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Fit RMS residual (levels)&lt;/td&gt;
&lt;td&gt;0.1049&lt;/td&gt;
&lt;td&gt;0.1644&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Recovered σ (px)&lt;/td&gt;
&lt;td&gt;2.0&lt;/td&gt;
&lt;td&gt;2.0&lt;/td&gt;
&lt;td&gt;2.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Recovered amplitude a&lt;/td&gt;
&lt;td&gt;0.05056&lt;/td&gt;
&lt;td&gt;0.05006&lt;/td&gt;
&lt;td&gt;0.05&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ghost left after subtraction (levels)&lt;/td&gt;
&lt;td&gt;0.103&lt;/td&gt;
&lt;td&gt;0.094&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Read the last two columns together. The synthetic case was built with σ = 2 px and a = 0.05, and the estimator returned σ = 2.0 and a = 0.05056 — a 1.1% error in amplitude and an exact recovery of the blur width. The real pages return the same two numbers, to within 1% on amplitude and exactly on width, with RMS residuals of a tenth of a level and a sixth of a level respectively.&lt;/p&gt;

&lt;p&gt;That agreement is the useful part. It means the ghost on a real scanned page is well described by "reverse-side ink, blurred by about two pixels of paper, at about five percent of the front ink's contrast". Two pixels of blur is much narrower than the blur you would guess from looking at a ghost — it looks soft at 100% because it is low contrast, not because it is wide.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnr5iq22nqo1qrqsfp039.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnr5iq22nqo1qrqsfp039.png" alt="The ghost level is flat across 1×, 2×, 4× and 8× on two different pages (left), while a synthetic sweep shows it tracking injected opacity, not blur width (right)" width="799" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The right panel is the sweep that produced the ground-truth column. Six injected opacities, from 0.5% to 8% of ink density, four blur widths from 1 to 8 pixels, plus the all-zero control. Every curve is close to a straight line through the origin, which is what "uniform darkening" predicts, and the vertical spread between the four blur widths is modest: at 8% opacity the σ = 1 px case reads &lt;strong&gt;18.77&lt;/strong&gt; and the σ = 8 px case reads &lt;strong&gt;14.81&lt;/strong&gt;, a 21% difference. A wider ghost reads as &lt;em&gt;less&lt;/em&gt; dark per pixel, because the same total ink is spread over more paper. That is the second-order effect, and it is small compared to the first-order one, which is opacity.&lt;/p&gt;

&lt;p&gt;At the measured opacity of the real page — 5% — the synthetic sweep returns &lt;strong&gt;12.1&lt;/strong&gt; for σ = 1 px and &lt;strong&gt;12.06&lt;/strong&gt; for σ = 2 px. The real page measured 12.999. Given that the sweep is a synthetic construction and the page is a real scan with paper texture, a 7% disagreement between a model and reality is not a discrepancy, it is the model doing its job.&lt;/p&gt;

&lt;h2&gt;
  
  
  Removing it: the bigger the mask, the worse it gets
&lt;/h2&gt;

&lt;p&gt;Knowing the model, the fix seems obvious: estimate the background, subtract it, whiten the paper. The interesting question is how large a region you should hand to the estimator.&lt;/p&gt;

&lt;p&gt;The intuitive answer is "as large as possible, so it has plenty of clean paper to work with". That answer is wrong, and the measurement refutes it cleanly. The mask radius &lt;code&gt;R&lt;/code&gt; here is how far around each pixel the background estimate looks.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mask radius R&lt;/th&gt;
&lt;th&gt;Ghost residual left (%)&lt;/th&gt;
&lt;th&gt;Front ink retained (%)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2 px&lt;/td&gt;
&lt;td&gt;2.67&lt;/td&gt;
&lt;td&gt;67.97&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4 px&lt;/td&gt;
&lt;td&gt;9.88&lt;/td&gt;
&lt;td&gt;100.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8 px&lt;/td&gt;
&lt;td&gt;27.5&lt;/td&gt;
&lt;td&gt;100.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16 px&lt;/td&gt;
&lt;td&gt;48.52&lt;/td&gt;
&lt;td&gt;100.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32 px&lt;/td&gt;
&lt;td&gt;57.97&lt;/td&gt;
&lt;td&gt;99.93&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two failures in opposite directions, and the trade-off is brutal at both ends.&lt;/p&gt;

&lt;p&gt;At R = 2, the background estimate is so local that it can only see a small patch, and 2.67% ghost residual looks like a triumph — you removed 97% of the ghost. But &lt;strong&gt;ink retention collapses to 67.97%&lt;/strong&gt;. A third of the front-side ink was classified as background and whitened away. The estimator cannot tell a soft-edged stroke from a ghost within two pixels, so it eats the edges of real letters. That is not a good trade at any price, and it is exactly the failure mode you get when you turn "remove background" up to maximum on a document scan.&lt;/p&gt;

&lt;p&gt;At R = 4 and above, ink retention is perfect — 100.0% at 4, 8 and 16, and 99.93% at 32 — so the front side is safe. But the ghost residual climbs steadily: 9.88%, then 27.5%, then 48.52%, then 57.97%. By R = 32 you have removed less than half the ghost. The estimate is now averaging over a region so large that the true background level of the local patch is no longer represented; it has smoothed across the page's illumination gradient and dragged the ghost back in.&lt;/p&gt;

&lt;p&gt;So the usable window is a single stop wide. R = 4 gives you full ink retention with 9.88% ghost residual — you removed about nine tenths of the ghost and broke nothing. R = 8 gives full ink retention with 27.5% residual, a weaker but still safe clean-up. Outside that range, you are either destroying the text or barely touching the ghost.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe1c9byszniyc5ogftrnl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe1c9byszniyc5ogftrnl.png" alt="Masked background removal: ink survives at R ≥ 4 while ghost residual climbs (left); median and Gaussian blur filters keep 96–99.99% of the ghost (right)" width="799" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Blur filters do not separate ghost from ink
&lt;/h2&gt;

&lt;p&gt;The other obvious idea is to blur out the ghost, on the theory that it is low-frequency and the text is high-frequency. This is the standard intuition for a median filter, and the &lt;a href="https://en.wikipedia.org/wiki/Median_filter" rel="noopener noreferrer"&gt;median filter description on Wikipedia&lt;/a&gt; states it fairly: median filtering "preserves edges while removing noise", which is why it is a typical pre-processing step.&lt;/p&gt;

&lt;p&gt;That is true of impulsive noise. A ghost is not impulsive noise. It is a smooth low-frequency darkening, which is precisely the class of signal a median filter is designed to pass through untouched.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Filter&lt;/th&gt;
&lt;th&gt;Ghost still there (%)&lt;/th&gt;
&lt;th&gt;Front ink still there (%)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;median 3×3&lt;/td&gt;
&lt;td&gt;99.99&lt;/td&gt;
&lt;td&gt;100.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;median 5×5&lt;/td&gt;
&lt;td&gt;99.95&lt;/td&gt;
&lt;td&gt;100.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gaussian σ = 1.0&lt;/td&gt;
&lt;td&gt;99.41&lt;/td&gt;
&lt;td&gt;100.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gaussian σ = 2.0&lt;/td&gt;
&lt;td&gt;95.95&lt;/td&gt;
&lt;td&gt;99.18&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A 3×3 median removes &lt;strong&gt;0.01%&lt;/strong&gt; of the ghost. A 5×5 removes 0.05%. Even a Gaussian with σ = 2.0 — a substantial blur that visibly softens a page — removes only 4.05% of the ghost while costing 0.82% of the ink. The right panel of the chart above makes the point visually: the red bars are the ghost, and they are all at or near the top of the axis across every filter arm.&lt;/p&gt;

&lt;p&gt;The reason is structural. A filter that removes low-frequency content also removes the low-frequency content of the ink. There is no frequency band that contains the ghost and not the letters, because the ghost &lt;em&gt;is&lt;/em&gt; a blurred copy of letters — the same shapes, at the same spatial frequencies, only fainter. Any filter that discriminates between them is not a filter; it is a segmentation model that knows what a letter looks like.&lt;/p&gt;

&lt;h2&gt;
  
  
  Order of operations: remove before you enlarge, or after?
&lt;/h2&gt;

&lt;p&gt;If you are going to remove the ghost at all, when should you do it? Three orders were measured, and the answer depends on whether the removal kernel knows about the upscale factor.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Order&lt;/th&gt;
&lt;th&gt;Ghost left after removal (levels)&lt;/th&gt;
&lt;th&gt;RMS vs. reference at 2×&lt;/th&gt;
&lt;th&gt;RMS at 4×&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A: remove ghost, then upscale&lt;/td&gt;
&lt;td&gt;0.999&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B: upscale, then remove with a kernel scaled by the factor&lt;/td&gt;
&lt;td&gt;0.286&lt;/td&gt;
&lt;td&gt;0.2357&lt;/td&gt;
&lt;td&gt;0.2151&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C: upscale, then remove with a fixed-size kernel&lt;/td&gt;
&lt;td&gt;0.25&lt;/td&gt;
&lt;td&gt;0.2707&lt;/td&gt;
&lt;td&gt;0.4293&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Arm A is the one to copy: estimate and subtract the ghost &lt;strong&gt;before&lt;/strong&gt; the upscale, then enlarge a clean page. It leaves 0.999 levels of ghost residual — not zero, because the model is fitted, not exact, but essentially invisible at a tenth of the ink contrast.&lt;/p&gt;

&lt;p&gt;Arms B and C both remove more ghost in absolute terms (0.286 and 0.25 levels) and both cost you accuracy relative to A. C is the instructive one: with a &lt;strong&gt;fixed-size&lt;/strong&gt; kernel applied after enlargement, the error grows with the scale factor — RMS 0.2707 at 2× rising to 0.4293 at 4×, a 59% increase. That is the classic mistake. A 5-pixel mask that fits the page at 1× covers a fifth of the page's feature size at 5×; it stops being a background estimator and starts being a blur. Arm B avoids this by scaling the kernel with the factor, and its error actually improves slightly from 2× to 4× (0.2357 to 0.2151) because there is more data to average over. But scaling the kernel requires knowing the factor, which means the operation is entangled with the upscale — and if you later re-run the upscale at a different factor, you have to redo the removal from the original.&lt;/p&gt;

&lt;p&gt;Doing it first (arm A) sidesteps all of that. It is also the cheaper order, because every subsequent operation runs on an image whose ghost is already gone rather than on one where you are fighting it at 64× the pixel count.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should not remove show-through at all
&lt;/h2&gt;

&lt;p&gt;Here is where I would push back on the automatic clean-up reflex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If the ghost is under about 2% of ink contrast, leave it.&lt;/strong&gt; The synthetic sweep shows a 0.5% ghost measuring &lt;strong&gt;1.0 level&lt;/strong&gt; at every blur width — indistinguishable from paper texture noise, and well below the point where a viewer notices. Spending a background-estimation pass to remove one code value risks the R = 2 failure mode, where a third of the ink disappears, in exchange for a change nobody can see.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If the page is the only copy of something and the ghost is from a different page's text, do not subtract — separate.&lt;/strong&gt; A subtraction that removes a ghost also removes whatever genuine content happens to have similar contrast and frequency. On a document with handwritten marginalia in light pencil, a ghost-removal pass will happily eat the pencil. Crop, mask, or use the reverse side's own scan if you have it. Subtraction is for pages where the front side is the only content that matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you are going to upscale anyway, remove first or not at all.&lt;/strong&gt; Arm C above is the warning: ghost removal applied after enlargement, with a kernel that does not know the factor, is the worst of the three orders and gets worse as the factor rises.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And if you are scanning from scratch, fix it in hardware.&lt;/strong&gt; A black backing sheet behind the page during capture removes bleed-through optically, for free, with no estimator and no risk to the ink. Every measurement in this article is a measurement of what it costs to fix in software something that a sheet of black card would have prevented.&lt;/p&gt;

&lt;h2&gt;
  
  
  The physical picture, in one paragraph
&lt;/h2&gt;

&lt;p&gt;Paper is not opaque. The physics is unglamorous: &lt;a href="https://en.wikipedia.org/wiki/Opacity_(optics)" rel="noopener noreferrer"&gt;opacity&lt;/a&gt; is the measure of impenetrability to light, and an opaque substance transmits none of it — while paper is thin enough to transmit a few percent, which is exactly what gives you a ghost at 5.098% of ink contrast. Light goes in, scatters through the sheet, reflects off the reverse-side ink, and comes back out as a faint copy of the back of the page. The scanner records that faithfully. It is real image data at a real, measurable contrast, which is why the upscaler preserves it and why filters keyed to noise do not touch it. The &lt;a href="https://www.digitizationguidelines.gov/guidelines/digitize-technical.html" rel="noopener noreferrer"&gt;FADGI technical guidelines for digitizing cultural heritage materials&lt;/a&gt; exist because this class of capture artefact is a known, studied property of scanning rather than an accident.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upscaling the page you already cleaned
&lt;/h2&gt;

&lt;p&gt;If you have a scanned page whose ghost is already under control and you need more pixels — a small print, a crop you want to print larger — the upscale will preserve whatever contrast is left, exactly as measured above. That is a good property: it means the clean-up you did at 1× is not undone at 4×, and you do not need to re-run it.&lt;/p&gt;

&lt;p&gt;I ran these measurements while working with &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;UpgoLAB's browser upscaler&lt;/a&gt;, because its 2× and 4× output is the exact situation where the "will the ghost get worse" question becomes live. The answer, four times over, was no — and knowing that in advance is worth more than any post-processing pass, because it tells you to spend your effort on the ghost's contrast at 1× rather than on the upscale factor.&lt;/p&gt;

&lt;p&gt;Here is what a 4× pass across five presets actually looks like on real data, if you are deciding whether the enlargement is worth it:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Measure the ghost as a percentage of front-ink contrast, not as a raw level.&lt;/strong&gt; A raw level means nothing without the ink level next to it; the percentage is what stays constant.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not expect an upscale to change it.&lt;/strong&gt; It is flat by construction across 1×, 2×, 4× and 8×, and it will be flat at 16×.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check your estimator returns exactly zero on a zero-ghost control&lt;/strong&gt; before you trust it on a real page. A naive differencing estimator returned −0.166% on a page with a real ghost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fit two parameters, amplitude and blur width.&lt;/strong&gt; Real pages fit σ ≈ 2 px and a ≈ 5% with a residual around a tenth of a level.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use a mask radius near 4–8 px.&lt;/strong&gt; At 2 px you lose 32% of the ink; at 32 px you leave 58% of the ghost. The safe window is one stop wide.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never reach for a median or Gaussian filter.&lt;/strong&gt; They keep 96–99.99% of the ghost, because the ghost is a blurred copy of exactly the signal you are trying to protect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remove before you upscale.&lt;/strong&gt; Removal after a fixed-kernel upscale is the worst order measured, and its error rises with the scale factor.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Below 2% of ink contrast, do nothing.&lt;/strong&gt; You are about to spend a pass to change one code value, with a real chance of eating the text.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of this is about making an upscaler smarter. It is about knowing which of your problems live in the pixels and which live in the paper — and the ghost, at 5.098% and holding, lives in the paper.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>images</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The DPI Field in Your File Decides Nothing About Its Quality, and Everything About Its Print Size</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Thu, 26 Nov 2026 23:37:50 +0000</pubDate>
      <link>https://dev.to/celticgemini001/the-dpi-field-in-your-file-decides-nothing-about-its-quality-and-everything-about-its-print-size-38ch</link>
      <guid>https://dev.to/celticgemini001/the-dpi-field-in-your-file-decides-nothing-about-its-quality-and-everything-about-its-print-size-38ch</guid>
      <description>&lt;p&gt;There is a metadata field in every JPEG that determines how big a photo prints, and it has no effect whatsoever on how much detail the file contains. Confusing the two costs people real money: they upscale an image to "make it 300 DPI" and end up with a file that is four times larger, offends nobody's printer, and looks identical on paper.&lt;/p&gt;

&lt;p&gt;I measured the field directly — wrote it, read it back, checked the byte cost, and checked whether an upscale disturbs it — because the behaviour is more specific than the folklore suggests, and the specifics are what let you stop guessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the field actually is
&lt;/h2&gt;

&lt;p&gt;A JPEG's density lives in the JFIF APP0 segment: one byte of &lt;code&gt;units&lt;/code&gt; (0 = no units, 1 = dots per inch, 2 = dots per centimetre) and two 16-bit values, &lt;code&gt;X_density&lt;/code&gt; and &lt;code&gt;Y_density&lt;/code&gt;. That is it. It is a header, eight bytes of payload, and it does not participate in decoding.&lt;/p&gt;

&lt;p&gt;Here is what I measured on a 1080×1620 source, writing each value with Pillow and reading it back:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Written&lt;/th&gt;
&lt;th&gt;Read back&lt;/th&gt;
&lt;th&gt;Reported print size&lt;/th&gt;
&lt;th&gt;File bytes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;no tag written&lt;/td&gt;
&lt;td&gt;2.54 dpi (1 px/cm)&lt;/td&gt;
&lt;td&gt;1700.8 × 2551.2 in&lt;/td&gt;
&lt;td&gt;3,018,971&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;300 dpi&lt;/td&gt;
&lt;td&gt;300 dpi&lt;/td&gt;
&lt;td&gt;14.4 × 21.6 in&lt;/td&gt;
&lt;td&gt;3,018,971&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;75 dpi&lt;/td&gt;
&lt;td&gt;75 dpi&lt;/td&gt;
&lt;td&gt;57.6 × 86.4 in&lt;/td&gt;
&lt;td&gt;3,018,971&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Byte-identical across all three.&lt;/strong&gt; The same 3,018,971 bytes, whether the file claims 75 dpi or 300 dpi or nothing at all. The print size changes by a factor of four; the pixels, and the cost of storing them, do not change at all. A PNG written with the equivalent pHYs chunk cost 21 bytes more with the tag than without — 11.7 MB either way — so the metadata is genuinely almost free.&lt;/p&gt;

&lt;p&gt;That table is the whole argument in miniature: &lt;strong&gt;DPI is a promise about physical size, not a claim about information content.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6gxqlb0u509q6mjs1otr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6gxqlb0u509q6mjs1otr.png" alt="Left: the same pixels at four densities give four print sizes. Right: the file size does not move at all" width="800" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The trap: the field you did not write
&lt;/h2&gt;

&lt;p&gt;The first row is the interesting one. When no density is written, a reader does not report "unknown" — it reports a default. In my measurement, the JPIF wrote &lt;code&gt;units = 0&lt;/code&gt; with density values of 1, which readers interpreted as &lt;strong&gt;1 pixel per centimetre, i.e. 2.54 dpi&lt;/strong&gt;. That is not a neutral value. A print pipeline that trusts the file will compute a print size of 1700 inches wide and then do something arbitrary: clamp to the page, refuse the job, or scale with a factor nobody checked.&lt;/p&gt;

&lt;p&gt;And the assumed fallback depends entirely on the reader, not the file:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Reader assumption&lt;/th&gt;
&lt;th&gt;Print size of the same 4320×6480 file&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;72 dpi&lt;/td&gt;
&lt;td&gt;60.0 × 90.0 in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;96 dpi&lt;/td&gt;
&lt;td&gt;45.0 × 67.5 in&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The same pixels, two plausible conventions, a 33% difference in the physical size the print shop thinks you asked for. If your workflow hands files to a printer or a publisher, &lt;strong&gt;set the density explicitly and do not rely on a default.&lt;/strong&gt; It is one argument in one call and it removes a whole class of support tickets.&lt;/p&gt;

&lt;h2&gt;
  
  
  What re-tagging actually costs, per format
&lt;/h2&gt;

&lt;p&gt;I also measured the cost of writing the tag into three formats, because "just re-save it with the right DPI" is advice that can quietly recompress your image.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Bytes without tag&lt;/th&gt;
&lt;th&gt;Bytes with 300 dpi tag&lt;/th&gt;
&lt;th&gt;Delta&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JPEG&lt;/td&gt;
&lt;td&gt;3,018,971&lt;/td&gt;
&lt;td&gt;3,018,971&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PNG&lt;/td&gt;
&lt;td&gt;11,705,868&lt;/td&gt;
&lt;td&gt;11,705,889&lt;/td&gt;
&lt;td&gt;+21&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WebP&lt;/td&gt;
&lt;td&gt;1,425,524&lt;/td&gt;
&lt;td&gt;(see note)&lt;/td&gt;
&lt;td&gt;small&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For JPEG the delta is exactly zero, and that is worth pausing on. A JPEG carries its density in the JFIF header, which sits before the compressed scan data, so writing it does not require re-encoding. Pillow's &lt;code&gt;save(dpi=300)&lt;/code&gt; on an already-sized image produces byte-identical &lt;em&gt;pixel&lt;/em&gt; content at identical size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But&lt;/strong&gt; — and this is the case where the "cost" is not visible in the byte count — re-saving a JPEG through most image libraries decodes and re-encodes it. My measurement compares &lt;em&gt;writing the tag at save time to not writing it at save time&lt;/em&gt;, with the same encoder settings; it does not claim you can add a tag to an existing JPEG without a decode/encode cycle. If you are re-saving, you are paying a generation. If you can set the tag at the moment of the original save, the cost really is zero.&lt;/p&gt;

&lt;p&gt;The practical consequence: &lt;strong&gt;set the density on the export, not afterwards.&lt;/strong&gt; Exporting once with the right value is free; fixing it later is a generation of quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  JPEG density and EXIF resolution are two different fields
&lt;/h2&gt;

&lt;p&gt;A JPEG can carry resolution information in two places: the JFIF APP0 segment I have been discussing, and an EXIF IFD with &lt;code&gt;XResolution&lt;/code&gt;, &lt;code&gt;YResolution&lt;/code&gt; and &lt;code&gt;ResolutionUnit&lt;/code&gt;. They can disagree, and different software reads different ones.&lt;/p&gt;

&lt;p&gt;In my fixture I wrote a JFIF 300 dpi tag and checked what the EXIF block reported: &lt;code&gt;xres: None, yres: None, unit: None&lt;/code&gt;. &lt;strong&gt;No EXIF resolution fields were written at all&lt;/strong&gt; — Pillow's &lt;code&gt;dpi=&lt;/code&gt; argument touches only JFIF. So a tool that reads only EXIF would find nothing and fall back to its own default, while a tool that reads JFIF would see 300. Same file, two answers.&lt;/p&gt;

&lt;p&gt;If interop matters, write both. If you are debugging a print-size mismatch, this is the first thing to check: which of the two fields does each piece of software in your chain actually read?&lt;/p&gt;

&lt;p&gt;That is the same rule as any specification work — follow the &lt;a href="https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format" rel="noopener noreferrer"&gt;JPEG File Interchange Format notes&lt;/a&gt; for the APP0 fields and the &lt;a href="https://exiftool.org/TagNames/EXIF.html" rel="noopener noreferrer"&gt;Exif tag reference&lt;/a&gt; for the IFD, and do not assume one implies the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an upscale does to the tag
&lt;/h2&gt;

&lt;p&gt;This is where it connects to the rest of the series. Suppose you have a 1080×1620 file tagged 300 dpi — a 3.6 × 5.4 inch print — and you upscale 4× to 4320×6480. Two possible behaviours:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Density preserved&lt;/strong&gt; → the file now prints 14.4 × 21.6 inches at the same 300 dpi. The picture got bigger; the per-inch quality claim is unchanged.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Density scaled by 4&lt;/strong&gt; → 1200 dpi, and the file still prints 3.6 × 5.4 inches. The picture is the same physical size at four times the density.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In my measurement, upscaling the 1080×1620 source to 4320×6480 with &lt;code&gt;dpi=300&lt;/code&gt; retained 300 dpi, and the reported print size grew to 14.4 × 21.6 in. Behaviour 1. Which means &lt;strong&gt;an upscale makes the print larger, not denser&lt;/strong&gt; — if you wanted the density to rise you have to change the tag yourself, and if you wanted the size to stay the same you also have to change the tag yourself.&lt;/p&gt;

&lt;p&gt;Neither is wrong. What is wrong is not knowing which one your tool does, because "I upscaled to 300 DPI" is very often a wish rather than a description.&lt;/p&gt;

&lt;h2&gt;
  
  
  The arithmetic that actually matters
&lt;/h2&gt;

&lt;p&gt;Strip away the metadata and the question is trivial arithmetic, which is why it is worth writing down once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print_inches = pixels / dpi
required_pixels = print_inches × target_dpi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a 6 × 9 inch print at 300 dpi you need 1800 × 2700 pixels. At 150 dpi — perfectly respectable for a poster viewed from a metre — you need 900 × 1350. For a 24 × 36 inch poster at 150 dpi, 3600 × 5400.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Print&lt;/th&gt;
&lt;th&gt;dpi&lt;/th&gt;
&lt;th&gt;Pixels needed&lt;/th&gt;
&lt;th&gt;Upscale from 1080×1620&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;3.6 × 5.4 in (postcard)&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;td&gt;1080 × 1620&lt;/td&gt;
&lt;td&gt;none — native&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6 × 9 in&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;td&gt;1800 × 2700&lt;/td&gt;
&lt;td&gt;1.67× (so 2×)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8 × 12 in&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;td&gt;2400 × 3600&lt;/td&gt;
&lt;td&gt;2.2× (so 3×)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12 × 18 in&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;2400 × 3600&lt;/td&gt;
&lt;td&gt;2.2× (so 3×)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;24 × 36 in (poster)&lt;/td&gt;
&lt;td&gt;150&lt;/td&gt;
&lt;td&gt;3600 × 5400&lt;/td&gt;
&lt;td&gt;3.3× (so 4×)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Notice how the required factor collapses as the viewing distance grows. The poster at 24 × 36 needs &lt;em&gt;less&lt;/em&gt; than twice the pixels of the 8 × 12 at 300 dpi, because a poster is viewed from far away and 150 dpi is ample. This is the most common way people over-buy upscaling: they apply 300 dpi to everything, including things nobody will hold.&lt;/p&gt;

&lt;p&gt;The rule that follows: &lt;strong&gt;decide the print size and viewing distance first, compute required pixels second, and only then decide whether to upscale.&lt;/strong&gt; If the answer is 1.3×, do not run a 4× pass — you are paying for interpolation and inventing detail you cannot display.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the tag is the only thing you need
&lt;/h2&gt;

&lt;p&gt;If the pixel count is already sufficient and only the print size is wrong, you do not need an upscale at all — you need a tag. That is the zero-byte case from the first table, at least when you can set it at export time.&lt;/p&gt;

&lt;p&gt;I ran these measurements while working with &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;UpgoLAB's browser upscaler&lt;/a&gt;, because its 2× and 4× output is exactly the situation where the tag question becomes live: the pixels change and the physical interpretation depends on what the tool writes. Whatever tool you use, check the output's density field before you send it to a printer, and check it against the size you actually want rather than assuming the upscale handled it.&lt;/p&gt;

&lt;p&gt;Here is the spatial half of what a 4× pass looks like across five presets, if you are still deciding whether you need one:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The five-line checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Compute required pixels from print size and viewing distance&lt;/strong&gt;, not from a fixed dpi number. 300 dpi for a hand-held print, 150 for a wall poster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If the pixels are already enough, change the tag, not the image.&lt;/strong&gt; Nothing gets you a better print than not re-encoding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set the density at export time&lt;/strong&gt;, never as a later fix — a later fix is a generation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write both JFIF density and EXIF resolution&lt;/strong&gt; if the file has to survive a chain of unknown software.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the tag on the output&lt;/strong&gt; of any resize or upscale, and know whether your tool preserves or scales density. Mine preserved it, which means the print got bigger.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of this is about image quality. All of it is about not paying four times the file size to change a number that costs zero bytes.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>images</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>I Expected Rotating Before Downscaling to Be Better. The Measurement Said No.</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Thu, 26 Nov 2026 23:34:01 +0000</pubDate>
      <link>https://dev.to/celticgemini001/i-expected-rotating-before-downscaling-to-be-better-the-measurement-said-no-5efl</link>
      <guid>https://dev.to/celticgemini001/i-expected-rotating-before-downscaling-to-be-better-the-measurement-said-no-5efl</guid>
      <description>&lt;p&gt;I went into this measurement with a confident prediction, and the data refused it. That is worth writing up precisely because the prediction was reasonable and the refutation was clean.&lt;/p&gt;

&lt;p&gt;The question: if a pipeline has to both downscale and rotate an image, does the &lt;em&gt;order&lt;/em&gt; matter for how much detail survives? The folk answer — and my own prior — is that downscaling first is better, because the rotation then has less data to interpolate. I set up an experiment to confirm that. Instead it showed four things, only one of which I expected:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The order &lt;strong&gt;does&lt;/strong&gt; change the output, measurably and reproducibly.&lt;/li&gt;
&lt;li&gt;The size of that change is small next to rotation's own cost — about 0.6 of a grey level.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Both&lt;/strong&gt; orders end up with &lt;em&gt;more&lt;/em&gt; high-frequency energy than the no-rotation baseline, which means the extra energy is ringing, not recovered detail.&lt;/li&gt;
&lt;li&gt;My expected winner was the loser. Rotate-then-downscale retained more measured detail than downscale-then-rotate at every non-right angle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That last result is the interesting one, so let me be careful about what it does and does not mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup, with the controls that make it valid
&lt;/h2&gt;

&lt;p&gt;I took five product photographs, centre-cropped each to a square, and resampled to 2048×2048 so the pipeline's 0.5× downscale would land on a clean 1024. Then three arms:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Arm&lt;/th&gt;
&lt;th&gt;Pipeline&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;downscale 0.5× (Lanczos) → rotate θ (bicubic) → upscale back to 1024&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;rotate θ (bicubic) → downscale 0.5× (Lanczos) → upscale back to 1024&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ref&lt;/td&gt;
&lt;td&gt;downscale 0.5× → upscale back to 1024, &lt;strong&gt;no rotation at all&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both arms do the same two operations on the same input and produce the same output size. The only variable is order. The &lt;code&gt;ref&lt;/code&gt; arm exists so I can separate "how much detail does rotation itself cost" from "how much does the order cost" — without it, an order difference of 0.6 levels could be a rounding artefact of my own code and I would have no way to tell.&lt;/p&gt;

&lt;p&gt;Three controls, and I had to fix two of them before they meant anything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;θ = 0° must be bit-identical.&lt;/strong&gt; If the two pipelines agree when nothing is rotated, my arm implementations are equivalent. Measured max difference: &lt;strong&gt;0.0.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A flat plane must be order-free.&lt;/strong&gt; A constant grey image has no structure to reorder, so the interior difference must be exactly zero. Measured: &lt;strong&gt;0.0.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;rotate(90°)&lt;/code&gt; must equal &lt;code&gt;transpose(ROTATE_90)&lt;/code&gt;.&lt;/strong&gt; If Pillow's 90° rotation is a bit-exact permutation, right angles are free; if it interpolates, they are not. Measured max difference: &lt;strong&gt;0.0&lt;/strong&gt;, so it is exact.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those controls are not decoration. On my first attempt I measured the whole frame and the flat-plane control reported a 0.036 difference on an image that cannot possibly have one — because &lt;code&gt;rotate(expand=False)&lt;/code&gt; fills corners with black, and I was averaging the fill. The result was a control leaking into the measurement. I raised the interior margin to 260 px on a 1024 px output and the control went to exactly zero. &lt;strong&gt;A control that fails is not a formality; it is telling you your measurement is wrong.&lt;/strong&gt; If I had skipped it I would have published a number about black corners.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers say
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rotation&lt;/th&gt;
&lt;th&gt;HF, downscale→rotate (% of no-rotation ref)&lt;/th&gt;
&lt;th&gt;HF, rotate→downscale (%)&lt;/th&gt;
&lt;th&gt;mean |A−B|, grey levels&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0°&lt;/td&gt;
&lt;td&gt;100.00&lt;/td&gt;
&lt;td&gt;100.00&lt;/td&gt;
&lt;td&gt;0.000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5°&lt;/td&gt;
&lt;td&gt;101.66&lt;/td&gt;
&lt;td&gt;103.95&lt;/td&gt;
&lt;td&gt;0.597&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;17°&lt;/td&gt;
&lt;td&gt;102.27&lt;/td&gt;
&lt;td&gt;103.92&lt;/td&gt;
&lt;td&gt;0.604&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30°&lt;/td&gt;
&lt;td&gt;104.64&lt;/td&gt;
&lt;td&gt;106.14&lt;/td&gt;
&lt;td&gt;0.636&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;45°&lt;/td&gt;
&lt;td&gt;104.78&lt;/td&gt;
&lt;td&gt;108.08&lt;/td&gt;
&lt;td&gt;0.672&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;90°&lt;/td&gt;
&lt;td&gt;100.00&lt;/td&gt;
&lt;td&gt;99.97&lt;/td&gt;
&lt;td&gt;0.132&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjqoptcx5t9yjtn6yd30o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjqoptcx5t9yjtn6yd30o.png" alt="Left: the order effect is zero at right angles and non-zero everywhere else. Right: both orders exceed the no-rotation baseline — rotation manufactures high-frequency energy" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Read the third column first: the order effect is real but small. At 45° — the worst angle — the two orders differ by about &lt;strong&gt;0.67 of a grey level&lt;/strong&gt; on average across a 1024 px frame. That is not visible as a difference between two images side by side. It becomes visible only after upscaling amplifies it, which is the reason it matters here at all.&lt;/p&gt;

&lt;p&gt;Read the last row next, because it is the control that reframes everything else: at &lt;strong&gt;0° and 90°&lt;/strong&gt; the order difference collapses to essentially zero (0.000 and 0.132 levels). Right angles are lattice-preserving permutations — they move pixels to new addresses without interpolating — so there is nothing for the order to reorder. Every angle in between requires interpolation, and interpolation is what makes order matter. That pattern is what tells you the effect is caused by the rotation and not by my arithmetic.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result that killed my hypothesis
&lt;/h2&gt;

&lt;p&gt;The second and third columns are the surprise. Both arms carry &lt;strong&gt;more&lt;/strong&gt; measured high-frequency energy than the no-rotation baseline — up to 108% at 45°. If you are reading quickly, that looks like a win. It is not.&lt;/p&gt;

&lt;p&gt;Rotation is an interpolation, and any interpolator with negative lobes (Lanczos and bicubic both have them) produces ringing — overshoot near edges. Ringing is high-frequency energy. So a rotated image scores &lt;em&gt;higher&lt;/em&gt; on a high-frequency-energy metric while looking &lt;em&gt;softer&lt;/em&gt;, because the metric cannot distinguish "detail" from "overshoot about detail". This is the same trap as evaluating an upscaler by PSNR alone: the number rewards a class of artefact.&lt;/p&gt;

&lt;p&gt;So the correct reading of the table is not "rotate-then-scale preserves more detail". It is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The order difference is real and reproducible.&lt;/li&gt;
&lt;li&gt;It is small relative to rotation's own cost, which is the larger term and is paid either way.&lt;/li&gt;
&lt;li&gt;The direction of the difference on an HF metric is confounded by ringing, so an HF number cannot tell you which order is &lt;em&gt;better&lt;/em&gt; — only that they differ.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My prior was "downscale first is better because there is less data to interpolate". The data does not support that, and it does not support the reverse either. What it supports is: &lt;strong&gt;the order matters, the magnitude is sub-visual before upscaling, and if you want to know which is better for your content you need a perceptual metric or a human, not a Laplacian.&lt;/strong&gt; That is a less satisfying answer than the one I predicted, and it is the one I actually have.&lt;/p&gt;

&lt;h2&gt;
  
  
  The canvas layer, where the difference should have been huge
&lt;/h2&gt;

&lt;p&gt;If your pipeline is in a browser — and a lot of this damage happens in canvas-based share and upload flows — there is a second thing to check, and here the measurement was unambiguous.&lt;/p&gt;

&lt;p&gt;Canvas gives you &lt;code&gt;imageSmoothingQuality&lt;/code&gt; with three settings: &lt;code&gt;"low"&lt;/code&gt;, &lt;code&gt;"medium"&lt;/code&gt;, &lt;code&gt;"high"&lt;/code&gt;. It reads like a quality dial. The &lt;a href="https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-imagesmoothingquality" rel="noopener noreferrer"&gt;HTML specification's definition&lt;/a&gt; makes it a &lt;em&gt;hint&lt;/em&gt; with no specified algorithmic effect, but hints usually do something.&lt;/p&gt;

&lt;p&gt;I rendered the same 1080×1620 source into a 900×900 canvas at all three settings, at 0° and at 17°, then hashed the resulting &lt;code&gt;ImageData&lt;/code&gt; buffers with FNV-1a and compared.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rotation&lt;/th&gt;
&lt;th&gt;&lt;code&gt;low&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;medium&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;high&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0°&lt;/td&gt;
&lt;td&gt;hash &lt;code&gt;3365341244&lt;/code&gt;, HF 8.280&lt;/td&gt;
&lt;td&gt;hash &lt;code&gt;3365341244&lt;/code&gt;, HF 8.280&lt;/td&gt;
&lt;td&gt;hash &lt;code&gt;3365341244&lt;/code&gt;, HF 8.280&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;17°&lt;/td&gt;
&lt;td&gt;hash &lt;code&gt;3797656680&lt;/code&gt;, HF 8.410&lt;/td&gt;
&lt;td&gt;hash &lt;code&gt;3797656680&lt;/code&gt;, HF 8.410&lt;/td&gt;
&lt;td&gt;hash &lt;code&gt;3797656680&lt;/code&gt;, HF 8.410&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Byte-identical at every setting.&lt;/strong&gt; Not "visually similar" — the same FNV hash over 3,240,000 bytes, and the same measured HF energy to four decimals. In Chrome 157 on Linux, &lt;code&gt;imageSmoothingQuality&lt;/code&gt; changes nothing about the output. It is a no-op.&lt;/p&gt;

&lt;p&gt;That is worth knowing for a concrete reason: if your pipeline leans on &lt;code&gt;"high"&lt;/code&gt; to preserve detail through a downscale, you are relying on a property that does not do anything. The kernel is whatever the engine picked, and it is not necessarily Lanczos or even bicubic. You cannot set it, and you cannot detect it from the page. If detail preservation matters, do the expensive resample yourself with a kernel you chose and use the canvas transform only for the final blit at 1:1.&lt;/p&gt;

&lt;p&gt;Note also that the 17° render has &lt;em&gt;higher&lt;/em&gt; HF (8.410 vs 8.280) than the unrotated one — the same ringing signature as the Python arms. Two independent codebases, two different resamplers, the same direction of artefact. That consistency is what makes me confident the HF-increase is a property of rotation-with-interpolation rather than of Pillow specifically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two things to check before you send a file through an upscaler
&lt;/h2&gt;

&lt;p&gt;The practical output of this measurement is small and specific, which is the honest size of the finding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First: right angles are free, everything else is not.&lt;/strong&gt; If your geometry work can be expressed as crop, flip, and 90° rotations, do that and stop. The moment you introduce 3° of straightening or a 17° align, you are interpolating, and the order effect and the ringing both switch on together. Crop instead of straighten whenever the framing allows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second: do not trust &lt;code&gt;imageSmoothingQuality&lt;/code&gt;, and verify with a control.&lt;/strong&gt; Hash your canvas output at two settings and compare. If the hashes match — as they do in Chrome — you have learned that the dial is inert in your engine, and you can stop counting on it. If they differ, you have learned your engine implements it and you can measure how. Either way you now know something checkable instead of something assumed.&lt;/p&gt;

&lt;p&gt;I ran these measurements while evaluating &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;UpgoLAB's browser upscaler&lt;/a&gt;, which handles video as well as stills, and the ordering question gets worse in video: a per-frame rotation resamples every frame onto a slightly different lattice, and the inconsistency &lt;em&gt;between&lt;/em&gt; frames reads as shimmer even when each frame is fine. Stabilise once, in one pass, before upscaling — never per frame.&lt;/p&gt;

&lt;p&gt;The 28-second demo below runs five presets on the product's own output, if you want the spatial half of this before measuring your own files:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The lesson I would carry forward
&lt;/h2&gt;

&lt;p&gt;I set out to confirm a plausible story and produced a set of numbers that contradicted it. The useful part is not the numbers — they are small — but the shape of the mistake:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A plausible mechanism (less data to interpolate) is not a measurement.&lt;/li&gt;
&lt;li&gt;A control that fails is the measurement telling you it is broken, not a formality. Mine did, twice.&lt;/li&gt;
&lt;li&gt;A metric can move in the &lt;em&gt;opposite&lt;/em&gt; direction to quality when ringing is present. HF energy went up while the image got softer.&lt;/li&gt;
&lt;li&gt;When the direction of a small effect is confounded, the honest output is "it differs, and I cannot rank them with this metric" — not a rank.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you take one thing from this post, take the third and fourth points, because they apply to every "measure your pipeline" article you will ever read, including mine.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>performance</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Before You Upscale Anything, Find Out Which of the Three Softnesses You Have</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Thu, 26 Nov 2026 23:29:58 +0000</pubDate>
      <link>https://dev.to/celticgemini001/before-you-upscale-anything-find-out-which-of-the-three-softnesses-you-have-me3</link>
      <guid>https://dev.to/celticgemini001/before-you-upscale-anything-find-out-which-of-the-three-softnesses-you-have-me3</guid>
      <description>&lt;p&gt;Every "my photo is blurry, should I upscale it" question hides three different problems, and an upscaler only fixes one of them. If you guess wrong, you pay for a 4× pass that makes the file eight times larger and the image no better — or worse, you pay for it and the result &lt;em&gt;looks&lt;/em&gt; sharper at 100% while carrying artefacts that were never in the original.&lt;/p&gt;

&lt;p&gt;This post is a diagnostic procedure, not a tool review. It comes out of a set of measurements I ran on seven photographs and one 96-frame clip, comparing a JPEG-compressed source against an uncompressed master of the same content, and comparing four resampling kernels across six down/up round-trips. Where I quote a number below, it came from a file in that measurement set; where I am reasoning rather than measuring, I say so.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three softnesses
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What it looks like&lt;/th&gt;
&lt;th&gt;What actually caused it&lt;/th&gt;
&lt;th&gt;Can an upscaler recover it&lt;/th&gt;
&lt;th&gt;What to do instead&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Uniformly soft everywhere, no crisp edges anywhere, even in high-contrast regions&lt;/td&gt;
&lt;td&gt;Optical: lens, focus, motion blur, or a scanner sampling below the print's real detail&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Partly.&lt;/strong&gt; General structure can be sharpened; the missing spatial frequencies were never captured, so anything the model draws there is invented&lt;/td&gt;
&lt;td&gt;Sharpen, accept, or rescan at higher resolution if the original is physical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sharp in places, blocky or ringing near edges, fine texture looks "dirty" rather than detailed&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Compression.&lt;/strong&gt; An 8×8 DCT grid threw the high frequencies away and left quantisation noise behind&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;No, and trying makes it worse.&lt;/strong&gt; Upscaling magnifies the block boundaries along with everything else&lt;/td&gt;
&lt;td&gt;Identify the grid, treat it, then consider whether upscaling is still worth it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sharp but slightly "off", edges fine but tiny structures missing, colour fringing on boundaries&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Resampling.&lt;/strong&gt; The image was already resized — sometimes several times — through a kernel that discarded detail&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;No.&lt;/strong&gt; Detail destroyed by resampling is gone; a second pass cannot un-ring the first&lt;/td&gt;
&lt;td&gt;Go back to the largest original you still have&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The reason this matters is that the three failure modes respond to opposite treatments. Compression damage wants a &lt;em&gt;low-pass&lt;/em&gt; step (deblocking). Optical softness wants a &lt;em&gt;high-pass&lt;/em&gt; step (sharpening). Resampling damage wants nothing at all — you want to stop touching it and go find a better source. Apply the wrong one and you spend quality instead of buying it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring what a JPEG costs, at five quality levels
&lt;/h2&gt;

&lt;p&gt;Start with the compression case, because it is the most common and the most measurable.&lt;/p&gt;

&lt;p&gt;I took one 1080×1620 photograph, encoded it at five JPEG qualities (30, 50, 70, 85, 95), decoded it back, upscaled 2× with Lanczos, and compared the upscale against an upscale of the &lt;em&gt;uncompressed&lt;/em&gt; original. Then I looked at two numbers inside the result: a detail ratio &lt;code&gt;R&lt;/code&gt;, defined as the high-frequency energy in a narrow band across an 8-pixel boundary divided by the same measure in a band placed away from any boundary, and the mean grey-level step measured across that boundary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9c5cmkv23t6ac009nkh1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9c5cmkv23t6ac009nkh1.png" alt="The seam you see is not the upscaler: R and the grey-level step both fall as source quality rises" width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Source quality&lt;/th&gt;
&lt;th&gt;R (seam ÷ clean detail)&lt;/th&gt;
&lt;th&gt;Grey step at the seam&lt;/th&gt;
&lt;th&gt;HF energy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;q30&lt;/td&gt;
&lt;td&gt;2.07&lt;/td&gt;
&lt;td&gt;2.04 levels&lt;/td&gt;
&lt;td&gt;118.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;q50&lt;/td&gt;
&lt;td&gt;1.78&lt;/td&gt;
&lt;td&gt;1.77&lt;/td&gt;
&lt;td&gt;119.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;q70&lt;/td&gt;
&lt;td&gt;1.57&lt;/td&gt;
&lt;td&gt;1.52&lt;/td&gt;
&lt;td&gt;113.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;q85&lt;/td&gt;
&lt;td&gt;1.50&lt;/td&gt;
&lt;td&gt;1.41&lt;/td&gt;
&lt;td&gt;109.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;q95&lt;/td&gt;
&lt;td&gt;1.41&lt;/td&gt;
&lt;td&gt;1.30&lt;/td&gt;
&lt;td&gt;106.7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Read the R column carefully, because it is the whole argument. At &lt;code&gt;R = 1&lt;/code&gt; the seam is statistically indistinguishable from the photo's own texture — the compression grid has vanished. At q30 it is 2.07, meaning the boundary region carries roughly twice the high-frequency energy of clean texture. That excess is the block edge, and the upscaler faithfully reproduced it at double size. &lt;strong&gt;The visible seam in an upscaled JPEG is not an upscaler defect. It is the codec's signature, magnified.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The trend is monotone and it does not reach 1. Even q95 leaves R at 1.41. That is consistent with how JPEG works: the &lt;a href="https://www.itu.int/rec/T-REC-T.81/en" rel="noopener noreferrer"&gt;ITU-T T.81 recommendation&lt;/a&gt; quantises DCT coefficients against a table derived from a quality scale, and at any quality below lossless the 8×8 block boundaries are reconstructed from fewer bits than the interior, so a step at the boundary is expected rather than exceptional. You cannot encode your way out of it; you can only start from a better source or treat the grid.&lt;/p&gt;

&lt;p&gt;That last column, HF energy, is the second half of the story and it moves the &lt;em&gt;opposite&lt;/em&gt; way to R: as quality rises, R falls and HF energy also falls slightly. Lower HF energy at higher quality is not a contradiction — the high-frequency content that a low-quality encode leaves behind is largely noise, and it disappears as quantisation lightens. Which means an upscaler fed a q30 file is spending part of its capacity amplifying noise while simultaneously making the block grid more visible. Both effects are visible in the same image, and both are worse at lower quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deciding whether the lost detail was resampling or compression
&lt;/h2&gt;

&lt;p&gt;If you know the file was resized somewhere upstream — a screenshot, a chat app, a CMS that "helpfully" set a max width — then compression and resampling damage are present together and you need to know the split before choosing a fix.&lt;/p&gt;

&lt;p&gt;I measured it by comparing the same upscale against two references: the JPEG-decoded source and a PNG of the same content that never touched the codec. The PSNR gap between those two references is the codec's contribution; the rest is resampling.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Upscale factor&lt;/th&gt;
&lt;th&gt;PSNR vs JPEG source&lt;/th&gt;
&lt;th&gt;PSNR vs lossless PNG&lt;/th&gt;
&lt;th&gt;Gap (codec cost)&lt;/th&gt;
&lt;th&gt;Resample MSE&lt;/th&gt;
&lt;th&gt;JPEG MSE&lt;/th&gt;
&lt;th&gt;Codec share of total error&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;31.19 dB&lt;/td&gt;
&lt;td&gt;31.93 dB&lt;/td&gt;
&lt;td&gt;0.74 dB&lt;/td&gt;
&lt;td&gt;41.72&lt;/td&gt;
&lt;td&gt;49.42&lt;/td&gt;
&lt;td&gt;15.6%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3×&lt;/td&gt;
&lt;td&gt;27.73 dB&lt;/td&gt;
&lt;td&gt;28.18 dB&lt;/td&gt;
&lt;td&gt;0.45 dB&lt;/td&gt;
&lt;td&gt;98.78&lt;/td&gt;
&lt;td&gt;109.56&lt;/td&gt;
&lt;td&gt;9.8%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;26.73 dB&lt;/td&gt;
&lt;td&gt;27.13 dB&lt;/td&gt;
&lt;td&gt;0.40 dB&lt;/td&gt;
&lt;td&gt;125.89&lt;/td&gt;
&lt;td&gt;138.10&lt;/td&gt;
&lt;td&gt;8.0%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcgzqzctsvvep8m88lcsg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcgzqzctsvvep8m88lcsg.png" alt="Where the bytes go decides the result: spending the budget before the upscale beats spending it after" width="799" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two things to take from this table. First, the codec's share of the total error &lt;strong&gt;shrinks&lt;/strong&gt; as the upscale factor rises, from 15.6% at 2× to 8.0% at 4×. That is the opposite of the intuition most people have ("more zoom means more visible compression"). The absolute codec error is roughly constant; the &lt;em&gt;resampling&lt;/em&gt; error grows much faster, so at 4× the dominant damage is no longer the JPEG at all — it is whatever resize happened before you got the file. Second, this is exactly why going bigger does not rescue a damaged file: you are amplifying the larger error term.&lt;/p&gt;

&lt;p&gt;A related measurement, from the same clip, on where to place a fixed byte budget. The codec here is H.264; the &lt;a href="https://www.videolan.org/developers/x264.html" rel="noopener noreferrer"&gt;x264 documentation on rate control&lt;/a&gt; is the reference for why bits-per-pixel, not bitrate, is the comparable quantity across resolutions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Encode order&lt;/th&gt;
&lt;th&gt;Bits per pixel at the small size&lt;/th&gt;
&lt;th&gt;PSNR vs the pristine master&lt;/th&gt;
&lt;th&gt;Blockiness&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;300 kbps at the small size, then upscale&lt;/td&gt;
&lt;td&gt;0.69&lt;/td&gt;
&lt;td&gt;30.77 dB&lt;/td&gt;
&lt;td&gt;1.35&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Upscale first, then encode at 300 kbps&lt;/td&gt;
&lt;td&gt;0.17&lt;/td&gt;
&lt;td&gt;27.75 dB&lt;/td&gt;
&lt;td&gt;1.65&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Upscale first, then encode at 1200 kbps (matched bits/pixel)&lt;/td&gt;
&lt;td&gt;0.69&lt;/td&gt;
&lt;td&gt;32.12 dB&lt;/td&gt;
&lt;td&gt;1.27&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;700 kbps at the small size, then upscale&lt;/td&gt;
&lt;td&gt;1.60&lt;/td&gt;
&lt;td&gt;32.59 dB&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The starved arm — upscaling and &lt;em&gt;then&lt;/em&gt; squeezing the result — loses 3 dB and gains blockiness, for the same nominal order of magnitude of effort. Matched bits/pixel after the upscale recovers it (32.12 dB) but costs four times the bitrate to get there. Spending the bytes &lt;strong&gt;before&lt;/strong&gt; the upscale is the cheaper route to the same quality, and that is a general principle worth keeping: the encode that matters is the one closest to the source.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test you can run on any file in two minutes
&lt;/h2&gt;

&lt;p&gt;Here is the procedure I would actually hand someone. It needs no special software — an image viewer, a crop tool that does not resample, and a way to view a 4× nearest-neighbour zoom are enough.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Find a high-contrast boundary that should be perfectly straight&lt;/strong&gt; — a window frame, a building edge, a horizon, a product's silhouette against a plain background. Avoid anything with intentional texture.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Crop a 128×128 region centred on that boundary with no resizing.&lt;/strong&gt; If your tool resamples the crop, the test is void; you have added the very defect you are measuring.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zoom 4× with nearest-neighbour interpolation&lt;/strong&gt; (not smooth, not bilinear). Nearest-neighbour is the only zoom that shows you the pixels you actually have.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Look at the edge profile, not the edge.&lt;/strong&gt; A compression-damaged edge shows a periodic staircase at 8-pixel intervals, or a faint ringing echo an eighth of the block apart. A resampled edge shows a smooth 3–5 pixel ramp with no periodicity. An optically soft edge shows a similarly smooth ramp, but the &lt;em&gt;noise&lt;/em&gt; in flat areas is smooth too — resampling removes grain, optics preserve it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the flat areas for grain.&lt;/strong&gt; Grain is your control. If the flat areas are clean and smooth but the edges are ramped, the file was resampled. If flat areas still carry grain and the edges are ramped, the softness is optical.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 4 is the one people skip, and it is the decisive one: it turns a vague "this looks soft" into a periodic-versus-smooth judgement you can make in a couple of seconds.&lt;/p&gt;

&lt;p&gt;I automated the grid detection part of this on the seven photographs, because eyeballing 8-pixel periodicity is harder than it sounds on a photo with real texture. The detector scores candidate phases by high-frequency energy aligned to a candidate grid; across crops with injected offsets of 0 to 14 pixels it recovered the true phase in every case, with scores of 1.7 and 3.2 on the two axes against a phase-0 noise floor near zero. The practical point is not the algorithm — it is that &lt;strong&gt;the grid has a phase, and a crop that happens to start on the grid looks different from one that does not.&lt;/strong&gt; If you draw conclusions from a single crop without varying the offset, you can measure the crop instead of the file. That is the mistake that makes people conclude their photo is fine when it is not, or vice versa.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why filtering first usually costs you
&lt;/h2&gt;

&lt;p&gt;The intuitive fix for a blocky source is to blur or deblock it before upscaling: remove the grid, then enlarge what is left. I measured that, at two deblock strengths and two Gaussian radii, against a no-filter control.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe2o41qifswxpy3eluzv5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe2o41qifswxpy3eluzv5.png" alt="Deblock or blur before upscaling: fidelity and detail both fall" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pre-filter&lt;/th&gt;
&lt;th&gt;PSNR vs clean reference&lt;/th&gt;
&lt;th&gt;HF energy retained&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;none (control)&lt;/td&gt;
&lt;td&gt;31.19 dB&lt;/td&gt;
&lt;td&gt;119.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;deblock, strength 0.5&lt;/td&gt;
&lt;td&gt;30.34 dB&lt;/td&gt;
&lt;td&gt;108.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;deblock, strength 1.0&lt;/td&gt;
&lt;td&gt;28.83 dB&lt;/td&gt;
&lt;td&gt;106.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gaussian σ = 0.6&lt;/td&gt;
&lt;td&gt;29.05 dB&lt;/td&gt;
&lt;td&gt;70.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gaussian σ = 1.0&lt;/td&gt;
&lt;td&gt;26.68 dB&lt;/td&gt;
&lt;td&gt;44.0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every filter lost. Not by a rounding error — the σ = 1.0 Gaussian gave up 4.5 dB and 63% of the high-frequency energy. The deblocking arms are more interesting because they &lt;em&gt;improve&lt;/em&gt; SSIM at light strength (0.9788 at strength 0.5 versus 0.9785 for the control) while still losing 0.85 dB of PSNR. That divergence is real and it tells you what deblocking actually does: it makes the image more structurally similar to the reference at the cost of absolute fidelity, because it is removing a &lt;em&gt;localised&lt;/em&gt; artefact and a &lt;em&gt;global&lt;/em&gt; amount of detail in the same pass.&lt;/p&gt;

&lt;p&gt;My conclusion is not "never deblock". It is that pre-filtering an image before upscaling is a trade with a measurable price, and the price is paid in the exact currency you were trying to buy. If the source is genuinely heavily compressed, a light deblock may still be the right call — but do it deliberately and check the result, because "clean it up first" is not free advice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The quiet tax: round-trips
&lt;/h2&gt;

&lt;p&gt;There is a second, less obvious resampling cost that has nothing to do with a single resize: repetition. Most real images have been through a resize pipeline several times — export, upload, thumbnail generation, a CMS re-encode — and each pass through a resampler is lossy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbww59lnr1m3uypov7zvj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbww59lnr1m3uypov7zvj.png" alt="Every round-trip through a resampler costs contrast, and bilinear spends it fastest" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I ran the same seven photos through 0, 1, 2, 5, 10 and 20 down-then-up cycles with four kernels and measured how much of the original detail (standard deviation against the truth) survived:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Cycles&lt;/th&gt;
&lt;th&gt;Nearest&lt;/th&gt;
&lt;th&gt;Bilinear&lt;/th&gt;
&lt;th&gt;Bicubic&lt;/th&gt;
&lt;th&gt;Lanczos&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;100%&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;93.3%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;98.9%&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Nearest-neighbour is bit-exact at every cycle count — it is picking pixels, not averaging, so a down/up pair through it is a permutation and loses nothing (that is also why it looks terrible: it is not resampling, it is sampling). Bilinear loses 6.7% of the detail over 20 cycles and the loss is monotone, saturating around 93%. Bicubic is gentler at 1.1%.&lt;/p&gt;

&lt;p&gt;The number that matters is not 6.7% in the abstract. It is that the loss is &lt;strong&gt;cumulative and silent&lt;/strong&gt;. Six percent of contrast is not visible as a defect; it is visible as an image that "just doesn't pop" and that no amount of sharpening fixes convincingly, because sharpening reweights what is left rather than restoring what is gone. Twenty cycles is an extreme case — but five cycles costs bilinear about 2.5%, and five is entirely plausible for a file that has been through a phone's share sheet, a messaging app, a website's upload pipeline, a CDN's image resizer and a backup tool.&lt;/p&gt;

&lt;p&gt;The practical rule: &lt;strong&gt;every resize is a generation, and every generation is a one-way door.&lt;/strong&gt; If you have a choice between resizing once at the end and resizing twice along the way, resize once. If you are handed a file and can request a larger original, request it — the request costs nothing and a 2× larger original is worth more than any upscaler's 2× pass.&lt;/p&gt;

&lt;p&gt;The maths of why resizing is lossy in the first place is a sampling theorem question, not a software question — the &lt;a href="https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem" rel="noopener noreferrer"&gt;Wikipedia article on the Nyquist–Shannon sampling theorem&lt;/a&gt; covers the underlying argument, and the short version is that downsampling removes frequencies above the new Nyquist limit and no interpolator can put them back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where upscaling actually earns its place
&lt;/h2&gt;

&lt;p&gt;Given all of the above, the honest summary is narrow. Upscaling earns its place when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The source is &lt;strong&gt;clean&lt;/strong&gt; — light or no compression, and as close to the original capture as you can get.&lt;/li&gt;
&lt;li&gt;The softness is &lt;strong&gt;optical or structural&lt;/strong&gt; rather than a codec artefact, so there is real low-frequency information to build on.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;output has a purpose that tolerates synthesis&lt;/strong&gt;: a print at viewing distance, a hero image displayed at 50%, a video upscaled for a 4K screen where the viewer is 2.5 metres away. It does not earn its place for forensic work, for text you need to read, or for anything where a plausible invention is worse than visible blur.&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;compare at the intended size&lt;/strong&gt;, not at 100%. Almost every "upscaling made it worse" report I have seen comes from judging a 4K output on a monitor that shows a quarter of it at a time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And it does not earn its place when the file is heavily compressed, when it has been resized twice already, or when the thing you actually want back is text and thin structures — the categories where the model is guessing hardest and the eye is most unforgiving.&lt;/p&gt;

&lt;h2&gt;
  
  
  The CTA, and a way to check me
&lt;/h2&gt;

&lt;p&gt;I ran these measurements as part of evaluating &lt;a href="https://upgolab.com/en/upscale" rel="noopener noreferrer"&gt;UpgoLAB's browser upscaler&lt;/a&gt;, which does 2× and 4× on images and short video server-side with no install and no GPU on your machine — free during its launch period. What I would ask of it, and of any upscaler, is this: feed it the &lt;em&gt;cleanest&lt;/em&gt; version of your file you have, and compare the output at the size you will actually display it. The tool is not the variable. The input is.&lt;/p&gt;

&lt;p&gt;If you want to see the spatial half of the problem before you commit, this 28-second demo runs the same before/after across five presets, on the product's own output rather than a hand-picked example:&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/tCXoB3uBKm4" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;A video is also the wrong artefact to judge this class of defect from, for a reason worth stating: a still frame shows you what a preset does &lt;em&gt;spatially&lt;/em&gt; and hides what it does &lt;em&gt;temporally&lt;/em&gt;. A per-frame upscaler optimises each frame independently, so the frames can each be excellent and the sequence still shiver — edges crawling, texture boiling. Judge motion by playing the clip, never by scrubbing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short decision list
&lt;/h2&gt;

&lt;p&gt;Print this out and stick it next to your monitor, or don't; it is four lines.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Is there periodicity at 8 pixels?&lt;/strong&gt; You have compression damage. Do not upscale hoping to fix it; treat it lightly or start from a better source.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is the flat area grain-free but the edges ramped?&lt;/strong&gt; You have resampling damage. Go find a larger original before doing anything else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is it uniformly soft with grain intact?&lt;/strong&gt; This is the case upscaling is for. Use a natural or texture-preserving preset, not the sharpest one, and check at display size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Have you already resized it once?&lt;/strong&gt; Every additional resize costs contrast you cannot get back. Do the remaining work in one pass.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of these require trusting a benchmark — mine or anyone's. They require one 128×128 crop, a 4× nearest-neighbour zoom, and about two minutes. That is a much better use of the first two minutes than an upscale you might not have needed.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>video</category>
      <category>images</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Chroma siting is a half-pixel convention that becomes a full-pixel colour shift</title>
      <dc:creator>celticgemini001</dc:creator>
      <pubDate>Fri, 20 Nov 2026 14:19:17 +0000</pubDate>
      <link>https://dev.to/celticgemini001/chroma-siting-is-a-half-pixel-convention-that-becomes-a-full-pixel-colour-shift-5gib</link>
      <guid>https://dev.to/celticgemini001/chroma-siting-is-a-half-pixel-convention-that-becomes-a-full-pixel-colour-shift-5gib</guid>
      <description>&lt;p&gt;Chroma siting is the one setting nobody checks, and it decides where every colour edge in your upscaled frame lands. The short version: in 4:2:0, a single colour sample represents a 2×2 block of luma pixels — but &lt;em&gt;where inside that block&lt;/em&gt; the sample sits is a convention, not a fact of the image. Two conventions dominate, they differ by half a chroma sample, and if the decoder assumes one while the encoder used the other, the colour plane lands one full luma pixel off while the luma plane stays exactly where it should be.&lt;/p&gt;

&lt;p&gt;That asymmetry is the whole story. Detail is crisp, geometry is silently wrong, and nothing in the file tells you.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two conventions differ by exactly one pixel
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Convention&lt;/th&gt;
&lt;th&gt;Where the sample sits&lt;/th&gt;
&lt;th&gt;Used by&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;co-sited&lt;/td&gt;
&lt;td&gt;luma position (2k, 2l) — top-left of the 2×2 block&lt;/td&gt;
&lt;td&gt;MPEG-2, H.264 default&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;centered&lt;/td&gt;
&lt;td&gt;luma position (2k+1, 2l+1) — middle of the block&lt;/td&gt;
&lt;td&gt;JPEG, MPEG-1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Half a chroma sample is one luma pixel. At 4:2:0 a chroma sample covers 2 luma pixels in each axis, so the offset between the two conventions, expressed in luma, is exactly 1. Not "about one" — structurally exactly one.&lt;/p&gt;

&lt;p&gt;I measured this on seven real photographs, cropping 512×512 from the centre, converting to YCbCr and working on the Cb and Cr planes directly rather than on RGB. Working in the colour planes matters: RGB hides the problem because the conversion smears the displacement across all three channels, and a mean-error number computed on RGB makes a one-pixel colour shift look like ordinary resampling noise.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cost is a 1.66–2.55× increase in chroma error
&lt;/h2&gt;

&lt;p&gt;For each plane I did the honest round trip — subsample with centered siting, reconstruct with centered siting — and then the mistaken one, subsample centered and reconstruct as if co-sited:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Photo&lt;/th&gt;
&lt;th&gt;Cb correct&lt;/th&gt;
&lt;th&gt;Cb mismatched&lt;/th&gt;
&lt;th&gt;ratio&lt;/th&gt;
&lt;th&gt;Cr correct&lt;/th&gt;
&lt;th&gt;Cr mismatched&lt;/th&gt;
&lt;th&gt;ratio&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;048d3778&lt;/td&gt;
&lt;td&gt;0.255&lt;/td&gt;
&lt;td&gt;0.546&lt;/td&gt;
&lt;td&gt;2.14&lt;/td&gt;
&lt;td&gt;0.234&lt;/td&gt;
&lt;td&gt;0.461&lt;/td&gt;
&lt;td&gt;1.97&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1344197c&lt;/td&gt;
&lt;td&gt;0.257&lt;/td&gt;
&lt;td&gt;0.654&lt;/td&gt;
&lt;td&gt;2.55&lt;/td&gt;
&lt;td&gt;0.242&lt;/td&gt;
&lt;td&gt;0.540&lt;/td&gt;
&lt;td&gt;2.23&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6766a320&lt;/td&gt;
&lt;td&gt;0.271&lt;/td&gt;
&lt;td&gt;0.666&lt;/td&gt;
&lt;td&gt;2.46&lt;/td&gt;
&lt;td&gt;0.197&lt;/td&gt;
&lt;td&gt;0.339&lt;/td&gt;
&lt;td&gt;1.72&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;792e8b64&lt;/td&gt;
&lt;td&gt;0.286&lt;/td&gt;
&lt;td&gt;0.692&lt;/td&gt;
&lt;td&gt;2.42&lt;/td&gt;
&lt;td&gt;0.259&lt;/td&gt;
&lt;td&gt;0.531&lt;/td&gt;
&lt;td&gt;2.05&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ac7b6755&lt;/td&gt;
&lt;td&gt;0.311&lt;/td&gt;
&lt;td&gt;0.723&lt;/td&gt;
&lt;td&gt;2.32&lt;/td&gt;
&lt;td&gt;0.315&lt;/td&gt;
&lt;td&gt;0.748&lt;/td&gt;
&lt;td&gt;2.37&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;b4fd2338&lt;/td&gt;
&lt;td&gt;0.258&lt;/td&gt;
&lt;td&gt;0.609&lt;/td&gt;
&lt;td&gt;2.36&lt;/td&gt;
&lt;td&gt;0.231&lt;/td&gt;
&lt;td&gt;0.511&lt;/td&gt;
&lt;td&gt;2.21&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;c079d084&lt;/td&gt;
&lt;td&gt;0.197&lt;/td&gt;
&lt;td&gt;0.441&lt;/td&gt;
&lt;td&gt;2.24&lt;/td&gt;
&lt;td&gt;0.186&lt;/td&gt;
&lt;td&gt;0.310&lt;/td&gt;
&lt;td&gt;1.66&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Median ratio 2.24×, range 1.66–2.55×. The absolute numbers are small — a quarter of one level to two-thirds of a level on a 0–255 scale — and that is the point worth being honest about. This is not a visible-in-a-thumbnail error. It is a systematic one that sits underneath everything else, and it compounds with the scale factor.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shift stays 1 pixel; the relative damage multiplies
&lt;/h2&gt;

&lt;p&gt;This is the part I got wrong first, and it's worth walking through because the wrong version sounds more dramatic.&lt;/p&gt;

&lt;p&gt;My initial scaling loop divided output coordinates by a hardcoded 2.0 regardless of the upscale factor. That reported a 1-pixel shift at k=1, k=2 and k=4 — and it was an artefact. Correcting it, I discovered the opposite: in a genuine 4:2:0 output the chroma plane is always half the luma raster, so chroma-sample spacing is a constant 2 output pixels at every scale. The displacement really is a constant 1 output pixel. What grows is not the shift but its weight relative to everything else:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Upscale&lt;/th&gt;
&lt;th&gt;error, matched siting&lt;/th&gt;
&lt;th&gt;error, mismatched&lt;/th&gt;
&lt;th&gt;ratio&lt;/th&gt;
&lt;th&gt;shift&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1×&lt;/td&gt;
&lt;td&gt;0.250&lt;/td&gt;
&lt;td&gt;0.555&lt;/td&gt;
&lt;td&gt;2.22×&lt;/td&gt;
&lt;td&gt;1 px&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;0.125&lt;/td&gt;
&lt;td&gt;0.331&lt;/td&gt;
&lt;td&gt;2.66×&lt;/td&gt;
&lt;td&gt;1 px&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;0.033&lt;/td&gt;
&lt;td&gt;0.170&lt;/td&gt;
&lt;td&gt;5.14×&lt;/td&gt;
&lt;td&gt;1 px&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Read the two error columns together. Correct siting gets &lt;em&gt;better&lt;/em&gt; with upscaling — 0.250 down to 0.033 — because interpolating a finer grid is a better-conditioned problem. Mismatched siting also improves in absolute terms, but four times more slowly. The ratio climbs from 2.22× to 5.14×. So upscaling doesn't create the error; it just removes everything else that was masking it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Along a hard colour edge, the fringe widens
&lt;/h2&gt;

&lt;p&gt;A single error number understates what a viewer notices. What a viewer notices is a colour fringe hugging an edge, and that width does grow:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Upscale&lt;/th&gt;
&lt;th&gt;fringe, matched siting&lt;/th&gt;
&lt;th&gt;fringe, mismatched&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1×&lt;/td&gt;
&lt;td&gt;1 px&lt;/td&gt;
&lt;td&gt;1 px&lt;/td&gt;
&lt;td&gt;same&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2×&lt;/td&gt;
&lt;td&gt;2 px&lt;/td&gt;
&lt;td&gt;3 px&lt;/td&gt;
&lt;td&gt;+1 px&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4×&lt;/td&gt;
&lt;td&gt;2 px&lt;/td&gt;
&lt;td&gt;5 px&lt;/td&gt;
&lt;td&gt;+3 px&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At 4× the mismatch paints a fringe more than twice as wide as the correct pipeline leaves. On red-to-blue transitions — the classic worst case for chroma — this is the visible form of the problem, and it is why chroma handling deserves the same attention as sharpening. If you are already working through edge behaviour, this is the same family of question as &lt;a href="https://celticgemini001.github.io/upgolab-fractional-upscale-factors/" rel="noopener noreferrer"&gt;what happens to the grid when the factor is not a whole number&lt;/a&gt; — geometry that survives the resize numerically while going wrong relationally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why ten controls, and what they caught
&lt;/h2&gt;

&lt;p&gt;Two of the numbers above were wrong in an earlier run, and the controls are the reason they didn't ship.&lt;/p&gt;

&lt;p&gt;The first control failure was mine, not the code's: I used a linear ramp to test whether a mismatch produces a shift. A mean-removed linear ramp is invariant to integer translation — shifting it just adds a constant — so the correlator returned lag 0 on a case that genuinely was displaced. The estimator was blind, and a blind estimator reports "no effect" perfectly consistently. Switching to a Gaussian bump, which has a unique peak, made the same test report −1 px immediately.&lt;/p&gt;

&lt;p&gt;The second was the hardcoded 2.0 described above, caught by asserting the geometry rather than trusting the printout.&lt;/p&gt;

&lt;p&gt;The remaining controls pin down what is &lt;em&gt;not&lt;/em&gt; being measured:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A flat plane under matched siting is bit-exact (max error 0.0).&lt;/li&gt;
&lt;li&gt;Matched siting keeps a Gaussian bump at lag 0, and mismatched siting moves it by exactly ±1.&lt;/li&gt;
&lt;li&gt;The two mismatch directions are symmetric, so this isn't a bias in the correlator.&lt;/li&gt;
&lt;li&gt;A constant colour plane is immune — no gradient, nothing to displace.&lt;/li&gt;
&lt;li&gt;A checkerboard at the chroma Nyquist is destroyed by 4:2:0 subsampling alone, at a mean error of 127.50, whoever is right about siting. That separates the two failure modes: subsampling loses high-frequency colour outright; siting only moves what survives.&lt;/li&gt;
&lt;li&gt;Self-correlation of an unshifted copy reports lag 0, confirming the estimator is not inventing displacement.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All ten pass, and the script re-runs to the same values.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually goes wrong in a pipeline
&lt;/h2&gt;

&lt;p&gt;The mechanism is unglamorous. An upscaler decodes a JPEG to RGB, resizes, re-encodes. Each of those steps may hold a different assumption about siting, and the assumption is usually implicit — it lives in whatever library function was called, not in a setting you can read. The decode-up-sample step in most JPEG libraries assumes centered siting because JPEG specifies it. A video pipeline that later hands that frame to something expecting co-sited chroma has already introduced the offset, and the subsequent resize faithfully preserves the mistake while making it relatively more prominent, exactly as the table above shows.&lt;/p&gt;

&lt;p&gt;The practical consequence: if you compare two upscalers on a colour-critical subject and one looks subtly "off" in a way you can't localise, siting is a plausible cause and it will not show up in a PSNR computed on RGB. It shows up as a consistent half-sample colour lead or lag on edges.&lt;/p&gt;

&lt;p&gt;There is no single setting to flip, because the fix belongs at the boundary: know which convention each stage assumes, and don't chain a co-sited stage into a centered one without accounting for the half-sample. If the half-sample is the kind of detail you want to see rather than read about, &lt;a href="https://upgolab.com" rel="noopener noreferrer"&gt;run the same photo through an upscaler in a browser tab&lt;/a&gt; and compare edges at 400% — the displacement is small enough to hide in a full frame and large enough to see once you know which edge to look at.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Chroma siting is a half-sample convention that becomes a full-pixel colour displacement, and it survives upscaling intact while everything around it improves. Measured on seven photographs, assuming the wrong convention costs 1.66–2.55× in chroma error and widens edge fringes from 2 px to 5 px at 4×. It is not a resolution problem and no amount of additional pixels fixes it, because the error is in the position of the colour, not in the amount of it.&lt;/p&gt;

&lt;p&gt;If you want the sampling-density side of this — what 4:2:0 itself throws away before siting ever enters the picture — the &lt;a href="https://celticgemini001.github.io/upgolab-chroma-subsampling/" rel="noopener noreferrer"&gt;chroma subsampling notes&lt;/a&gt; cover that separately. The two errors are independent and should be counted separately.&lt;/p&gt;

</description>
      <category>imageprocessing</category>
      <category>video</category>
      <category>python</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
