-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
105 lines (85 loc) · 3.67 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const { createCanvas, loadImage } = require('canvas')
class Image
{
constructor(w, h, data)
{
this.pixels = data.slice();
this.width = w;
this.height = h;
}
}
let image = new Image(13, 18,
[0xff, 0xff, 0xff, 0xc0, 0xad, 0xad, 0xad, 0xad, 0xaf, 0xe8, 0xff, 0xff, 0xff,
0xff, 0xff, 0xda, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0xff, 0xff, 0xff,
0xff, 0xff, 0xd4, 0x0, 0x0, 0x28, 0x2e, 0xe, 0x0, 0x37, 0xff, 0xff, 0xff,
0xff, 0xff, 0xd4, 0x0, 0x0, 0xdc, 0xff, 0x50, 0x0, 0x37, 0xff, 0xff, 0xff,
0xff, 0xff, 0xd4, 0x0, 0x0, 0xdc, 0xff, 0x50, 0x0, 0x37, 0xff, 0xff, 0xff,
0xff, 0xff, 0xd4, 0x0, 0x0, 0xdc, 0xff, 0x50, 0x0, 0x37, 0xff, 0xff, 0xff,
0xff, 0xff, 0xd4, 0x0, 0x0, 0xdc, 0xff, 0x50, 0x0, 0x37, 0xff, 0xff, 0xff,
0xff, 0xff, 0xd4, 0x0, 0x0, 0xdc, 0xff, 0x50, 0x0, 0x37, 0xff, 0xff, 0xff,
0xff, 0xd3, 0x42, 0x0, 0x0, 0x3a, 0x44, 0x12, 0x0, 0xe, 0x81, 0xf3, 0xff,
0xd9, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4f, 0xff,
0xb0, 0x0, 0xb, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x35, 0x0, 0xa, 0xf1,
0xad, 0x0, 0x2b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x0, 0x0, 0xe8,
0xad, 0x0, 0x2b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x0, 0x0, 0xe8,
0xad, 0x0, 0x2b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x0, 0x0, 0xe8,
0xad, 0x0, 0x2b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x0, 0x0, 0xe8,
0xad, 0x0, 0x2b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0x0, 0x0, 0xe8,
0xb2, 0x0, 0x8, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x28, 0x0, 0xe, 0xf5,
0xe8, 0x1e, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x6b, 0xff ]);
function x_axis_to_array(x_position, pixel_array)
{
column = [];
for(x=x_position, pixel_array.length > x_position; x=x+x_position;) {
column.push(pixel_array.length[x]);
}
return column;
}
function find_fully_white_columns(imageObj) {
wh =[]
for(x=0;x<imageObj.width;x++){
column = x_axis_to_array(x, imageObj.pixels);
column = column.filter(color => color != '0xffffff');
if (column.length > 0) {
wh.push(x);
}
}
return wh;
}
function read_image_from_file(f){
loadImage(f).then((image) => {
const canvas = createCanvas(image.width, image.height)
const context = canvas.getContext("2d");
context.drawImage(image, 0,0);
pixel_array=[];
for (y=0; y < image.height; y++ ) {
//console.log("row " , y, image.width , image.height)
var imageData = context.getImageData(0,y,image.width,1);
//console.log(imageData)
for(x=0; x < image.width * 4; x=x+4 ){
var [r,g,b,a] = imageData.data.slice(x, x+4)
r = r.toString(16);
if (r.length == 1) { r = "0" + r }
g = g.toString(16);
if (g.length == 1) { g = "0" + g }
b = b.toString(16);
if (b.length == 1) { b = "0" + b }
h = ("0x"+ r + g + b);
pixel_array.push(h)
}
}
console.log(pixel_array);
image = new Image(image.width, image.height, pixel_array);
return image;
}).catch(err => { console.log('oh no!', err) });
}
image = read_image_from_file("images/test0123456789.png");
console.log(image);
console.log(find_fully_white_columns(image));
// dumb idea a 1.40am
// get bounding boxes
// down grad the image into BLACK / WHITE
// find contours
// masking 2x2 slide and was a neraul net
// write a script with imagemagic to geternate model
//