From f6b8790c28a136b0ee57f8d4aa801348efcb4b74 Mon Sep 17 00:00:00 2001 From: Charis Lanaras Date: Sun, 17 Feb 2019 23:39:46 +0100 Subject: [PATCH] fix non-squre input images --- utils/patches.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/utils/patches.py b/utils/patches.py index f130cb0..d18dbed 100644 --- a/utils/patches.py +++ b/utils/patches.py @@ -381,25 +381,25 @@ def recompose_images(a, border, size=None): # print('Patch has dimension {}'.format(patch_size)) # print('Prediction has shape {}'.format(a.shape)) - x_tiles = int(ceil(size[0]/float(patch_size))) - y_tiles = int(ceil(size[1]/float(patch_size))) + x_tiles = int(ceil(size[1]/float(patch_size))) + y_tiles = int(ceil(size[0]/float(patch_size))) # print('Tiles per image {} {}'.format(x_tiles, y_tiles)) # Initialize image # print('Image size is: {}'.format(size)) - images = np.zeros((a.shape[1], size[1], size[0])).astype(np.float32) + images = np.zeros((a.shape[1], size[0], size[1])).astype(np.float32) print(images.shape) current_patch = 0 for y in range(0, y_tiles): ypoint = y * patch_size - if ypoint > size[1] - patch_size: - ypoint = size[1] - patch_size + if ypoint > size[0] - patch_size: + ypoint = size[0] - patch_size for x in range(0, x_tiles): xpoint = x * patch_size - if xpoint > size[0] - patch_size: - xpoint = size[0] - patch_size - images[:, ypoint:ypoint+patch_size, xpoint:xpoint+patch_size] = a[current_patch, :, border:a.shape[2]-border, border:a.shape[2]-border] + if xpoint > size[1] - patch_size: + xpoint = size[1] - patch_size + images[:, ypoint:ypoint+patch_size, xpoint:xpoint+patch_size] = a[current_patch, :, border:a.shape[2]-border, border:a.shape[3]-border] current_patch += 1 return images.transpose((1, 2, 0))