get("#348") -- rgb functions get("#480") -- horizontalsplit (v2) -- 4 examples, pretty printed tree = {0, 0, {0, 1, {0, 6, {0, 7, {0, 9, {4, 0, {1, 1, "p", "l"}, {1, 4, "h", "l"}}, {5, 0, "E", "D"}}, {4, 0, "n", "r"}}, "u"}, "i"}, {0, 1, {0, 2, {0, 3, "o", "s"}, "a"}, {0, 2, {0, 3, {4, 0, "e", "c"}, "t"}, {0, 3, "n", {0, 4, "s", "C"}}}}} parts = horizontalsplit(img) -- returns a list of characters function decide(tree, img) if type(tree) == 'string' then -- leaf (single character) return {tree} elseif type(tree[1]) == 'number' then -- node (decision point) local w, h = img.width, img.height local x, y, plus, minus = unpack(tree) local set = x < w and y < h and bright(rgb(img.getInt(x, y))) <= 0.5 return decide(set and plus or minus, img) else -- leaf (list of characters) return tree end end -- iterate over parts local result = {} for _, r in ipairs(parts) do local x1, y1, x2, y2 = r.x, r.y, r.x+r.width, r.y+r.height local cimg = {width=x2-x1+1, height=y2-y1+1, getInt = function(x, y) return (x < x2-x1 and y < y2-y1) and img.getInt(x1+x, y1+y) or 0xFFFFFF end} chars = decide(tree, cimg) table.insert(result, #chars == 1 and chars[1] or "["..table.concat(chars).."]") end return table.concat(result)