Please bookmark this page to avoid losing your image tool!

Image Fishnet Removal 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, darkThreshold = 50, lightThreshold = 200, searchRadius = 1) {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');

    const width = originalImg.naturalWidth || originalImg.width;
    const height = originalImg.naturalHeight || originalImg.height;

    if (width === 0 || height === 0) {
        canvas.width = width;
        canvas.height = height;
        return canvas; 
    }

    canvas.width = width;
    canvas.height = height;
    ctx.drawImage(originalImg, 0, 0, width, height);

    // Sanitize parameters
    // parseFloat(String(param)) handles cases where params might be passed as strings.
    // Allow -1 for darkThreshold to disable dark fishnet detection.
    const cleanDarkThreshold = Math.max(-1, Math.min(255, parseFloat(String(darkThreshold))));
    // Allow 256 for lightThreshold to disable light fishnet detection.
    const cleanLightThreshold = Math.max(0, Math.min(256, parseFloat(String(lightThreshold))));
    const cleanSearchRadius = Math.max(0, Math.floor(parseFloat(String(searchRadius))));

    let imageData;
    try {
        imageData = ctx.getImageData(0, 0, width, height);
    } catch (e) {
        // If getImageData fails (e.g., tainted canvas from cross-origin image),
        // return the canvas with the original image drawn.
        return canvas;
    }
    
    const srcData = imageData.data;
    const dstData = new Uint8ClampedArray(srcData.length);

    function isFishnetPixel(r, g, b) {
        const isDark = (cleanDarkThreshold !== -1 && r <= cleanDarkThreshold && g <= cleanDarkThreshold && b <= cleanDarkThreshold);
        const isLight = (cleanLightThreshold !== 256 && r >= cleanLightThreshold && g >= cleanLightThreshold && b >= cleanLightThreshold);
        return isDark || isLight;
    }

    for (let y = 0; y < height; y++) {
        for (let x = 0; x < width; x++) {
            const F_INDEX = (y * width + x) * 4; 

            const r = srcData[F_INDEX];
            const g = srcData[F_INDEX + 1];
            const b = srcData[F_INDEX + 2];
            const a = srcData[F_INDEX + 3];

            if (isFishnetPixel(r, g, b)) {
                let R_SUM = 0, G_SUM = 0, B_SUM = 0, A_SUM = 0;
                let NEIGHBOR_COUNT = 0;

                for (let ny = Math.max(0, y - cleanSearchRadius); ny <= Math.min(height - 1, y + cleanSearchRadius); ny++) {
                    for (let nx = Math.max(0, x - cleanSearchRadius); nx <= Math.min(width - 1, x + cleanSearchRadius); nx++) {
                        if (nx === x && ny === y) {
                            continue;
                        }

                        const N_F_INDEX = (ny * width + nx) * 4;
                        const nr = srcData[N_F_INDEX];
                        const ng = srcData[N_F_INDEX + 1];
                        const nb = srcData[N_F_INDEX + 2];
                        const na = srcData[N_F_INDEX + 3];

                        if (!isFishnetPixel(nr, ng, nb)) {
                            R_SUM += nr;
                            G_SUM += ng;
                            B_SUM += nb;
                            A_SUM += na;
                            NEIGHBOR_COUNT++;
                        }
                    }
                }

                if (NEIGHBOR_COUNT > 0) {
                    dstData[F_INDEX]     = R_SUM / NEIGHBOR_COUNT;
                    dstData[F_INDEX + 1] = G_SUM / NEIGHBOR_COUNT;
                    dstData[F_INDEX + 2] = B_SUM / NEIGHBOR_COUNT;
                    dstData[F_INDEX + 3] = A_SUM / NEIGHBOR_COUNT;
                } else {
                    dstData[F_INDEX]     = r;
                    dstData[F_INDEX + 1] = g;
                    dstData[F_INDEX + 2] = b;
                    dstData[F_INDEX + 3] = a;
                }
            } else {
                dstData[F_INDEX]     = r;
                dstData[F_INDEX + 1] = g;
                dstData[F_INDEX + 2] = b;
                dstData[F_INDEX + 3] = a;
            }
        }
    }

    const outputImageData = new ImageData(dstData, width, height);
    ctx.putImageData(outputImageData, 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 Fishnet Removal Tool is designed to enhance images by detecting and removing unwanted fishnet patterns, whether they are dark or light. Users can adjust sensitivity settings to effectively filter out these patterns. This tool is particularly useful for photographers, graphic designers, and anyone interested in improving image quality by minimizing distracting textures in photos, ensuring that the final images appear cleaner and more professional.

Leave a Reply

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