Sharpening & Halos
A soft edge before and after an unsharp mask: raise amount and radius and watch the profile overshoot into halos.
AI prompt
Educational before and after panel of a photographed tree branch against a pale sky, on the left the soft original, on the right a correctly sharpened version with crisp clean edges, below them a magnified crop of an over-sharpened version showing light halos along the dark twig edges, and a small line graph of the edge profile with overshoot bumps marked, clean flat layout, neutral grey background, small labels. Negative: noise, colour fringes, text errors, clutter. Reduced motion: static panel.About this pattern
Definition
Unsharp masking makes an edge look crisper by subtracting a blurred copy, which exaggerates the difference at the boundary. The edge gains contrast, but if the amount or radius is too high, the line overshoots on both sides, creating light and dark halos.
When to use it
- Amount sets how strong the effect is; radius sets how wide the affected zone is around an edge.
- The profile graph shows the overshoot: bumps above and below the original levels are halos.
- Small radius with moderate amount sharpens fine detail; large radius adds local contrast.
- Sharpen last, at the output size.
What the controls do
- Amount and Radius sliders with an edge strip and a profile plot.
Motion & timing
- Updates follow the sliders.
- Reduced motion: nothing animates.
Tips & variations
- Judge sharpening at 100 percent zoom.
- Zero overshoot is not the goal; keep it small enough that halos stay invisible.
Code of this live preview
<div class="bx"><canvas id="cv" width="300" height="124" aria-label="Edge before and after sharpening with profile"></canvas><div class="two"><label class="rw">Amount <b id="av">150%</b><input id="am" type="range" min="0" max="400" value="150"></label><label class="rw">Radius <b id="rv">4 px</b><input id="rd" type="range" min="1" max="14" value="4"></label></div><p class="out" id="out"></p></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
canvas{width:100%;height:auto;border-radius:10px;border:1px solid var(--line);background:#fff}.out{font-size:12px;color:var(--muted)}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const cv=document.getElementById('cv'),x=cv.getContext('2d'),N=300,am=document.getElementById('am'),rd=document.getElementById('rd');const s=[];for(let i=0;i<N;i++){const t=(i-150)/2.2;s.push(.3+.4/(1+Math.exp(-t)));}
function blur(a,r){return a.map((_,i)=>{let sum=0,c=0;for(let k=-r;k<=r;k++){const j=Math.max(0,Math.min(N-1,i+k));sum+=a[j];c++;}return sum/c;});}
function up(){const A=am.value/100,R=+rd.value,b=blur(s,R),o=s.map((v,i)=>v+A*(v-b[i])),cl=o.map(v=>Math.max(0,Math.min(1,v))),g=v=>{const c=Math.round(v*255);return 'rgb('+c+','+c+','+c+')';};
x.clearRect(0,0,N,124);for(let i=0;i<N;i++){x.fillStyle=g(s[i]);x.fillRect(i,0,1,22);x.fillStyle=g(cl[i]);x.fillRect(i,24,1,22);}
x.fillStyle='#888';x.font='9px sans-serif';x.fillText('Original',4,10);x.fillStyle='#fff';x.fillText('Sharpened',4,40);
const y=v=>118-Math.max(0,Math.min(1,v))*66;x.strokeStyle='#ccc';x.beginPath();x.moveTo(0,y(.3));x.lineTo(N,y(.3));x.moveTo(0,y(.7));x.lineTo(N,y(.7));x.stroke();
x.strokeStyle='#bbb';x.lineWidth=1.5;x.beginPath();s.forEach((v,i)=>i?x.lineTo(i,y(v)):x.moveTo(i,y(v)));x.stroke();x.strokeStyle='#2b59d6';x.lineWidth=2;x.beginPath();o.forEach((v,i)=>i?x.lineTo(i,y(v)):x.moveTo(i,y(v)));x.stroke();
const hi=Math.max(...o)-.7,lo=.3-Math.min(...o);document.getElementById('av').textContent=am.value+'%';document.getElementById('rv').textContent=R+' px';const ov=Math.max(hi,lo);document.getElementById('out').textContent=ov>.12?'Overshoot '+Math.round(ov*100)+'%: visible halos along the edge.':ov>.04?'Overshoot '+Math.round(ov*100)+'%: crisp, halos barely visible.':'Little overshoot: a gentle, clean result.';}
[am,rd].forEach(i=>i.addEventListener('input',up));up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Sharpening & Halos — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
canvas{width:100%;height:auto;border-radius:10px;border:1px solid var(--line);background:#fff}.out{font-size:12px;color:var(--muted)}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><canvas id="cv" width="300" height="124" aria-label="Edge before and after sharpening with profile"></canvas><div class="two"><label class="rw">Amount <b id="av">150%</b><input id="am" type="range" min="0" max="400" value="150"></label><label class="rw">Radius <b id="rv">4 px</b><input id="rd" type="range" min="1" max="14" value="4"></label></div><p class="out" id="out"></p></div>
</div>
<script>
const cv=document.getElementById('cv'),x=cv.getContext('2d'),N=300,am=document.getElementById('am'),rd=document.getElementById('rd');const s=[];for(let i=0;i<N;i++){const t=(i-150)/2.2;s.push(.3+.4/(1+Math.exp(-t)));}
function blur(a,r){return a.map((_,i)=>{let sum=0,c=0;for(let k=-r;k<=r;k++){const j=Math.max(0,Math.min(N-1,i+k));sum+=a[j];c++;}return sum/c;});}
function up(){const A=am.value/100,R=+rd.value,b=blur(s,R),o=s.map((v,i)=>v+A*(v-b[i])),cl=o.map(v=>Math.max(0,Math.min(1,v))),g=v=>{const c=Math.round(v*255);return 'rgb('+c+','+c+','+c+')';};
x.clearRect(0,0,N,124);for(let i=0;i<N;i++){x.fillStyle=g(s[i]);x.fillRect(i,0,1,22);x.fillStyle=g(cl[i]);x.fillRect(i,24,1,22);}
x.fillStyle='#888';x.font='9px sans-serif';x.fillText('Original',4,10);x.fillStyle='#fff';x.fillText('Sharpened',4,40);
const y=v=>118-Math.max(0,Math.min(1,v))*66;x.strokeStyle='#ccc';x.beginPath();x.moveTo(0,y(.3));x.lineTo(N,y(.3));x.moveTo(0,y(.7));x.lineTo(N,y(.7));x.stroke();
x.strokeStyle='#bbb';x.lineWidth=1.5;x.beginPath();s.forEach((v,i)=>i?x.lineTo(i,y(v)):x.moveTo(i,y(v)));x.stroke();x.strokeStyle='#2b59d6';x.lineWidth=2;x.beginPath();o.forEach((v,i)=>i?x.lineTo(i,y(v)):x.moveTo(i,y(v)));x.stroke();
const hi=Math.max(...o)-.7,lo=.3-Math.min(...o);document.getElementById('av').textContent=am.value+'%';document.getElementById('rv').textContent=R+' px';const ov=Math.max(hi,lo);document.getElementById('out').textContent=ov>.12?'Overshoot '+Math.round(ov*100)+'%: visible halos along the edge.':ov>.04?'Overshoot '+Math.round(ov*100)+'%: crisp, halos barely visible.':'Little overshoot: a gentle, clean result.';}
[am,rd].forEach(i=>i.addEventListener('input',up));up();
</script>
</body></html>