當前位置: 首頁>>代碼示例>>Python>>正文


Python Image.isImageType方法代碼示例

本文整理匯總了Python中PIL.Image.isImageType方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.isImageType方法的具體用法?Python Image.isImageType怎麽用?Python Image.isImageType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PIL.Image的用法示例。


在下文中一共展示了Image.isImageType方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_bytes2image

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import isImageType [as 別名]
def test_bytes2image(self):
        # Image
        jpg = open(os.path.join(DATA_DIR, 'scooter.jpg'), 'rb').read()
        img = bytes2image(jpg)
        self.assertTrue(Image.isImageType(img))

        # DataFrame
        df_jpg = pd.DataFrame([['a', jpg]], columns=['Name', 'Image'])
        df_jpg = bytes2image(df_jpg)
        self.assertEqual(list(df_jpg.columns), ['Name', 'Image'])
        self.assertTrue(Image.isImageType(df_jpg['Image'][0]))

        # DataFrame with columns
        df_jpg = pd.DataFrame([['a', jpg]], columns=['Name', 'Image'])
        df_jpg = bytes2image(df_jpg, columns='Image')
        self.assertEqual(list(df_jpg.columns), ['Name', 'Image'])
        self.assertTrue(Image.isImageType(df_jpg['Image'][0]))

        # Unknown data
        self.assertEqual(bytes2image(10), 10) 
開發者ID:sassoftware,項目名稱:python-esppy,代碼行數:22,代碼來源:test_transformers.py

示例2: bgr2rgb

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import isImageType [as 別名]
def bgr2rgb(data, columns=None):
    '''
    Convert BGR images to RGB

    Parameters
    ----------
    data : PIL.Image or DataFrame
        The image data
    columns : string or list-of-strings, optional
        If `data` is a DataFrame, this is the list of columns that 
        contain image data.

    Returns
    -------
    :class:`PIL.Image`
        If `data` is a :class:`PIL.Image` 
    :class:`pandas.DataFrame`
        If `data` is a :class:`pandas.DataFrame`

    '''
    if hasattr(data, 'columns'):
        if len(data):
            if not columns:
                columns = list(data.columns)
            elif isinstance(columns, six.string_types):
                columns = [columns]
            for col in columns:
                if Image.isImageType(data[col].iloc[0]):
                    data[col] = data[col].apply(_bgr2rgb)
        return data

    elif Image.isImageType(data):
        return _bgr2rgb(data)

    return data 
開發者ID:sassoftware,項目名稱:python-esppy,代碼行數:37,代碼來源:transformers.py

示例3: fromimage

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import isImageType [as 別名]
def fromimage(im, flatten=0):
    """
    Return a copy of a PIL image as a numpy array.

    Parameters
    ----------
    im : PIL image
        Input image.
    flatten : bool
        If true, convert the output to grey-scale.

    Returns
    -------
    fromimage : ndarray
        The different colour bands/channels are stored in the
        third dimension, such that a grey-image is MxN, an
        RGB-image MxNx3 and an RGBA-image MxNx4.

    """
    if not Image.isImageType(im):
        raise TypeError("Input is not a PIL image.")
    if flatten:
        im = im.convert('F')
    elif im.mode == '1':
        # workaround for crash in PIL, see #1613.
        im.convert('L')

    return array(im) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:30,代碼來源:pilutil.py

示例4: _open_image_source

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import isImageType [as 別名]
def _open_image_source(self):
        if system_config.PIL_available:
            if isinstance(self._image_source, str):
                # the source is a string, so try and open as a path
                self._pil_image = Image.open(self._image_source)
                self._tk_image = ImageTk.PhotoImage(self._pil_image)

            elif Image.isImageType(self._image_source):
                # the source is a PIL Image
                self._pil_image = self._image_source
                self._tk_image = ImageTk.PhotoImage(self._pil_image)

            elif isinstance(self._image_source, (PhotoImage, ImageTk.PhotoImage)):
                self._tk_image = self._image_source

            else:
                raise Exception("Image must be a file path, PIL.Image or tkinter.PhotoImage")

        else:
            if isinstance(self._image_source, str):
                self._tk_image = PhotoImage(file=self._image_source)

            elif isinstance(self._image_source, PhotoImage):
                self._tk_image = self._image_source

            else:
                raise Exception("Image must be a file path or tkinter.PhotoImage") 
開發者ID:lawsie,項目名稱:guizero,代碼行數:29,代碼來源:utilities.py

示例5: fromimage

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import isImageType [as 別名]
def fromimage(im, flatten=False, mode=None):
    """
    Return a copy of a PIL image as a numpy array.

    Parameters
    ----------
    im : PIL image
        Input image.
    flatten : bool
        If true, convert the output to grey-scale.
    mode : str, optional
        Mode to convert image to, e.g. ``'RGB'``.  See the Notes of the
        `imread` docstring for more details.

    Returns
    -------
    fromimage : ndarray
        The different colour bands/channels are stored in the
        third dimension, such that a grey-image is MxN, an
        RGB-image MxNx3 and an RGBA-image MxNx4.

    """
    if not Image.isImageType(im):
        raise TypeError("Input is not a PIL image.")

    if mode is not None:
        if mode != im.mode:
            im = im.convert(mode)
    elif im.mode == 'P':
        # Mode 'P' means there is an indexed "palette".  If we leave the mode
        # as 'P', then when we do `a = array(im)` below, `a` will be a 2-D
        # containing the indices into the palette, and not a 3-D array
        # containing the RGB or RGBA values.
        if 'transparency' in im.info:
            im = im.convert('RGBA')
        else:
            im = im.convert('RGB')

    if flatten:
        im = im.convert('F')
    elif im.mode == '1':
        # Workaround for crash in PIL. When im is 1-bit, the call array(im)
        # can cause a seg. fault, or generate garbage. See
        # https://github.com/scipy/scipy/issues/2138 and
        # https://github.com/python-pillow/Pillow/issues/350.
        #
        # This converts im from a 1-bit image to an 8-bit image.
        im = im.convert('L')

    a = array(im)
    return a 
開發者ID:aetros,項目名稱:aetros-cli,代碼行數:53,代碼來源:pilutil.py

示例6: fromimage

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import isImageType [as 別名]
def fromimage(im, flatten=False, mode=None):
    """
    Return a copy of a PIL image as a numpy array.

    This function is only available if Python Imaging Library (PIL) is installed.

    Parameters
    ----------
    im : PIL image
        Input image.
    flatten : bool
        If true, convert the output to grey-scale.
    mode : str, optional
        Mode to convert image to, e.g. ``'RGB'``.  See the Notes of the
        `imread` docstring for more details.

    Returns
    -------
    fromimage : ndarray
        The different colour bands/channels are stored in the
        third dimension, such that a grey-image is MxN, an
        RGB-image MxNx3 and an RGBA-image MxNx4.

    """
    if not Image.isImageType(im):
        raise TypeError("Input is not a PIL image.")

    if mode is not None:
        if mode != im.mode:
            im = im.convert(mode)
    elif im.mode == 'P':
        # Mode 'P' means there is an indexed "palette".  If we leave the mode
        # as 'P', then when we do `a = array(im)` below, `a` will be a 2-D
        # containing the indices into the palette, and not a 3-D array
        # containing the RGB or RGBA values.
        if 'transparency' in im.info:
            im = im.convert('RGBA')
        else:
            im = im.convert('RGB')

    if flatten:
        im = im.convert('F')
    elif im.mode == '1':
        # Workaround for crash in PIL. When im is 1-bit, the call array(im)
        # can cause a seg. fault, or generate garbage. See
        # https://github.com/scipy/scipy/issues/2138 and
        # https://github.com/python-pillow/Pillow/issues/350.
        #
        # This converts im from a 1-bit image to an 8-bit image.
        im = im.convert('L')

    a = array(im)
    return a 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:55,代碼來源:pilutil.py

