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

22
LINES

< > BotCompany Repo | #1015507 // bwAutoContrast - uses actual min and max

JavaX fragment (include)

1  
static BWImage bwAutoContrast(BWImage bw) {
2  
  ret bwAutoContrast(bw, 0f);
3  
}
4  
5  
// def value is usually irrelevant
6  
static BWImage bwAutoContrast(BWImage bw, float def) {
7  
  if (bw == null) null;
8  
  int w = bw.getWidth(), h = bw.getHeight();
9  
  float min = 1, max = 0;
10  
  for y to h: for x to w: {
11  
    float f = bw.getPixel(x, y);
12  
    min = min(min, f);
13  
    max = max(max, f);
14  
  }
15  
  if (min == max) ret new BWImage(w, h, def);
16  
  if (min == 0 && max == 1) ret bw;
17  
  float factor = floatRatio(1, max-min);
18  
  BWImage bw2 = new BWImage(w, h);
19  
  for y to h: for x to w:
20  
    bw2.setPixel(x, y, (bw.getPixel(x, y)-min)*factor);
21  
  ret bw2;
22  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015507
Snippet name: bwAutoContrast - uses actual min and max
Eternal ID of this version: #1015507/8
Text MD5: 3e2b82135c6790e0fa392c53c3ab4e12
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-14 23:36:30
Source code size: 646 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 496 / 510
Version history: 7 change(s)
Referenced in: [show references]