get("#507") -- averageBrightness
ow, oh = img.width, img.height
g = math.min(ow, oh)/16 -- grid size
-- copy image and invert
pixels = {}
w, h = math.floor(ow/g), math.floor(oh/g)
for y = 0, h-1 do
for x = 0, w-1 do
x1 = math.floor(x*g+0.5)
y1 = math.floor(y*g+0.5)
x2 = math.floor((x+1)*g+0.5)
y2 = math.floor((y+1)*g+0.5)
b = averageBrightness(img, x1, y1, x2, y2)
n = math.max(0, math.min(255, math.floor(b*255+0.5)))
pixels[y*w+x+1] = n*0x010101
end
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: | 983 / 197 |
| Referenced in: | #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |