in lib/datasets/image_processor.py [0:0]
def random_crop_list(images, size, pad_size=0, order='CHW', boxes=None):
if pad_size > 0:
raise NotImplementedError()
images = [pad_image(pad_size=pad_size, image=image, order=order)
for image in images]
if order == 'CHW':
if images[0].shape[1] == size and images[0].shape[2] == size:
return images, boxes
height = images[0].shape[1]
width = images[0].shape[2]
y_offset = 0
if height > size:
y_offset = int(np.random.randint(0, height - size))
x_offset = 0
if width > size:
x_offset = int(np.random.randint(0, width - size))
cropped = [image[:, y_offset:y_offset + size, x_offset:x_offset + size]
for image in images]
assert cropped[0].shape[1] == size, "Image not cropped properly"
assert cropped[0].shape[2] == size, "Image not cropped properly"
elif order == 'HWC':
if images[0].shape[0] == size and images[0].shape[1] == size:
return images, boxes
height = images[0].shape[0]
width = images[0].shape[1]
y_offset = 0
if height > size:
y_offset = int(np.random.randint(0, height - size))
x_offset = 0
if width > size:
x_offset = int(np.random.randint(0, width - size))
cropped = [image[y_offset:y_offset + size, x_offset:x_offset + size, :]
for image in images]
assert cropped[0].shape[0] == size, "Image not cropped properly"
assert cropped[0].shape[1] == size, "Image not cropped properly"
if boxes is not None:
boxes = crop_boxes(boxes, x_offset, y_offset)
return cropped, boxes