reader/reader_utils.py
def random_pad_crop_image_with_label(img, size, ignore_label=255):
    """
    Random pad or crop the image to the desired shape
    :param img: the data cube, assume the label is at the last dimension
    :param size: desired size of the image
    :param ignore_label: label to be ignored
    :return: image with the desired shape
    """
    img[:, :, -1] -= ignore_label  # padded zeros will eventually become the value of ignore label
    h, w, _ = img.shape
    pad_h0, pad_h1, pad_w0, pad_w1 = 0, 0, 0, 0
    if size[0] > h:
        # need padding
        diff = size[0] - h
        if diff % 2 == 0:
            pad_h0, pad_h1 = diff // 2, diff // 2
        else:
            pad_h0 = diff // 2
            pad_h1 = diff - pad_h0
    if size[1] > w:
        # need padding
        diff = size[1] - w
        if diff % 2 == 0:
            pad_w0, pad_w1 = diff // 2, diff // 2
        else:
            pad_w0 = diff // 2
            pad_w1 = diff - pad_w0
    img = ersa_utils.pad_image(img, [pad_h0, pad_h1, pad_w0, pad_w1], mode='constant')

    img = random_crop(img, size[0], size[1])
    img[:, :, -1] += ignore_label
    return img

    Random pad or crop the image to the desired shape
    :param img: the data cube, assume the label is at the last dimension
    :param size: desired size of the image
    :param ignore_label: label to be ignored
    :return: image with the desired shape
    
Random pad or crop the image to the desired shape
Random pad or crop the image to the desired shape
def random_pad_crop_image_with_label(img, size, ignore_label=255):
    img[:, :, -1] -= ignore_label  
    h, w, _ = img.shape
    pad_h0, pad_h1, pad_w0, pad_w1 = 0, 0, 0, 0
    if size[0] > h:
        diff = size[0] - h
        if diff % 2 == 0:
            pad_h0, pad_h1 = diff // 2, diff // 2
        else:
            pad_h0 = diff // 2
            pad_h1 = diff - pad_h0
    if size[1] > w:
        diff = size[1] - w
        if diff % 2 == 0:
            pad_w0, pad_w1 = diff // 2, diff // 2
        else:
            pad_w0 = diff // 2
            pad_w1 = diff - pad_w0
    img = ersa_utils.pad_image(img, [pad_h0, pad_h1, pad_w0, pad_w1], mode='constant')
    img = random_crop(img, size[0], size[1])
    img[:, :, -1] += ignore_label
    return img
def random_pad_crop_image_with_label ( img , size , ignore_label = 255 ) : img [ : , : , - 1 ] -= ignore_label h , w , _ = img . shape pad_h0 , pad_h1 , pad_w0 , pad_w1 = 0 , 0 , 0 , 0 if size [ 0 ] > h : diff = size [ 0 ] - h if diff % 2 == 0 : pad_h0 , pad_h1 = diff // 2 , diff // 2 else : pad_h0 = diff // 2 pad_h1 = diff - pad_h0 if size [ 1 ] > w : diff = size [ 1 ] - w if diff % 2 == 0 : pad_w0 , pad_w1 = diff // 2 , diff // 2 else : pad_w0 = diff // 2 pad_w1 = diff - pad_w0 img = ersa_utils . pad_image ( img , [ pad_h0 , pad_h1 , pad_w0 , pad_w1 ] , mode = 'constant' ) img = random_crop ( img , size [ 0 ] , size [ 1 ] ) img [ : , : , - 1 ] += ignore_label return img
Random pad or crop the image to the desired shape
Random pad or crop the image to the desired shape
"""
    Random pad or crop the image to the desired shape
    :param img: the data cube, assume the label is at the last dimension
    :param size: desired size of the image
    :param ignore_label: label to be ignored
    :return: image with the desired shape
    """ # padded zeros will eventually become the value of ignore label # need padding # need padding
image with the desired shape
image with the desired shape
img
the data cube, assume the label is at the last dimension
the data cube assume the label is at the last dimension
size
desired size of the image
desired size of the image
ignore_label
label to be ignored
label to be ignored