示例7: fromimage

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import isImageType [as 別名]
def fromimage(im, flatten=False, mode=None):
    """
    Return a copy of a PIL image as a numpy array.

    This function is only available if Python Imaging Library (PIL) is installed.

    Parameters
    ----------
    im : PIL image
        Input image.
    flatten : bool
        If true, convert the output to grey-scale.
    mode : str, optional
        Mode to convert image to, e.g. ``'RGB'``.  See the Notes of the
        `imread` docstring for more details.

    Returns
    -------
    fromimage : ndarray
        The different colour bands/channels are stored in the
        third dimension, such that a grey-image is MxN, an
        RGB-image MxNx3 and an RGBA-image MxNx4.

    """
    if not pillow_installed:
        raise ImportError("The Python Imaging Library (PIL) "
                          "is required to load data from jpeg files")

    if not Image.isImageType(im):
        raise TypeError("Input is not a PIL image.")

    if mode is not None:
        if mode != im.mode:
            im = im.convert(mode)
    elif im.mode == 'P':
        # Mode 'P' means there is an indexed "palette".  If we leave the mode
        # as 'P', then when we do `a = array(im)` below, `a` will be a 2-D
        # containing the indices into the palette, and not a 3-D array
        # containing the RGB or RGBA values.
        if 'transparency' in im.info:
            im = im.convert('RGBA')
        else:
            im = im.convert('RGB')

    if flatten:
        im = im.convert('F')
    elif im.mode == '1':
        # Workaround for crash in PIL. When im is 1-bit, the call array(im)
        # can cause a seg. fault, or generate garbage. See
        # https://github.com/scipy/scipy/issues/2138 and
        # https://github.com/python-pillow/Pillow/issues/350.
        #
        # This converts im from a 1-bit image to an 8-bit image.
        im = im.convert('L')

    a = array(im)
    return a 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:59,代碼來源:_pilutil.py

示例8: scan_codes

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import isImageType [as 別名]
def scan_codes(code_types, image):
    """
    Get *code_type* codes from a PIL Image.

    *code_type* can be any of zbar supported code type [#zbar_symbologies]_:

    - **EAN/UPC**: EAN-13 (`ean13`), UPC-A (`upca`), EAN-8 (`ean8`) and UPC-E (`upce`)
    - **Linear barcode**: Code 128 (`code128`), Code 93 (`code93`), Code 39 (`code39`), Interleaved 2 of 5 (`i25`),
      DataBar (`databar`) and DataBar Expanded (`databar-exp`)
    - **2D**: QR Code (`qrcode`)
    - **Undocumented**: `ean5`, `ean2`, `composite`, `isbn13`, `isbn10`, `codabar`, `pdf417`

    .. [#zbar_symbologies] http://zbar.sourceforge.net/iphone/userguide/symbologies.html

    Args:
        code_types (list(str)): Code type(s) to search (see ``zbarlight.Symbologies`` for supported values).
        image (PIL.Image.Image): Image to scan

    returns:
        A list of *code_type* code values or None

    """
    if isinstance(code_types, str):
        code_types = [code_types]
        warnings.warn(
            'Using a str for code_types is deprecated, please use a list of str instead',
            DeprecationWarning,
        )

    # Translate symbologies
    symbologies = [
        Symbologies.get(code_type.upper())
        for code_type in set(code_types)
    ]

    # Check that all symbologies are known
    if None in symbologies:
        bad_code_types = [code_type for code_type in code_types if code_type.upper() not in Symbologies]
        raise UnknownSymbologieError('Unknown Symbologies: %s' % bad_code_types)

    # Convert the image to be used by c-extension
    if not Image.isImageType(image):
        raise RuntimeError('Bad or unknown image format')
    converted_image = image.convert('L')  # Convert image to gray scale (8 bits per pixel).
    raw = converted_image.tobytes()  # Get image data.
    width, height = converted_image.size  # Get image size.

    return zbar_code_scanner(symbologies, raw, width, height) 
開發者ID:Polyconseil,項目名稱:zbarlight,代碼行數:50,代碼來源:__init__.py


注:本文中的PIL.Image.isImageType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。