static L unclusterImages(BWImage img) { int w = img.getWidth(), h = img.getHeight(); L bc = unclusterImages_findBlackCols(img); L br = unclusterImages_findBlackRows(img); if (!bc.contains(0) || !br.contains(0) || !bc.contains(w-1) || !br.contains(h-1)) null; new L 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 unclusterImages_findBlackCols(BWImage img) { new L 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 unclusterImages_findBlackRows(BWImage img) { new L 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; }