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

40
LINES

< > BotCompany Repo | #1004640 // unclusterImages

JavaX fragment (include)

static L<BWImage> unclusterImages(BWImage img) {
  int w = img.getWidth(), h = img.getHeight();
  L<Int> bc = unclusterImages_findBlackCols(img);
  L<Int> br = unclusterImages_findBlackRows(img);
  if (!bc.contains(0) || !br.contains(0)
    || !bc.contains(w-1) || !br.contains(h-1))
    null;
  new L<BWImage> images;
  for (int y = 1; y < l(br)-1; y++)
    for (int x = 1; x < l(bc)-1; x++) {
      int x1 = bc.get(x)+1, cw = bc.get(x+1)-x1;
      int y1 = br.get(y)+1, ch = br.get(y+1)-y1;
      images.add(img.clip(x1, y1, cw, ch));
    }
  ret images;
}

static L<Int> unclusterImages_findBlackCols(BWImage img) {
  new L<Int> l;
  int w = img.getWidth(), h = img.getHeight();
  outer: for (int x = 0; x < w; x++) {
    for (int y = 0; y < h; y++)
      if (img.getPixel(x, y) > 0.1f)
        continue outer;
    l.add(x);
  }
  ret l;
}

static L<Int> unclusterImages_findBlackRows(BWImage img) {
  new L<Int> l;
  int w = img.getWidth(), h = img.getHeight();
  outer: for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++)
      if (img.getPixel(x, y) > 0.1f)
        continue outer;
    l.add(y);
  }
  ret l;
}

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: #1004640
Snippet name: unclusterImages
Eternal ID of this version: #1004640/1
Text MD5: 3f07a8e4beda796e0a03f88b76d0f234
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 17:26:02
Source code size: 1165 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 473 / 467
Referenced in: [show references]