You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, mode = 'Equalize', param = '1') {
const canvas = document.createElement('canvas');
canvas.width = originalImg.naturalWidth || originalImg.width;
canvas.height = originalImg.naturalHeight || originalImg.height;
const ctx = canvas.getContext('2d');
// Draw original image
ctx.drawImage(originalImg, 0, 0);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const data = imageData.data;
const total = data.length / 4;
// Helper to convert RGB to HSL
function rgbToHsl(r, g, b) {
r /= 255; g /= 255; b /= 255;
const max = Math.max(r, g, b), min = Math.min(r, g, b);
let h = 0, s = 0, l = (max + min) / 2;
if (max !== min) {
const d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return [h, s, l];
}
// Helper to convert HSL back to RGB
function hslToRgb(h, s, l) {
let r, g, b;
if (s === 0) {
r = g = b = l;
} else {
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
};
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
return [r * 255, g * 255, b * 255];
}
const modeStr = (mode + '').toLowerCase();
// Strategy 1: Reveal LSB Steganography
if (modeStr.includes('lsb')) {
const bits = Math.max(1, Math.min(8, parseInt(param) || 1));
const mask = (1 << bits) - 1;
const mult = 255 / mask;
for (let i = 0; i < data.length; i += 4) {
data[i] = (data[i] & mask) * mult;
data[i+1] = (data[i+1] & mask) * mult;
data[i+2] = (data[i+2] & mask) * mult;
// Alpha remains unchanged
}
}
// Strategy 2: High exposure (Good for revealing text crossed out with black highlight marker)
else if (modeStr.includes('exposure') || modeStr.includes('bright')) {
const intensity = parseFloat(param) || 5;
for (let i = 0; i < data.length; i += 4) {
data[i] = Math.min(255, data[i] * intensity);
data[i+1] = Math.min(255, data[i+1] * intensity);
data[i+2] = Math.min(255, data[i+2] * intensity);
}
}
// Strategy 3: Global Histogram Equalization (Default)
// Highly effective for maximizing contrast and revealing hidden details in solid-looking image layers
else {
// Find luminance distribution
const hist = new Array(256).fill(0);
for (let i = 0; i < data.length; i += 4) {
const max = Math.max(data[i], data[i+1], data[i+2]);
const min = Math.min(data[i], data[i+1], data[i+2]);
const l = Math.round((max + min) / 2);
hist[l]++;
}
// Cumulative Distribution Function (CDF)
const cdf = new Array(256).fill(0);
cdf[0] = hist[0];
for (let i = 1; i < 256; i++) {
cdf[i] = cdf[i-1] + hist[i];
}
const minCdfVal = cdf.find(v => v > 0) || 0;
const cdfRange = total - minCdfVal;
// Equalization mapping table
const equalizedL = new Array(256);
if (cdfRange > 0) {
for (let i = 0; i < 256; i++) {
equalizedL[i] = Math.max(0, Math.min(1, (cdf[i] - minCdfVal) / cdfRange));
}
} else {
for (let i = 0; i < 256; i++) {
equalizedL[i] = i / 255;
}
}
// Apply new mapping to the image while preserving hue & saturation
for (let i = 0; i < data.length; i += 4) {
const [h, s, l] = rgbToHsl(data[i], data[i+1], data[i+2]);
const origLInt = Math.round(l * 255);
const newL = equalizedL[origLInt];
const [r, g, b] = hslToRgb(h, s, newL);
data[i] = r;
data[i+1] = g;
data[i+2] = b;
}
}
ctx.putImageData(imageData, 0, 0);
return canvas;
}
Apply Changes