Please bookmark this page to avoid losing your image tool!

Image To Lg Converter

(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, intensity = "1.0") {
    // Lg (Logarithmic) Transformation
    // Applies a log base 2 (lg) filter to enhance image details, especially in darker regions.
    
    const canvas = document.createElement('canvas');
    canvas.width = originalImg.width;
    canvas.height = originalImg.height;
    
    const ctx = canvas.getContext('2d');
    ctx.drawImage(originalImg, 0, 0);
    
    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    const data = imageData.data;
    
    // Parse intensity parameter to a blend factor between 0 and 1
    const blend = Math.max(0, Math.min(1, parseFloat(intensity) || 1));
    
    for (let i = 0; i < data.length; i += 4) {
        const r = data[i];
        const g = data[i + 1];
        const b = data[i + 2];
        
        // Lg (log base 2) mapping: Max input is 255, 1+255 = 256. Math.log2(256) = 8.
        // Therefore, we divide by 8 to normalize to [0, 1], then multiply by 255.
        const lg_r = 255 * (Math.log2(1 + r) / 8);
        const lg_g = 255 * (Math.log2(1 + g) / 8);
        const lg_b = 255 * (Math.log2(1 + b) / 8);
        
        // Blend between the original and the logarithmically transformed pixel using intensity
        data[i]     = (lg_r * blend) + (r * (1 - blend));
        data[i + 1] = (lg_g * blend) + (g * (1 - blend));
        data[i + 2] = (lg_b * blend) + (b * (1 - blend));
        // Alpha channel data[i + 3] remains unchanged
    }
    
    ctx.putImageData(imageData, 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

The Image To Lg Converter applies a logarithmic transformation to images to enhance detail, particularly in darker regions. By utilizing a log base 2 filter, the tool expands the dynamic range of low-intensity pixel values, making shadows and obscured details more visible. Users can adjust the intensity of the effect to blend the transformation with the original image. This tool is useful for photographers, researchers, or enthusiasts looking to improve the visibility of dark subjects in low-light photographs or medical imaging.

Leave a Reply

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