Skip to content

Random crop assumes 3-dimensional matrix (instead of 4D or 5D matrices) #34

@KingPowa

Description

@KingPowa

Hello! First of all, thanks for the useful library, I think it is extremely useful, especially the elastic transformation, which has improved sensibly my pipeline.

However, when considering the random_crop implementation:

def random_crop(img, crop_height, crop_width, crop_depth, h_start, w_start, d_start):
    height, width, depth = img.shape[:3] # Considering that here we are only taking the "space" dimensions...
    if height < crop_height or width < crop_width or depth < crop_depth:
        img = pad(img, (crop_width, crop_height, crop_depth))
        warn('image size smaller than crop size, pad by default.', UserWarning)
    else:
        x1, y1, z1, x2, y2, z2 = get_random_crop_coords(height, width, depth, crop_height, crop_width, crop_depth, h_start, w_start, d_start)
        img = img[x1:x2, y1:y2, z1:z2] # ...It is possible to use ellipsis here and admit an equal random cropping on each batch and channel: img[..., x1:x2, y1:y2, z1:z2]
    return img

it assumes that the input is 3D. I saw some similar assumptions and errors in the code and I would be interested in improving or fixing the code where it is needed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions