1 | get("#348") -- rgb functions |
2 | get("#346") -- getcrop |
3 | get("#337") -- map(list, f) |
4 | get("#388") -- rectangle functions |
5 | |
6 | brightnessThreshold = 0.9 |
7 | |
8 | function horizontalsplit(img) |
9 | local function isEmpty(x) |
10 | for y=0, img.height-1 do |
11 | if bright(rgb(img.getInt(x, y))) <= brightnessThreshold then |
12 | return false |
13 | end |
14 | end |
15 | return true |
16 | end |
17 | |
18 | local lastEmpty, start = true, nil |
19 | local segments = {} |
20 | |
21 | for x=0, img.width-1 do |
22 | empty = isEmpty(x) |
23 | if empty and not lastEmpty then |
24 | table.insert(segments, {start, x}) |
25 | elseif not empty and lastEmpty then |
26 | start = x |
27 | end |
28 | lastEmpty = empty |
29 | end |
30 | |
31 | if not lastEmpty then |
32 | table.insert(segments, {start, img.width}) |
33 | end |
34 | |
35 | if #segments <= 1 then -- don't bother with only 1 segment |
36 | return {} |
37 | end |
38 | |
39 | local result = {} |
40 | for _, seg in ipairs(segments) do |
41 | local sx1, sx2 = unpack(seg) |
42 | |
43 | local cropped = { |
44 | width = sx2-sx1, |
45 | height = img.height, |
46 | getInt = function(x, y) |
47 | return img.getInt(x+sx1, y) |
48 | end |
49 | } |
50 | local x1, y1, x2, y2 = getcrop(cropped) |
51 | table.insert(result, newRectangle(x1+sx1, y1, x2-x1, y2-y1)) |
52 | end |
53 | return result |
54 | end |
Began life as a copy of #345
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 |
---|---|---|
#84 | java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... | 2016-08-01 02:54:44 [raw result] [visualize] |
#87 | java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... | 2016-08-01 02:54:44 [raw result] [visualize] |
#92 | java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... | 2016-08-01 02:54:44 [raw result] [visualize] |
#93 | java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... | 2016-08-01 02:54:44 [raw result] [visualize] |
Snippet ID: | #478 |
Snippet name: | Horizontal split with crop (include) |
Eternal ID of this version: | #478/1 |
Text MD5: | cbc8adaf3de51544d5ca7de9cbeda693 |
Author: | stefan |
Category: | |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-02-25 19:25:17 |
Source code size: | 1243 bytes / 54 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 2010 / 191 |
Referenced in: | [show references] |