Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

15
LINES

< > BotCompany Repo | #373 // Maximize Contrast (also convert to black/white)

Lua code - Image transformer

1  
get("#372") -- getContrast
2  
3  
_, _, min, max = getContrast(img)
4  
5  
-- copy image and invert
6  
7  
w, h = img.width, img.height
8  
pixels = {}
9  
for y = 0, h-1 do
10  
  for x = 0, w-1 do
11  
    b = bright(rgb(img.getInt(x, y)))
12  
    n = math.max(0, math.min(255, math.floor((b-min)/(max-min)*255+0.5)))
13  
    pixels[y*w+x+1] = n*0x010101
14  
  end
15  
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: #373
Snippet name: Maximize Contrast (also convert to black/white)
Eternal ID of this version: #373/1
Text MD5: ddddde999a932b220c6c3c25fe656026
Author: stefan
Category: image transformers
Type: Lua code - Image transformer
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-03 21:27:24
Source code size: 338 bytes / 15 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 758 / 192
Referenced in: [show references]