the average grayscale of every 10x10 pixels block gets calculated and mapped to a morph. apparently it has a bug because the result does not seem to match the input image

This commit is contained in:
SallarShayegan
2025-02-09 18:48:42 +01:00
parent 37e86b0faf
commit 8dc9641ee0
12 changed files with 59 additions and 17 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

BIN
assets/.DS_Store vendored Normal file

Binary file not shown.

BIN
assets/morphs/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -33,37 +33,78 @@ function setup() {
image(img, 0, 0);
loadPixels();
let pixels2d = new Array(400);
for(let i = 0; i < 400; i++){
pixels2d[i] = new Array(260);
let pixels2d = new Array(countH);
for(let i = 0; i < countH; i++){
pixels2d[i] = new Array(countV);
}
let i = 0;
let j = 0;
let str1 = "";
for(let k = 0; k < pixels.length; k++) {
if (k%4 == 0) {
str1 += str(pixels[k]%7);
pixels2d[i][j] = pixels[k]%7;
j++;
let pixels1d = [];
for (let i = 0; i < pixels.length; i += 4)
pixels1d[i/4] = pixels[i];
/*
let averages = [];
let sum = 0;
for (let i = 0; i < pixels1d.length; i++) {
sum += pixels1d[i];
if (i%10 == 0) {
averages[i/10] = sum/10;
sum = 0;
}
if (k/4%260 == 0 && k>0) {
str1 += '\n';
}
*/
let averages = new Array(countH);
for (let i = 0; i < averages.length; i++)
averages[i] = new Array(countV/10);
let sum = 0;
let sum2 = [];
for(let k = 0; k < pixels1d.length; k++) {
//str1 += str(pixels1d[k]%count);
sum += pixels1d[k];
if (j%10 == 0) {
averages[i][j/10] = sum/10;
sum = 0;
}
pixels2d[i][j] = pixels1d[k]%count;
j++;
if (k%countV == 0 && k>0) {
//str1 += '\n';
i++;
j = 0;
}
}
console.log(pixels);
let sums = []
let averages2 = new Array(countH/10);
for (let i = 0; i < averages2.length; i++)
averages2[i] = new Array(countV/10);
for (let i = 0; i < averages.length; i++) {
for (let j = 0; j < averages[0].length; j++) {
sums[j] += averages[i][j];
if (i%10 == 0) {
averages2[i/10][j] = Math.round(sums[j]/10);
if (!averages2[i/10][j]) averages2[i/10][j] = 0;
averages2[i/10][j] %= 7;
sums[j] = 0;
}
}
}
console.log(averages2);
console.log(pixels1d);
console.log(pixels2d);
//saveStrings(str1.split('\n'), 'data.txt');
//resizeCanvas(countV*10, countH*10)
/*imageMode(CORNER);
for (let i = 0; i < countH; i++) {
for (let j = 0; j < countV; j++) {
image(morphs[i], i*size, j*size, size, size);
fill(255);
//rect(0,0,countV,countH);
imageMode(CORNER);
for (let i = 0; i < countV/10; i++) {
for (let j = 0; j < countH/10; j++) {
image(morphs[averages2[j][i]], i*size, j*size, size, size);
}
}*/
}
describe('Mona lisa - by Davincci');
}