xxxxxxxxxx
69
var thresh=10;
function preload()
{
photo=loadImage('/untitled.png');
txt= createImage(400,400);
txt.loadPixels();
photo.loadPixels();
loadStrings('untitled.txt', ldstr);
//img.resize (400,400);
}
var count=0;
function setup() {
createCanvas(400, 400);
photo.resize(400,400);
photo.loadPixels();
for(var i=1; i<photo.pixels.length; i++)
{
if(abs(photo.pixels[i]-txt.pixels[i])>thresh)
{
count++;
//else
photo.pixels[i]=0;
}
else
{
//photo.pixels[i]=255;
}
}
photo.updatePixels();
console.log("DIFF: " + count);
//image(txt,0,0);
image(photo, 0,0);
//save(photo, 'neat.jpeg');
}
function draw() {
//background(220);
}
function ldstr(instr)
{
for(var i=1; i<txt.pixels.length; i+=4)
{
txt.pixels[i]=instr[i];
txt.pixels[i+1]=instr[i+1];
txt.pixels[i+2]=instr[i+2];
txt.pixels[i+3]=instr[i+3];
}
txt.updatePixels();
console.log("Image Loaded From Text File");
}