mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: CLAHE tile size and alpha channel corruption in image enhancement
CLAHE width/height is tile size in pixels, not tile count. A 3px tile on a 992x1088 image created ~330x360 independent histogram regions, producing crosshatch/etching artifacts. Now uses image_dimension/8 (clamped 8-256) for ~8 tiles per axis. Also strips alpha before enhancement and re-joins after to prevent CLAHE/normalise/linear from corrupting transparency.
This commit is contained in:
@@ -226,10 +226,12 @@ export function applyCorrections(
|
||||
// maxSlope must be an integer (Sharp requirement); skip for tiny images
|
||||
if (toggles.contrast !== false) {
|
||||
const maxSlope = clamp(Math.round(1.0 + (intensity / 100) * 4.0 * presets.clahe), 1, 10);
|
||||
const minDim = imageSize ? Math.min(imageSize.width, imageSize.height) : 4;
|
||||
const tileSize = minDim >= 3 ? 3 : 1;
|
||||
if (maxSlope >= 2) {
|
||||
result = result.clahe({ width: tileSize, height: tileSize, maxSlope });
|
||||
const w = imageSize?.width ?? 64;
|
||||
const h = imageSize?.height ?? 64;
|
||||
const tileW = clamp(Math.round(w / 8), 8, 256);
|
||||
const tileH = clamp(Math.round(h / 8), 8, 256);
|
||||
if (maxSlope >= 2 && w >= tileW && h >= tileH) {
|
||||
result = result.clahe({ width: tileW, height: tileH, maxSlope });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user