get("#348") -- rgb functions get("#388") -- rect functions get("#410") -- shrinkRectangle get("#417") -- stringRepImage w, h = img.width, img.height g = 4 -- grid size gw, gh = math.floor(w/g), math.floor(h/g) -- widht & height of grid grid = {} for gy = 0, h-g, g do for gx = 0, w-g, g do local min, max = 1, 0 for y = gy, gy+g-1 do for x = gx, gx+g-1 do local b = bright(rgb(img.getInt(x, y))) min, max = math.min(min, b), math.max(max, b) if min < 0.5 and max > 0.5 then grid[(gy/g)*gw+(gx/g)+1] = true goto next end end end ::next:: end end function fill(x, y, r) if x < 0 or y < 0 or x >= gw or y >= gh then return r end local idx = y*gw+x+1 if not grid[idx] then return r end grid[idx] = nil local me = newRectangle(x, y, 1, 1) if r == nil then r = me else r = mergeRectangles(r, me) end r = fill(x-1, y, r) r = fill(x+1, y, r) r = fill(x, y-1, r) r = fill(x, y+1, r) return r end result = {} for y = 0, gh-1 do for x = 0, gw-1 do local r = fill(x, y, nil) if r then --table.insert(result, (x*g).."/"..(y*g).."-"..c) r = scaleRectangle(r, g) r = shrinkRectangle(r, img) local cropped = {width=r.width, height=r.height, getInt = function(x, y) return img.getInt(x+r.x, y+r.y) end} local hash = stringRepImage(cropped) local line = recttostring(r).." -> "..hash print(line) table.insert(result, line) end end end return "Floodfill string rep:\n"..table.concat(result, "\n")