get("#348") -- rgb functions -- returns value between 0 and 1 function averageBrightness(img, x1, y1, x2, y2) local sum, count = 0, 0 local w, h, g = img.width, img.height, img.getInt for y=y1, y2-1 do if y >= 0 and y < h then for x=x1, x2-1 do if x >= 0 and x < w then count = count+1 sum = sum+bright(rgb(g(x, y))) end end end end return count == 0 and nil or sum/count 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: | 709 / 143 |
Referenced in: | [show references] |