1 | brightnessThreshold = 0.9 |
2 | maxSignatureLen = 10 |
3 | |
4 | function rgb(i) |
5 | local r = bit32.band(bit32.rshift(i, 16), 255) |
6 | local g = bit32.band(bit32.rshift(i, 8), 255) |
7 | local b = bit32.band(i, 255) |
8 | return r, g, b |
9 | end |
10 | |
11 | function bright(r, g, b) |
12 | return (r+g+b)/(255*3) |
13 | end |
14 | |
15 | -- from Java class "SegmentCounter" |
16 | |
17 | function countSegments(y, flip) |
18 | local lastPix = 1 |
19 | local segments = 0 |
20 | for x = 0, (flip and h or w)-1 do |
21 | local pix = bright(rgb(flip and img.getInt(y, x) or img.getInt(x, y))) |
22 | if pix >= brightnessThreshold and lastPix < brightnessThreshold then |
23 | segments = segments+1 |
24 | end |
25 | lastPix = pix |
26 | end |
27 | if lastPix < brightnessThreshold then segments = segments+1 end |
28 | return segments |
29 | end |
30 | |
31 | function getSegmentSignature(flip) |
32 | local s = "" |
33 | |
34 | local lastN = 0 |
35 | for y = 0, (flip and w or h)-1 do |
36 | local n = math.min(countSegments(y, flip), 9) |
37 | if n ~= lastN then |
38 | if #s >= maxSignatureLen then return nil end |
39 | s = s..n |
40 | end |
41 | lastN = n |
42 | end |
43 | if lastN == 0 and #s > 0 then |
44 | s = s:sub(1, #s-1) |
45 | end |
46 | return s |
47 | end |
Began life as a copy of #334
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
2 comment(s) hidden. show
Snippet ID: | #339 |
Snippet name: | Embeddable Signature Maker |
Eternal ID of this version: | #339/1 |
Text MD5: | 841909b563987c2791a18ce0639f0773 |
Author: | stefan |
Category: | |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-01-25 01:56:44 |
Source code size: | 1113 bytes / 47 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 1198 / 198 |
Referenced in: | [show references] |