Beispiel #1
0
def byte_view(qimage, byteorder='little'):
    """Return the bytes in the view with the given byteorder."""
    raw = _qimageview(qimage)
    result = raw.view(_np.uint8).reshape(raw.shape + (-1, ))
    if byteorder and byteorder != _sys.byteorder:
        result = result[..., ::-1]
    return result
Beispiel #2
0
def byte_view(qimage, byteorder = 'little'):
    """Return the bytes in the view with the given byteorder."""
    raw = _qimageview(qimage)
    result = raw.view(_np.uint8).reshape(raw.shape + (-1, ))
    if byteorder and byteorder != _sys.byteorder:
        result = result[...,::-1]
    return result
Beispiel #3
0
def gray2qimage(array, normalize=False):
    """Convert a 2D numpy array 'array' into a 8-bit, indexed QImage with
    a specific colormap. The first dimension represents the vertical image
    axis.

    The parameter 'normalize' can be used to normalize an image's value range
    to 0 ~ 255:

        normalize = (nmin, nmax):
         scale & clip image values from nmin..nmax to 0..255

        normalize = nmax:
         lets nmin default to zero, i.e. scale & clip the range 0..nmax to
         0..255

        normalize = True:
         scale image values to 0..255 (same as passing (array.min(), 
         array.max()))

    If the source array 'array' contains masked values, the result will have 
    only 255 shades of gray, and one color map entry will be used to make the
    corresponding pixels transparent.


    """
    if _np.ndim(array) != 2:
        raise ValueError("gray2qimage can only convert 2D arrays")

    h, w = array.shape
    result = _qt.QImage(w, h, _qt.QImage.Format_Indexed8)

    array = _normalize255(array, normalize)

    for i in range(256):
        result.setColor(i, _qt.qRgb(i, i, i))

    _qimageview(result)[:] = array.clip(0, 255)

    return result
Beispiel #4
0
def gray2qimage(array, normalize=False):
    """Convert a 2D numpy array 'array' into a 8-bit, indexed QImage with
    a specific colormap. The first dimension represents the vertical image
    axis.

    The parameter 'normalize' can be used to normalize an image's value range
    to 0 ~ 255:

        normalize = (nmin, nmax):
         scale & clip image values from nmin..nmax to 0..255

        normalize = nmax:
         lets nmin default to zero, i.e. scale & clip the range 0..nmax to
         0..255

        normalize = True:
         scale image values to 0..255 (same as passing (array.min(), 
         array.max()))

    If the source array 'array' contains masked values, the result will have 
    only 255 shades of gray, and one color map entry will be used to make the
    corresponding pixels transparent.


    """
    if _np.ndim(array) != 2:
        raise ValueError("gray2qimage can only convert 2D arrays")

    h, w = array.shape
    result = _qt.QImage(w, h, _qt.QImage.Format_Indexed8)

    array = _normalize255(array, normalize)

    for i in range(256):
        result.setColor(i, _qt.qRgb(i, i, i))

    _qimageview(result)[:] = array.clip(0, 255)

    return result
Beispiel #5
0
def byte_view(qimage, byteorder = 'little'):
    raw = _qimageview(qimage)
    result = raw.view(_np.uint8).reshape(raw.shape + (-1, ))
    if byteorder and byteorder != _sys.byteorder:
        result = result[...,::-1]
    return result
Beispiel #6
0
def byte_view(qimage, byteorder='little'):
    raw = _qimageview(qimage)
    result = raw.view(_np.uint8).reshape(raw.shape + (-1, ))
    if byteorder and byteorder != _sys.byteorder:
        result = result[..., ::-1]
    return result