# -*- coding: utf-8 -*-
"""Cutout.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1T0wwUNmgDJ22YNcAr0ovUYGlwaWLzNon
"""

import numpy as np
import random

def _Cutout(img: np.array, side: int) -> np.array:
    """
    This function is intended to be used as a data augmentation method for image classification training.

    img: a 2D or 3D numpy array, either an image or a volume formed by stacking a bunch of consecutive images
    side: an integer, the desired side length of the square/cube to be cut out of the image

    returns: the original image with between 1 & 5 squares/cubes zeroed out

    Note: if side is greater than one of the dimensions (realistically depth) then this will not work properly
    """
    ycap = img.shape[0] - side
    xcap = img.shape[1] - side
    
    nholes = random.randint(1, 5)
    ycorners = random.sample(range(0, ycap), nholes)
    xcorners = random.sample(range(0, xcap), nholes)
    
    if len(img.shape) == 3:
        dcap = img.shape[2] - side
        dcorners = random.sample(range(0, dcap), nholes)
    
    for i in range(nholes):
        if len(img.shape) == 3:
            img[ycorners[i]:ycorners[i]+side, xcorners[i]:xcorners[i]+side, dcorners[i]:dcorners[i]+side] = 0
        else:
            img[ycorners[i]:ycorners[i]+side, xcorners[i]:xcorners[i]+side] = 0
    
    return img
# -*- coding: utf-8 -*-
"""Cutout.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1T0wwUNmgDJ22YNcAr0ovUYGlwaWLzNon
"""

import numpy as np
import random

def _Cutout(img: np.array, side: int) -> np.array:
    """
    This function is intended to be used as a data augmentation method for image classification training.

    img: a 2D or 3D numpy array, either an image or a volume formed by stacking a bunch of consecutive images
    side: an integer, the desired side length of the square/cube to be cut out of the image

    returns: the original image with between 1 & 5 squares/cubes zeroed out

    Note: if side is greater than one of the dimensions (realistically depth) then this will not work properly
    """
    ycap = img.shape[0] - side
    xcap = img.shape[1] - side
    
    nholes = random.randint(1, 5)
    ycorners = random.sample(range(0, ycap), nholes)
    xcorners = random.sample(range(0, xcap), nholes)
    
    if len(img.shape) == 3:
        dcap = img.shape[2] - side
        dcorners = random.sample(range(0, dcap), nholes)
    
    for i in range(nholes):
        if len(img.shape) == 3:
            img[ycorners[i]:ycorners[i]+side, xcorners[i]:xcorners[i]+side, dcorners[i]:dcorners[i]+side] = 0
        else:
            img[ycorners[i]:ycorners[i]+side, xcorners[i]:xcorners[i]+side] = 0
    
    return img
# -*- coding: utf-8 -*- Cutout.ipynb  Automatically generated by Colaboratory.  Original file is located at     https://colab.research.google.com/drive/1T0wwUNmgDJ22YNcAr0ovUYGlwaWLzNon This function is intended to be used as a data augmentation method for image classification training.      img: a 2D or 3D numpy array, either an image or a volume formed by stacking a bunch of consecutive images     side: an integer, the desired side length of the square/cube to be cut out of the image      returns: the original image with between 1 & 5 squares/cubes zeroed out      Note: if side is greater than one of the dimensions (realistically depth) then this will not work properly