-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest.js
40 lines (37 loc) · 1018 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Jimp from "jimp";
import numeral from "numeral";
testImages(1);
async function testImages(total) {
const allImages = [];
for (let i = 0; i < total; i++) {
const num = numeral(i).format("000");
const img = await Jimp.read(`data/square${num}.png`);
let rawData = [];
for (let n = 0; n < 28 * 28; n++) {
let index = n * 4;
let r = img.bitmap.data[index + 0];
// let g = img.bitmap.data[n + 1];
// let b = img.bitmap.data[n + 2];
rawData[n] = r / 255.0;
}
const buffer = [];
for (let n = 0; n < img.length; n++) {
const val = Math.floor(rawData[n] * 255);
buffer[n * 4 + 0] = val;
buffer[n * 4 + 1] = val;
buffer[n * 4 + 2] = val;
buffer[n * 4 + 3] = 255;
}
const image = new Jimp(
{
data: Buffer.from(buffer),
width: 28,
height: 28,
},
(err, image) => {
const num = numeral(i).format("000");
image.write(`output/square${num}.png`);
}
);
}
}