Please bookmark this page to avoid losing your image tool!

Washed Out Image Fixer

(Free & Supports Bulk Upload)

Drag & drop your images here or

The result will appear here...
You can edit the below JavaScript code to customize the image tool.
function processImage(originalImg, correctionStrength = 100, saturationBoost = 20) {
    const canvas = document.createElement('canvas');
    canvas.width = originalImg.width;
    canvas.height = originalImg.height;
    
    // Draw original image to canvas
    const ctx = canvas.getContext('2d');
    ctx.drawImage(originalImg, 0, 0);

    // Parse parameters
    const strengthNum = Math.max(0, Math.min(100, parseFloat(correctionStrength))) / 100;
    const satBoostNum = Math.max(0, parseFloat(saturationBoost)) / 100;

    // If no correction is requested, return the canvas early
    if (strengthNum === 0 && satBoostNum === 0) {
        return canvas;
    }

    const imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const data = imgData.data;

    // 1. Calculate luminance histogram to find sensible minimum and maximum brightness
    const hist = new Array(256).fill(0);
    for (let i = 0; i < data.length; i += 4) {
        // Exclude completely transparent pixels from histogram
        if (data[i + 3] === 0) continue; 
        
        const r = data[i];
        const g = data[i + 1];
        const b = data[i + 2];
        const lum = Math.round(0.299 * r + 0.587 * g + 0.114 * b);
        hist[Math.min(255, Math.max(0, lum))]++;
    }

    // Use a 1% cutoff to ignore noise/outliers when figuring out contrast limits
    const totalPixels = canvas.width * canvas.height;
    const cutoff = totalPixels * 0.01; 

    let low = 0;
    let high = 255;
    let sumLow = 0;
    
    for (let i = 0; i < 256; i++) {
        sumLow += hist[i];
        if (sumLow >= cutoff) {
            low = i;
            break;
        }
    }

    let sumHigh = 0;
    for (let i = 255; i >= 0; i--) {
        sumHigh += hist[i];
        if (sumHigh >= cutoff) {
            high = i;
            break;
        }
    }

    // Ensure we don't divide by zero
    if (high <= low) {
        high = low + 1;
    }

    // 2. Interpolate limits based on the requested correction strength
    // A strength of 100% applies full Auto-Levels stretching
    const actualLow = low * strengthNum;
    const actualHigh = 255 - ((255 - high) * strengthNum);
    const stretchFactor = 255 / (actualHigh - actualLow);

    // Combine saturation boost with the correction strength
    const satFactor = 1 + (satBoostNum * strengthNum);

    // 3. Process every pixel
    for (let i = 0; i < data.length; i += 4) {
        // Skip fully transparent pixels
        if (data[i + 3] === 0) continue;

        let r = data[i];
        let g = data[i + 1];
        let b = data[i + 2];

        // Apply contrast stretch
        r = (r - actualLow) * stretchFactor;
        g = (g - actualLow) * stretchFactor;
        b = (b - actualLow) * stretchFactor;

        // Apply saturation boost to restore vibrancy to washed out colors
        if (satFactor !== 1) {
            const lum = 0.299 * r + 0.587 * g + 0.114 * b;
            r = lum + (r - lum) * satFactor;
            g = lum + (g - lum) * satFactor;
            b = lum + (b - lum) * satFactor;
        }

        // Clamp values to the safe 8-bit color range (0-255)
        data[i]     = Math.min(255, Math.max(0, r));
        data[i + 1] = Math.min(255, Math.max(0, g));
        data[i + 2] = Math.min(255, Math.max(0, b));
        // Alpha channel (data[i + 3]) remains untouched
    }

    // Put updated data back to the canvas
    ctx.putImageData(imgData, 0, 0);

    return canvas;
}

Free Image Tool Creator

Can't find the image tool you're looking for?
Create one based on your own needs now!

Description

This tool helps restore clarity and color vibrancy to faded or washed-out images. It automatically analyzes the image’s brightness levels to stretch the contrast, effectively deepening shadows and brightening highlights, while also allowing for a saturation boost to revitalize dull colors. It is ideal for enhancing old photographs, fixing poorly lit shots, or improving images that appear flat or hazy.

Leave a Reply

Your email address will not be published. Required fields are marked *