Please bookmark this page to avoid losing your image tool!

Image Night Vision Filter Effect Tool

(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, amplification = 1.5, blueTintFactor = 0.2) {
    // Parse and validate parameters to ensure they are numbers and within expected ranges
    let numAmplification = Number(amplification);
    if (isNaN(numAmplification) || numAmplification < 0) {
        numAmplification = 1.5; // Default amplification if parsing fails or value is invalid
    }

    let numBlueTintFactor = Number(blueTintFactor);
    if (isNaN(numBlueTintFactor) || numBlueTintFactor < 0 || numBlueTintFactor > 1) {
        numBlueTintFactor = 0.2; // Default blueTintFactor if parsing fails or value is out of [0,1] range
    }

    const canvas = document.createElement('canvas');
    // Optimization hint for frequent readbacks, though for a single operation effect might be minor.
    const ctx = canvas.getContext('2d', { willReadFrequently: true });

    const imageWidth = originalImg.naturalWidth;
    const imageHeight = originalImg.naturalHeight;

    canvas.width = imageWidth;
    canvas.height = imageHeight;

    // If image dimensions are zero (e.g., image not loaded), return an empty canvas.
    if (imageWidth === 0 || imageHeight === 0) {
        return canvas;
    }

    ctx.drawImage(originalImg, 0, 0, imageWidth, imageHeight);

    // Get the image data from the canvas.
    // Note: This can throw a security error if the image is cross-origin and lacks CORS headers.
    // The problem implies originalImg is usable.
    let imageData;
    try {
        imageData = ctx.getImageData(0, 0, imageWidth, imageHeight);
    } catch (e) {
        console.error("Error getting image data: ", e);
        // Return the canvas with the original image drawn, if processing fails
        return canvas;
    }
    
    const data = imageData.data;
    
    // Iterate over each pixel (RGBA)
    for (let i = 0; i < data.length; i += 4) {
        const r = data[i];
        const g = data[i + 1];
        const b = data[i + 2];
        // const alpha = data[i + 3]; // Alpha channel is preserved

        // Calculate luminance (perceived brightness) using the standard NTSC conversion formula
        const luminance = 0.299 * r + 0.587 * g + 0.114 * b;
        
        // Amplify luminance for the night vision effect
        const amplifiedLuminance = luminance * numAmplification;
        
        // Calculate the green channel value, clamping to the 0-255 range
        // This is the primary color for the night vision effect
        const greenValue = Math.max(0, Math.min(255, Math.floor(amplifiedLuminance)));
        
        // Calculate the blue channel value, also clamped
        // This adds a common cyan-ish tint to the green, based on the blueTintFactor
        const blueValue = Math.max(0, Math.min(255, Math.floor(amplifiedLuminance * numBlueTintFactor)));

        // Apply the night vision colors
        data[i] = 0;           // Set Red channel to 0 (or a very dark green component if desired)
        data[i + 1] = greenValue;  // Set Green channel to the calculated amplified luminance
        data[i + 2] = blueValue;   // Set Blue channel to introduce a tint
        // data[i + 3] (alpha) remains unchanged
    }

    // Put the modified image data back onto the canvas
    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 Night Vision Filter Effect Tool allows users to apply a night vision effect to their images. This tool enhances the green tones of the image to simulate a night vision look, while optionally applying a blue tint for added visual effect. It is useful for creating artistic representations, enhancing visibility in low-light photographs, or for any project that requires a thematic night vision style. Users can adjust the amplification of the effect and the intensity of the blue tint to customize the final result.

Leave a Reply

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

Other Image Tools:

Image Tintype Filter Effect Application

Image Color Graduated Filter Effect Tool

Image Agfa Vista Filter Effect Application

Image Schneider Hollywood Black Magic Filter Effect Tool

Image TMax 400 Filter Effect Tool

Image Double Exposure Filter Effect Tool

Image Fujichrome Velvia 50 Filter Effect Application

Image Revolog Texture Film Filter Effect Tool

Image Lomography Metropolis Filter Effect Application

Image Variable ND Filter Effect Tool

Image 8mm Movie Film Filter Effect Application

Image TMax 100 Filter Effect Application

Image Fog Filter Effect Tool

Image Ektachrome E100 Filter Effect Application

Image RED Cinema Camera Filter Effect Tool

Image Reverse Graduated ND Filter Effect Tool

Image Kaleidoscope Filter Effect Tool

Image Platinum Palladium Print Filter Effect

Image Light Leak Filter Effect Tool

Image Moire Pattern Filter Effect Tool

Image Pull Processing Filter Effect Tool

Photo Ambrotype Filter Effect Tool

Image Cross-Screen Star Filter Effect Tool

Image Tiffen Ultra Contrast Filter Effect Application

Photo Telephoto Lens Compression Filter Effect Tool

Image Leica M6 Camera Render Filter Effect

Image Cokin Sunset Filter Effect Application

Image CineScope Aspect Ratio Filter Effect Tool

Image Ilford FP4 Plus Filter Effect Tool

Image Infrared 850nm Filter Effect Tool

Image Pentax 67 Medium Format Filter Effect Tool

Image ARRI Alexa Cinema Camera Filter Effect Enhancer

Image Cinestill 50D Filter Effect Application

Image Kodachrome 64 Filter Effect Tool

Photo Lomography Berlin Kino Filter Effect Tool

Image Fujifilm Neopan Filter Effect Tool

See All →