1 | get("#507") -- averageBrightness
|
2 | |
3 | ow, oh = img.width, img.height |
4 | |
5 | g = math.min(ow, oh)/16 -- grid size |
6 | |
7 | -- copy image and invert |
8 | |
9 | pixels = {}
|
10 | w, h = math.floor(ow/g), math.floor(oh/g) |
11 | for y = 0, h-1 do |
12 | for x = 0, w-1 do |
13 | x1 = math.floor(x*g+0.5) |
14 | y1 = math.floor(y*g+0.5) |
15 | x2 = math.floor((x+1)*g+0.5) |
16 | y2 = math.floor((y+1)*g+0.5) |
17 | |
18 | b = averageBrightness(img, x1, y1, x2, y2) |
19 | n = math.max(0, math.min(255, math.floor(b*255+0.5))) |
20 | pixels[y*w+x+1] = n*0x010101 |
21 | end |
22 | end |
Began life as a copy of #506
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: | #508 |
| Snippet name: | Shrink to 16*x (or x*16) with x >= 16 |
| Eternal ID of this version: | #508/1 |
| Text MD5: | 532de8914d57c2dc17fb25531bd8cbc3 |
| Author: | stefan |
| Category: | image transformers |
| Type: | Lua code - Image transformer |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-03-09 18:30:53 |
| Source code size: | 519 bytes / 22 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 985 / 197 |
| Referenced in: | [show references] |