get("#348") -- rgb functions get("#388") -- rect functions w, h = img.width, img.height g = 3 -- grid size maxBlackPixels = g-1 minSize = {20, 20} -- exclude the really small white spaces gw, gh = math.floor(w/g), math.floor(h/g) -- width & height of grid function makeGrid() grid = {} for gy = 0, h-g, g do for gx = 0, w-g, g do local black = 0 for y = gy, gy+g-1 do for x = gx, gx+g-1 do local b = bright(rgb(img.getInt(x, y))) if b < 0.94 then black = black+1 if black > maxBlackPixels then goto next end end end end grid[(gy/g)*gw+(gx/g)+1] = true ::next:: end end end -- stack layout: {{x, y}, ...} local r function fill(stack) while #stack > 0 do local x, y = unpack(stack[#stack]) stack[#stack] = nil if not (x < 0 or y < 0 or x >= gw or y >= gh) then local idx = y*gw+x+1 if grid[idx] then grid[idx] = nil local me = newRectangle(x, y, 1, 1) if r == nil then r = me else r = mergeRectangles(r, me) end stack[#stack+1] = {x-1, y} stack[#stack+1] = {x+1, y} stack[#stack+1] = {x, y-1} stack[#stack+1] = {x, y+1} end end end end function makeSpaces() spaces = {} for y = 0, gh-1 do for x = 0, gw-1 do r = nil -- must be global fill {{x, y, 1}} if r and r.width >= minSize[1] and r.height >= minSize[2] then --table.insert(result, (x*g).."/"..(y*g).."-"..c) r = scaleRectangle(r, g) --r = shrinkRectangle(r, img) table.insert(spaces, r) end end end 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: | 958 / 164 |
Referenced in: | [show references] |