cytometer/utils.py
def resize(x, size, resample=Image.NEAREST):
    """
    Resize an image in numpy.ndarray format. PIL is used internally for the resizing.

    :param x: numpy.ndarray (row, col) or (row, col, chan) for colour images.
    :param size: (row, col)-tuple with the output size.
    :param resample: (def Image.NEAREST) An optional resampling filter. This can be one of PIL.Image.NEAREST (use
    nearest neighbour), PIL.Image.BILINEAR (linear interpolation), PIL.Image.BICUBIC (cubic spline interpolation), or
    PIL.Image.LANCZOS (a high-quality downsampling filter).
    :return: numpy.ndarray with the resized image.
    """

    if x.ndim < 2 or x.ndim > 3:
        raise ValueError('x.ndims must be 2 or 3')

    if x.ndim == 2:
        # convert to PIL image
        x = Image.fromarray(x)

        # resize image
        x = np.array(x.resize(size, resample=resample))
    else:
        y = np.zeros(shape=size + (x.shape[2],), dtype=x.dtype)
        for chan in range(x.shape[2]):
            # convert to PIL image
            aux = Image.fromarray(x[:, :, chan])

            # resize image
            y[:, :, chan] = np.array(aux.resize(size, resample=resample))
        x = y

    # convert back to numpy array
    return np.array(x)

    Resize an image in numpy.ndarray format. PIL is used internally for the resizing.

    :param x: numpy.ndarray (row, col) or (row, col, chan) for colour images.
    :param size: (row, col)-tuple with the output size.
    :param resample: (def Image.NEAREST) An optional resampling filter. This can be one of PIL.Image.NEAREST (use
    nearest neighbour), PIL.Image.BILINEAR (linear interpolation), PIL.Image.BICUBIC (cubic spline interpolation), or
    PIL.Image.LANCZOS (a high-quality downsampling filter).
    :return: numpy.ndarray with the resized image.
    
Resize an image in numpy.ndarray format. PIL is used internally for the resizing.
Resize an image in numpy . ndarray format . PIL is used internally for the resizing .
def resize(x, size, resample=Image.NEAREST):
    if x.ndim < 2 or x.ndim > 3:
        raise ValueError('x.ndims must be 2 or 3')
    if x.ndim == 2:
        x = Image.fromarray(x)
        x = np.array(x.resize(size, resample=resample))
    else:
        y = np.zeros(shape=size + (x.shape[2],), dtype=x.dtype)
        for chan in range(x.shape[2]):
            aux = Image.fromarray(x[:, :, chan])
            y[:, :, chan] = np.array(aux.resize(size, resample=resample))
        x = y
    return np.array(x)
def resize ( x , size , resample = Image . NEAREST ) : if x . ndim < 2 or x . ndim > 3 : raise ValueError ( 'x.ndims must be 2 or 3' ) if x . ndim == 2 : x = Image . fromarray ( x ) x = np . array ( x . resize ( size , resample = resample ) ) else : y = np . zeros ( shape = size + ( x . shape [ 2 ] , ) , dtype = x . dtype ) for chan in range ( x . shape [ 2 ] ) : aux = Image . fromarray ( x [ : , : , chan ] ) y [ : , : , chan ] = np . array ( aux . resize ( size , resample = resample ) ) x = y return np . array ( x )
Resize an image in numpy.ndarray format.
Resize an image in numpy . ndarray format .
"""
    Resize an image in numpy.ndarray format. PIL is used internally for the resizing.

    :param x: numpy.ndarray (row, col) or (row, col, chan) for colour images.
    :param size: (row, col)-tuple with the output size.
    :param resample: (def Image.NEAREST) An optional resampling filter. This can be one of PIL.Image.NEAREST (use
    nearest neighbour), PIL.Image.BILINEAR (linear interpolation), PIL.Image.BICUBIC (cubic spline interpolation), or
    PIL.Image.LANCZOS (a high-quality downsampling filter).
    :return: numpy.ndarray with the resized image.
    """ # convert to PIL image # resize image # convert to PIL image # resize image # convert back to numpy array
numpy.ndarray with the resized image.
numpy . ndarray with the resized image .
x
numpy.ndarray (row, col) or (row, col, chan) for colour images.
numpy . ndarray ( row col ) or ( row col chan ) for colour images .
size
(row, col)-tuple with the output size.
( row col ) - tuple with the output size .
resample
(def Image.NEAREST) An optional resampling filter. This can be one of PIL.Image.NEAREST (use
nearest neighbour), PIL.Image.BILINEAR (linear interpolation), PIL.Image.BICUBIC (cubic spline interpolation), or
PIL.Image.LANCZOS (a high-quality downsampling filter).
( def Image . NEAREST ) An optional resampling filter . This can be one of PIL . Image . NEAREST ( use nearest neighbour ) PIL . Image . BILINEAR ( linear interpolation ) PIL . Image . BICUBIC ( cubic spline interpolation ) or PIL . Image . LANCZOS ( a high - quality downsampling filter ) .