1 | get("#507") -- averageBrightness
|
2 | |
3 | ow, oh = img.width, img.height |
4 | |
5 | g = math.min(ow, oh)/4 -- 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 #373
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: | #506 |
| Snippet name: | Shrink to 4*x (or x*4) with x >= 4 |
| Eternal ID of this version: | #506/1 |
| Text MD5: | d6e0f21b3e14bc56aa4bf3c95a9fb7af |
| 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:31:05 |
| Source code size: | 518 bytes / 22 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 979 / 211 |
| Referenced in: | [show references] |