<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[De1ta on Image Checks]]></title><description><![CDATA[De1ta on Image Checks]]></description><link>https://de1tay.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 14:03:55 GMT</lastBuildDate><atom:link href="https://de1tay.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Detecting blurry and too-dark product photos in the browser (Laplacian variance per tile)]]></title><description><![CDATA[Per-tile Laplacian variance plus a two-part darkness test for product photos, in plain canvas code, with calibration numbers and known gaps.]]></description><link>https://de1tay.hashnode.dev/detecting-blurry-and-too-dark-product-photos-in-the-browser-laplacian-variance-per-tile</link><guid isPermaLink="true">https://de1tay.hashnode.dev/detecting-blurry-and-too-dark-product-photos-in-the-browser-laplacian-variance-per-tile</guid><category><![CDATA[canvas]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[image processing]]></category><dc:creator><![CDATA[De1ta]]></dc:creator><pubDate>Tue, 17 Nov 2026 22:43:49 GMT</pubDate><content:encoded><![CDATA[<p>Marketplaces warn sellers about main photos that are "blurry" or "too dark", but they don't publish the thresholds. I needed a check that runs entirely in the browser (no upload), so here is the approach I ended up with, the numbers I calibrated it on, and the parts I'm still unsure about.</p>
<h2>1. Normalize first: one grayscale buffer at a fixed size</h2>
<p>Every metric below depends on resolution, so the first step is to draw the image onto a canvas with the long side capped at 1024 px and convert it to luminance:</p>
<pre><code class="language-ts">function grayAt(bmp: ImageBitmap, maxSide: number) {
  const s = Math.min(1, maxSide / Math.max(bmp.width, bmp.height))
  const w = Math.max(1, Math.round(bmp.width * s))
  const h = Math.max(1, Math.round(bmp.height * s))
  const ctx = new OffscreenCanvas(w, h).getContext('2d')!
  ctx.fillStyle = '#fff' // transparent pixels count as white
  ctx.fillRect(0, 0, w, h)
  ctx.imageSmoothingQuality = 'high'
  ctx.drawImage(bmp, 0, 0, w, h)
  const d = ctx.getImageData(0, 0, w, h).data
  const y = new Float32Array(w * h)
  for (let p = 0, i = 0; p &lt; w * h; p++, i += 4)
    y[p] = 0.2126 * d[i] + 0.7152 * d[i + 1] + 0.0722 * d[i + 2]
  return { y, w, h }
}
</code></pre>
<p>Two shortcuts worth calling out:</p>
<ul>
<li>The Rec. 709 weights are applied straight to the sRGB values without linearizing. That's not physically correct, but it's close to how bright the photo <em>looks</em>, which is what a "too dark" warning is about.</li>
<li>Transparent pixels are filled with white before measuring. Some marketplaces render transparency as black, so that gets its own separate warning rather than skewing the brightness number.</li>
</ul>
<h2>2. "Too dark": mean plus the share of deep shadow</h2>
<pre><code class="language-ts">let sum = 0, dark = 0
for (let p = 0; p &lt; g.y.length; p++) {
  sum += g.y[p]
  if (g.y[p] &lt; 50) dark++
}
const mean = sum / g.y.length
const isDark = mean &lt; 70 || dark / g.y.length &gt; 0.5
</code></pre>
<p>The mean alone isn't enough. A product on a black backdrop with a bright, well-lit item can average quite low and still be a perfectly good photo, while a dim photo with a white wall in the corner can average fine. Combining "average below 70" with "more than half the pixels below 50" catches the photos that look underexposed overall. Between 70 and 95 I only show a soft note ("on the dark side, fine for a moody shot").</p>
<p>For reference, the intentionally moody holiday shots in my test set averaged 39–48 and were flagged, which is the behaviour I want: they are fine as secondary images, risky as the first one.</p>
<h2>3. "Blurry": Laplacian variance, per 32 px tile, 95th percentile</h2>
<p>The classic blur metric is the variance of the Laplacian over the whole image. It fails badly on product photos because most of the frame is a smooth background: a tack-sharp mug on a white sweep scores low simply because 70% of the pixels are flat.</p>
<p>So the image is split into 32×32 tiles, the Laplacian variance is computed per tile, and the score is the 95th percentile, which asks "is the sharpest part of the photo actually sharp?":</p>
<pre><code class="language-ts">function sharpness(y: Float32Array, w: number, h: number) {
  const T = 32
  const vars: number[] = []
  for (let ty = 1; ty + T &lt;= h - 1; ty += T) {
    for (let tx = 1; tx + T &lt;= w - 1; tx += T) {
      let sum = 0, sum2 = 0
      for (let yy = ty; yy &lt; ty + T; yy++) {
        for (let xx = tx; xx &lt; tx + T; xx++) {
          const p = yy * w + xx
          const l = y[p - 1] + y[p + 1] + y[p - w] + y[p + w] - 4 * y[p]
          sum += l
          sum2 += l * l
        }
      }
      const n = T * T
      vars.push(sum2 / n - (sum / n) ** 2)
    }
  }
  if (!vars.length) return { sharp: 0, tiles: 0 }
  vars.sort((a, b) =&gt; a - b)
  return { sharp: vars[Math.min(vars.length - 1, Math.floor(vars.length * 0.95))], tiles: vars.length }
}
</code></pre>
<p>Why the 95th percentile and not the max? A single tile with JPEG ringing, a printed label or a strand of hair can be very "sharp" in an otherwise soft photo. The 95th percentile needs a small region (about 1 in 20 tiles) to be sharp, which matches "the product is in focus".</p>
<h2>4. Calibrating the thresholds</h2>
<p>I calibrated on 32 product photos (white background, lifestyle and holiday shots) and two degraded copies of each:</p>
<table>
<thead>
<tr>
<th>Set</th>
<th>95th-percentile Laplacian variance</th>
</tr>
</thead>
<tbody><tr>
<td>Originals</td>
<td>512 – 4500</td>
</tr>
<tr>
<td>Gaussian blur, 1.5 px</td>
<td>13 – 124</td>
</tr>
<tr>
<td>Downscaled to 400 px, then upscaled 2.5×</td>
<td>24 – 262</td>
</tr>
</tbody></table>
<p>The ranges overlap a little between "blurred" and "upscaled", which is expected: an upscaled thumbnail is a kind of blur. The thresholds I settled on:</p>
<ul>
<li>below 60: warning ("even the sharpest part of the photo is soft")</li>
<li>60–200: soft note ("check the item is in focus at full size; enlarged or heavily compressed photos often look like this")</li>
<li>200 and up: looks sharp</li>
</ul>
<p>If there are fewer than 6 tiles (a tiny image), no blur verdict is given at all; the size check already complains about it.</p>
<h2>5. What I'd still be careful about</h2>
<ul>
<li><strong>These are my thresholds, not the marketplace's.</strong> Nobody publishes theirs, so the tool says a photo "may" get flagged rather than "will".</li>
<li><strong>Scale matters.</strong> Everything is measured at 1024 px on the long side. Measure at a different size and the numbers shift, so don't compare scores across different normalizations.</li>
<li><strong>Shallow depth of field is fine.</strong> A product shot with a blurred background still scores well because the 95th percentile only needs the subject to be sharp. A photo where the focus landed on the background instead of the item will also pass, though, and that's a known gap.</li>
<li><strong>Noise reads as sharpness.</strong> A grainy, dark phone photo can get a decent blur score. That's partly why the darkness check is separate.</li>
</ul>
<h2>Try it</h2>
<p>I build ImageWhim, and this code runs in a free checker for Etsy first photos (size, brightness, blur, collage-style layouts and thumbnail crop preview). Images never leave the browser: <a href="https://imagewhim.com/tools/etsy-listing-photo-checker">https://imagewhim.com/tools/etsy-listing-photo-checker</a></p>
<p>If you've found a better metric for "is the product in focus" that still runs in a few milliseconds on a canvas, I'd like to hear about it.</p>
<p><em>Written with AI assistance; the code and the calibration numbers come from the tool's source.</em></p>
]]></content:encoded></item></channel></rss>