本文整理汇总了Python中PIL.ImageSequence.Iterator方法的典型用法代码示例。如果您正苦于以下问题:Python ImageSequence.Iterator方法的具体用法?Python ImageSequence.Iterator怎么用?Python ImageSequence.Iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PIL.ImageSequence
的用法示例。
在下文中一共展示了ImageSequence.Iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def __init__(self, path, size=(226, 226), transform=lambda x: x):
self.transform = transform
with Image.open(path + ".tif") as stack:
frames = []
for img in ImageSequence.Iterator(stack):
frame = torch.tensor(np.array(img).astype(float))
frames.append(frame.unsqueeze(0))
self.raw_image = torch.cat(frames, dim=0)
rois = read_roi_zip(path + ".roi.zip")
self.rois = [
torch.tensor(zip(*polygon(
roi[1]["x"], roi[1]["y"],
shape=(self.raw_image.size(1),
self.raw_image.size(2))
)), dtype=torch.long)
for roi in rois
]
示例2: test_sanity
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def test_sanity(self):
test_file = self.tempfile("temp.im")
im = hopper("RGB")
im.save(test_file)
seq = ImageSequence.Iterator(im)
index = 0
for frame in seq:
self.assert_image_equal(im, frame)
self.assertEqual(im.tell(), index)
index += 1
self.assertEqual(index, 1)
self.assertRaises(AttributeError, ImageSequence.Iterator, 0)
示例3: __init__
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def __init__(self, gifpath, master, widget, loop = False):
from PIL import Image, ImageTk, ImageSequence
self.master = master
self.widget = widget
self.loop = loop
self.cancelid = None
self.flagstop = False
self.index = 0
self.frames = []
img = Image.open(gifpath)
size = img.size
for frame in ImageSequence.Iterator(img):
static_img = ImageTk.PhotoImage(frame.convert('RGBA'))
try:
static_img.delay = int(frame.info['duration'])
except KeyError:
static_img.delay = 100
self.frames.append(static_img)
self.widget.configure(width = size[0], height = size[1])
self.initialize()
示例4: ready_gif
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def ready_gif(gif, preview=False):
from PIL import ImageSequence
#from multiprocessing import Pool
imgs = []
fm = ''
for l in open('/proc/meminfo'):
if l.startswith('MemFree:'):
fm = int(l.split()[1])
break
frame_limit = fm // msize_kb
for img in ImageSequence.Iterator(gif):
imgs.append(_ready_gif(img))#.copy())
if preview:
preview = False
show_img(imgs[0][0])
if len(imgs) >= frame_limit:
if _verbose:
#print('This file is too big to play. Limited to play only %d frames in total %d frames.' % (frame_limit, gif.n_frames))
print('This file is too big to play. Limited to play only %d frames.' % frame_limit )
break
#with Pool(4) as p:
#imgs=list(p.map(_ready_gif, imgs))
return imgs
示例5: produce
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def produce(txt,img,ver=5,err_crt = qrcode.constants.ERROR_CORRECT_H,bri = 1.0, cont = 1.0,\
colourful = False, rgba = (0,0,0,255),pixelate = False):
"""Produce QR code
:txt: QR text
:img: Image path / Image object
:ver: QR version
:err_crt: QR error correct
:bri: Brightness enhance
:cont: Contrast enhance
:colourful: If colourful mode
:rgba: color to replace black
:pixelate: pixelate
:returns: list of produced image
"""
if type(img) is Image.Image:
pass
elif type(img) is str:
img = Image.open(img)
else:
return []
frames = [produce_impl(txt,frame.copy(),ver,err_crt,bri,cont,colourful,rgba,pixelate) for frame in ImageSequence.Iterator(img)]
return frames
示例6: make_beautiful_gif
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def make_beautiful_gif(self, template: Image, avatar: Image) -> BytesIO:
gif_list = [frame.copy() for frame in ImageSequence.Iterator(avatar)]
img_list = []
num = 0
temp = None
for frame in gif_list:
template = template.convert("RGBA")
frame = frame.convert("RGBA")
# frame = frame.rotate(-30, expand=True)
# frame = frame.resize((60, 60), Image.ANTIALIAS)
template.paste(frame, (370, 45), frame)
template.paste(frame, (370, 330), frame)
# temp2.thumbnail((320, 320), Image.ANTIALIAS)
img_list.append(template)
num += 1
temp = BytesIO()
template.save(
temp, format="GIF", save_all=True, append_images=img_list, duration=0, loop=0
)
temp.name = "beautiful.gif"
if sys.getsizeof(temp) < 8000000 and sys.getsizeof(temp) > 7000000:
break
return temp
示例7: make_wheeze_gif
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def make_wheeze_gif(self, template: Image, avatar: Image) -> BytesIO:
gif_list = [frame.copy() for frame in ImageSequence.Iterator(avatar)]
img_list = []
num = 0
temp = None
for frame in gif_list:
template = template.convert("RGBA")
frame = frame.convert("RGBA")
template.paste(frame, (60, 470), frame)
img_list.append(template)
num += 1
temp = BytesIO()
template.save(
temp, format="GIF", save_all=True, append_images=img_list, duration=0, loop=0
)
temp.name = "beautiful.gif"
if sys.getsizeof(temp) < 8000000 and sys.getsizeof(temp) > 7000000:
break
return temp
示例8: _loadGIFSequence
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def _loadGIFSequence(self, imagePath):
img = Image.open(imagePath)
if any(self._offset):
ox, oy = self._offset
elif self.scale_to:
ox, oy = 0, 0
else:
ox = max(0, (self.layout.width - img.size[0]) // 2)
oy = max(0, (self.layout.height - img.size[1]) // 2)
return [self._getBufferFromImage(frame, ox, oy)
for frame in ImageSequence.Iterator(img)]
示例9: animated_gif_to_colorlists
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def animated_gif_to_colorlists(image, container=list):
"""
Given an animated GIF, return a list with a colorlist for each frame.
"""
deprecated.deprecated('util.gif.animated_gif_to_colorlists')
from PIL import ImageSequence
it = ImageSequence.Iterator(image)
return [image_to_colorlist(i, container) for i in it]
示例10: test_iterator
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def test_iterator(self):
im = Image.open('Tests/images/multipage.tiff')
i = ImageSequence.Iterator(im)
for index in range(0, im.n_frames):
self.assertEqual(i[index], next(i))
self.assertRaises(IndexError, lambda: i[index+1])
self.assertRaises(StopIteration, next, i)
示例11: _test_multipage_tiff
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def _test_multipage_tiff(self):
im = Image.open('Tests/images/multipage.tiff')
for index, frame in enumerate(ImageSequence.Iterator(im)):
frame.load()
self.assertEqual(index, im.tell())
frame.convert('RGB')
示例12: test_consecutive
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def test_consecutive(self):
im = Image.open('Tests/images/multipage.tiff')
firstFrame = None
for frame in ImageSequence.Iterator(im):
if firstFrame is None:
firstFrame = frame.copy()
for frame in ImageSequence.Iterator(im):
self.assert_image_equal(frame, firstFrame)
break
示例13: test_nonstack_dos
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def test_nonstack_dos(self):
im = Image.open(TEST_FILE)
for i, frame in enumerate(ImageSequence.Iterator(im)):
if i > 1:
self.fail("Non-stack DOS file test failed")
示例14: legofy_gif
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def legofy_gif(base_image, brick_image, output_path, size, palette_mode, dither):
'''Alternative function that legofies animated gifs, makes use of images2gif - uses numpy!'''
im = base_image
# Read original image duration
original_duration = im.info['duration']
# Split image into single frames
frames = [frame.copy() for frame in ImageSequence.Iterator(im)]
# Create container for converted images
frames_converted = []
print("Number of frames to convert: " + str(len(frames)))
# Iterate through single frames
for i, frame in enumerate(frames, 1):
print("Converting frame number " + str(i))
new_size = get_new_size(frame, brick_image, size)
frame.thumbnail(new_size, Image.ANTIALIAS)
if palette_mode:
palette = get_lego_palette(palette_mode)
frame = apply_thumbnail_effects(frame, palette, dither)
new_frame = make_lego_image(frame, brick_image)
frames_converted.append(new_frame)
# Make use of images to gif function
images2gif.writeGif(output_path, frames_converted, duration=original_duration/1000.0, dither=0, subRectangles=False)
示例15: set_source_path
# 需要导入模块: from PIL import ImageSequence [as 别名]
# 或者: from PIL.ImageSequence import Iterator [as 别名]
def set_source_path(self, path):
"""Set this image source to a new path."""
image = PILImage.open(os.path.expandvars(path))
frames = [frame.copy() for frame in ImageSequence.Iterator(image)]
for frame in frames:
frame.thumbnail((self.max_x, self.max_y), PILImage.ANTIALIAS)
self.frames = [frame.convert('RGB') for frame in frames]
self._frame_delta = 1