1 | get("#348") -- rgb functions |
2 | |
3 | -- returns value between 0 and 1 |
4 | function averageBrightness(img, x1, y1, x2, y2) |
5 | local sum, count = 0, 0 |
6 | local w, h, g = img.width, img.height, img.getInt |
7 | for y=y1, y2-1 do |
8 | if y >= 0 and y < h then |
9 | for x=x1, x2-1 do |
10 | if x >= 0 and x < w then |
11 | count = count+1 |
12 | sum = sum+bright(rgb(g(x, y))) |
13 | end |
14 | end |
15 | end |
16 | end |
17 | return count == 0 and nil or sum/count |
18 | end |
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: | #507 |
Snippet name: | averageBrightness (function) |
Eternal ID of this version: | #507/1 |
Text MD5: | dc79389206223ea4da426b2e6efe083a |
Author: | stefan |
Category: | image recognition |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-03-09 18:29:15 |
Source code size: | 459 bytes / 18 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 770 / 165 |
Referenced in: | [show references] |