Converted from Scipy V1.1.0 Resize an image. Parameters ---------- arr : ndarray The array of image to be resized. size : int, float or tuple * int - Percentage of current size. * float - Fraction of current size. * tuple - Size of the out
(arr,
size,
interp: str ='bilinear',
mode=None)
| 3 | |
| 4 | |
| 5 | def imresize(arr, |
| 6 | size, |
| 7 | interp: str ='bilinear', |
| 8 | mode=None): |
| 9 | """ |
| 10 | Converted from Scipy V1.1.0 |
| 11 | |
| 12 | Resize an image. |
| 13 | |
| 14 | Parameters |
| 15 | ---------- |
| 16 | arr : ndarray |
| 17 | The array of image to be resized. |
| 18 | size : int, float or tuple |
| 19 | * int - Percentage of current size. |
| 20 | * float - Fraction of current size. |
| 21 | * tuple - Size of the output image (height, width). |
| 22 | |
| 23 | interp : str, optional |
| 24 | Interpolation to use for re-sizing ('nearest', 'lanczos', 'bilinear', |
| 25 | 'bicubic' or 'cubic'). |
| 26 | mode : str, optional |
| 27 | The PIL image mode ('P', 'L', etc.) to convert `arr` before resizing. |
| 28 | If ``mode=None`` (the default), 2-D images will be treated like |
| 29 | ``mode='L'``, i.e. casting to long integer. For 3-D and 4-D arrays, |
| 30 | `mode` will be set to ``'RGB'`` and ``'RGBA'`` respectively. |
| 31 | |
| 32 | Returns |
| 33 | ------- |
| 34 | imresize : ndarray |
| 35 | The resized array of image. |
| 36 | """ |
| 37 | |
| 38 | im = Image.fromarray(arr, mode=mode) |
| 39 | ts = type(size) |
| 40 | if numpy.issubdtype(ts, numpy.signedinteger): |
| 41 | percent = size / 100.0 |
| 42 | size = tuple((array(im.size)*percent).astype(int)) |
| 43 | elif numpy.issubdtype(type(size), numpy.floating): |
| 44 | size = tuple((array(im.size)*size).astype(int)) |
| 45 | else: |
| 46 | size = (size[1], size[0]) |
| 47 | func = {'nearest': 0, 'lanczos': 1, 'bilinear': 2, 'bicubic': 3, 'cubic': 3} |
| 48 | imnew = im.resize(size, resample=func[interp]) |
| 49 | return numpy.asarray(imnew) |
no outgoing calls
no test coverage detected