static BWImage bwAutoContrast(BWImage bw) {
ret bwAutoContrast(bw, 0f);
}
// def value is usually irrelevant
static BWImage bwAutoContrast(BWImage bw, float def) {
if (bw == null) null;
int w = bw.getWidth(), h = bw.getHeight();
float min = 1, max = 0;
for y to h: for x to w: {
float f = bw.getPixel(x, y);
min = min(min, f);
max = max(max, f);
}
if (min == max) ret new BWImage(w, h, def);
if (min == 0 && max == 1) ret bw;
float factor = floatRatio(1, max-min);
BWImage bw2 = new BWImage(w, h);
for y to h: for x to w:
bw2.setPixel(x, y, (bw.getPixel(x, y)-min)*factor);
ret bw2;
}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: | 971 / 977 |
| Version history: | 7 change(s) |
| Referenced in: | [show references] |