diff options
| author | adamhrv <adam@ahprojects.com> | 2019-01-14 22:25:25 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2019-01-14 22:25:25 +0100 |
| commit | df9d364e3664f45c65cac5990d3d742b990217fa (patch) | |
| tree | 8842d844a5ea8e6c87599b8683009cba23262713 /megapixels/app/utils/im_utils.py | |
| parent | 2fedd95fcee3f048c5f24333ffdb9bb4e13eafe2 (diff) | |
| parent | 3b2f0dc6d969fa323fe8775b4269e17c60192431 (diff) | |
Merge branch 'master' of github.com:adamhrv/megapixels_dev
Diffstat (limited to 'megapixels/app/utils/im_utils.py')
| -rw-r--r-- | megapixels/app/utils/im_utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/megapixels/app/utils/im_utils.py b/megapixels/app/utils/im_utils.py index e882c67f..d36c1c32 100644 --- a/megapixels/app/utils/im_utils.py +++ b/megapixels/app/utils/im_utils.py @@ -19,7 +19,19 @@ from torch.autograd import Variable from sklearn.metrics.pairwise import cosine_similarity import datetime +def ensure_pil(im): + """Ensure image is Pillow format""" + try: + im.verify() + return im + except: + return Image.fromarray(im.astype('uint8'), 'RGB') +def ensure_np(im): + """Ensure image is numpy array""" + if type(im) == np.ndarray: + return im + return np.asarray(im, np.uint8) def num_channels(im): '''Returns number of channels in numpy.ndarray image''' |
