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

get("#372") -- getContrast

_, _, min, max = getContrast(img)

-- copy image and invert

w, h = img.width, img.height
pixels = {}
for y = 0, h-1 do
  for x = 0, w-1 do
    b = bright(rgb(img.getInt(x, y)))
    n = math.max(0, math.min(255, math.floor((b-min)/(max-min)*255+0.5)))
    pixels[y*w+x+1] = n*0x010101
  end
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: 757 / 192
Referenced in: #503 - Convert image to 1 bit (threshold 50%)
#506 - Shrink to 4*x (or x*4) with x >= 4
#3000189 - Answer for stefanreich(>> t bla)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)