Filtrowanie – szum
Listing
function szum(img) { var cv = document.getElementById("canvas"); var ctx = cv.getContext("2d"); //położenie obrazka na canvas var imageX = 10; var imageY = 10; //pobranie obrazka //var img = document.getElementById("aniolek"); //wymiary obrazka var imageW = img.width; var imageH = img.height; //odrysowanie obrazka ctx.drawImage(img, imageX, imageY); //pobranie danych obrazka var imageData = ctx.getImageData(imageX, imageY, imageW, imageH); var data = imageData.data; var factor = 40; for (var i = 0; i < data.length; i += 4) { var rand = (0.5 - Math.random()) * factor; data[i] = data[i] + rand; data[i + 1] = data[i+1] + rand; data[i + 2] = data[i+2] + rand; } ctx.putImageData(imageData, imageX, imageY); }; var image = new Image(); image.src = "images/pies.jpg"; image.crossOrigin = "Anonymous"; image.onload = function() { szum(this); };