1 | get("#348") -- rgb functions |
2 | |
3 | -- returns value between 0 and 1 |
4 | -- img must be cropped already |
5 | function triangleness(img) |
6 | local w, h = img.width, img.height |
7 | local stepx = w < 40 and 1 or 4 |
8 | local stepy = h < 40 and 1 or 4 |
9 | |
10 | local total = 0 |
11 | for y = 0, h-1, stepy do |
12 | local sum = 0 |
13 | for x = 0, w-1, stepx do |
14 | sum = sum+bright(rgb(img.getInt(x, y))) |
15 | end |
16 | sum = sum/math.floor(w/stepx) |
17 | local expected = 1-(y+1)/h |
18 | total = total+math.abs(sum-expected) |
19 | end |
20 | |
21 | return 1-total/math.floor(h/stepy) |
22 | end |
Began life as a copy of #496
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
Snippet ID: | #501 |
Snippet name: | Triangle detector (standing on bottom, include, optimized) |
Eternal ID of this version: | #501/1 |
Text MD5: | 344a4d1877285082721b9e30c900480a |
Author: | stefan |
Category: | image recognition |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-03-09 00:12:51 |
Source code size: | 552 bytes / 22 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 599 / 153 |
Referenced in: | [show references] |