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

24
LINES

< > BotCompany Repo | #1004642 // removeGrayBorder

JavaX fragment (include)

static BWImage removeGrayBorder(BWImage image) {
  float threshold = 0.9f;
  int w = image.getWidth(), h = image.getHeight();
  int x1 = w, x2 = 0, y1 = h, y2 = 0;
  
  // haha, slow algorithm :)
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) {
      float f = image.getPixel(x, y);
      if (f < threshold || f == 1) {
        x1 = Math.min(x1, x);
        x2 = Math.max(x2, x);
        y1 = Math.min(y1, y);
        y2 = Math.max(y2, y);
      }
    }
  if (x1 == 0 && y1 == 0 && x2 == w-1 && y2 == h-1)
    return image;
  else
    if (x2 < x1 || y2 < y1)
      null;
    else
      return image.clip(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
}

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: 480 / 497
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)