Skip to content

Commit

Permalink
Only allow for images with at least 32x32 pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
bmitzkus committed Oct 30, 2019
1 parent 55338d1 commit cb16512
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion imagecorruptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def corrupt(image, severity=1, corruption_name=None, corruption_number=-1):
Args:
image (numpy.ndarray): image to corrupt; a numpy array in [0, 255], expected datatype is np.uint8
expected shape is either (height x width x channels) or (height x width), channels must be 1 or 3
expected shape is either (height x width x channels) or (height x width);
width and height must be at least 32 pixels;
channels must be 1 or 3;
severity (int): strength with which to corrupt the image; an integer in [1, 5]
corruption_name (str): specifies which corruption function to call, must be one of
'gaussian_noise', 'shot_noise', 'impulse_noise', 'defocus_blur',
Expand All @@ -43,6 +45,9 @@ def corrupt(image, severity=1, corruption_name=None, corruption_number=-1):

height, width, channels = image.shape

if (height < 32 or width < 32):
raise AttributeError('Image width and height must be at least 32 pixels')

if not (channels in [1,3]):
raise AttributeError('Expecting image to have either 1 or 3 channels (last dimension)')

Expand Down

0 comments on commit cb16512

Please sign in to comment.