1 | static BWImage removeGrayBorder(BWImage image) { |
2 | float threshold = 0.9f; |
3 | int w = image.getWidth(), h = image.getHeight(); |
4 | int x1 = w, x2 = 0, y1 = h, y2 = 0; |
5 | |
6 | // haha, slow algorithm :) |
7 | for (int y = 0; y < h; y++) |
8 | for (int x = 0; x < w; x++) { |
9 | float f = image.getPixel(x, y); |
10 | if (f < threshold || f == 1) { |
11 | x1 = Math.min(x1, x); |
12 | x2 = Math.max(x2, x); |
13 | y1 = Math.min(y1, y); |
14 | y2 = Math.max(y2, y); |
15 | } |
16 | } |
17 | if (x1 == 0 && y1 == 0 && x2 == w-1 && y2 == h-1) |
18 | return image; |
19 | else |
20 | if (x2 < x1 || y2 < y1) |
21 | null; |
22 | else |
23 | return image.clip(x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
24 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004642 |
Snippet name: | removeGrayBorder |
Eternal ID of this version: | #1004642/1 |
Text MD5: | 99af0813c35025a56de29ecab712c864 |
Author: | stefan |
Category: | javax / images |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-24 19:41:25 |
Source code size: | 678 bytes / 24 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 479 / 497 |
Referenced in: | [show references] |