| 91 | |
| 92 | |
| 93 | def patches_from_image(img, p_size=512, p_overlap=64, p_max=800): |
| 94 | w, h = img.shape[:2] |
| 95 | patches = [] |
| 96 | if w > p_max and h > p_max: |
| 97 | w1 = list(np.arange(0, w-p_size, p_size-p_overlap, dtype=np.int)) |
| 98 | h1 = list(np.arange(0, h-p_size, p_size-p_overlap, dtype=np.int)) |
| 99 | w1.append(w-p_size) |
| 100 | h1.append(h-p_size) |
| 101 | # print(w1) |
| 102 | # print(h1) |
| 103 | for i in w1: |
| 104 | for j in h1: |
| 105 | patches.append(img[i:i+p_size, j:j+p_size,:]) |
| 106 | else: |
| 107 | patches.append(img) |
| 108 | |
| 109 | return patches |
| 110 | |
| 111 | |
| 112 | def imssave(imgs, img_path): |