get("#348") -- rgb functions brightnessThreshold = 0.9 function getcrop2(img) local w, h, g = img.width, img.height, img.getInt local x1, y1, x2, y2 = 0, 0, w, h -- left side while x1 < x2 do for y=y1, y2-1 do if bright(rgb(g(x1, y))) <= brightnessThreshold then goto out0 end end x1=x1+1 end ::out0:: -- top side while y1 < y2 do for x=x1, x2-1 do if bright(rgb(g(x, y1))) <= brightnessThreshold then goto out1 end end y1=y1+1 end ::out1:: -- right side while x2 > x1 do for y=y1, y2-1 do if bright(rgb(g(x2-1, y))) <= brightnessThreshold then goto out2 end end x2=x2-1 end ::out2:: -- bottom side while y2 > y1 do for x=x1, x2-1 do if bright(rgb(g(x, y2-1))) <= brightnessThreshold then goto out3 end end y2=y2-1 end ::out3:: if x2 <= x1 or y2 <= y1 then -- weird result? return full image x1, y1, x2, y2 = 0, 0, w, h end return x1, y1, x2, y2 end
Began life as a copy of #346 Assumes light background
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