本文整理汇总了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)
示例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
示例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)
示例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")
示例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
示例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
示例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
示例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)