get("#348") -- rgb functions get("#388") -- rect functions get("#410") -- shrinkRectangle get("#380") -- hashImage 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 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 -- 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 result = {} for y = 0, gh-1 do for x = 0, gw-1 do r = nil 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(result, recttostring(r)) end end end return "White Spaces: "..table.concat(result, "|")