1 | get("#348") -- rgb functions |
2 | get("#388") -- rect functions |
3 | |
4 | w, h = img.width, img.height |
5 | g = 3 -- grid size |
6 | maxBlackPixels = g-1 |
7 | minSize = {20, 20} -- exclude the really small white spaces |
8 | gw, gh = math.floor(w/g), math.floor(h/g) -- width & height of grid |
9 | |
10 | function makeGrid() |
11 | grid = {} |
12 | for gy = 0, h-g, g do |
13 | for gx = 0, w-g, g do |
14 | local black = 0 |
15 | for y = gy, gy+g-1 do |
16 | for x = gx, gx+g-1 do |
17 | local b = bright(rgb(img.getInt(x, y))) |
18 | if b < 0.94 then |
19 | black = black+1 |
20 | if black > maxBlackPixels then |
21 | goto next |
22 | end |
23 | end |
24 | end |
25 | end |
26 | grid[(gy/g)*gw+(gx/g)+1] = true |
27 | ::next:: |
28 | end |
29 | end |
30 | end |
31 | |
32 | -- stack layout: {{x, y}, ...} |
33 | local r |
34 | function fill(stack) |
35 | while #stack > 0 do |
36 | local x, y = unpack(stack[#stack]) |
37 | stack[#stack] = nil |
38 | |
39 | if not (x < 0 or y < 0 or x >= gw or y >= gh) then |
40 | local idx = y*gw+x+1 |
41 | |
42 | if grid[idx] then |
43 | grid[idx] = nil |
44 | local me = newRectangle(x, y, 1, 1) |
45 | if r == nil then |
46 | r = me |
47 | else |
48 | r = mergeRectangles(r, me) |
49 | end |
50 | |
51 | stack[#stack+1] = {x-1, y} |
52 | stack[#stack+1] = {x+1, y} |
53 | stack[#stack+1] = {x, y-1} |
54 | stack[#stack+1] = {x, y+1} |
55 | end |
56 | end |
57 | end |
58 | end |
59 | |
60 | function makeSpaces() |
61 | spaces = {} |
62 | for y = 0, gh-1 do |
63 | for x = 0, gw-1 do |
64 | r = nil -- must be global |
65 | fill {{x, y, 1}} |
66 | if r and r.width >= minSize[1] and r.height >= minSize[2] then |
67 | --table.insert(result, (x*g).."/"..(y*g).."-"..c) |
68 | r = scaleRectangle(r, g) |
69 | --r = shrinkRectangle(r, img) |
70 | table.insert(spaces, r) |
71 | end |
72 | end |
73 | end |
74 | end |
Began life as a copy of #444
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Image | Result | Result calculated |
---|---|---|
#419 | java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... | 2016-07-31 20:46:50 [raw result] [visualize] |
Snippet ID: | #446 |
Snippet name: | White Spaces (include) |
Eternal ID of this version: | #446/1 |
Text MD5: | df0b414d714f4fb0e5e32c9c60a740df |
Author: | stefan |
Category: | image recognition |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-02-10 21:55:04 |
Source code size: | 1794 bytes / 74 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 957 / 164 |
Referenced in: | [show references] |