本文整理汇总了Python中PIL.Image.FLIP_TOP_BOTTOM属性的典型用法代码示例。如果您正苦于以下问题:Python Image.FLIP_TOP_BOTTOM属性的具体用法?Python Image.FLIP_TOP_BOTTOM怎么用?Python Image.FLIP_TOP_BOTTOM使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类PIL.Image
的用法示例。
在下文中一共展示了Image.FLIP_TOP_BOTTOM属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_orientation
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def update_orientation(image):
exif_orientation_tag = 0x0112
if hasattr(image, '_getexif'):
exif = image._getexif()
if exif != None and exif_orientation_tag in exif:
orientation = exif.get(exif_orientation_tag, 1)
log_msg('Image has EXIF Orientation: ' + str(orientation))
# orientation is 1 based, shift to zero based and flip/transpose based on 0-based values
orientation -= 1
if orientation >= 4:
image = image.transpose(Image.TRANSPOSE)
if orientation == 2 or orientation == 3 or orientation == 6 or orientation == 7:
image = image.transpose(Image.FLIP_TOP_BOTTOM)
if orientation == 1 or orientation == 2 or orientation == 5 or orientation == 6:
image = image.transpose(Image.FLIP_LEFT_RIGHT)
return image
示例2: __init__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def __init__(
self, unit, im,
min_filter=GL_LINEAR, mag_filter=GL_LINEAR,
wrap_s=GL_REPEAT, wrap_t=GL_REPEAT,
mipmap=False):
self.unit = unit
if isinstance(im, basestring):
im = Image.open(im)
im = im.convert('RGBA').transpose(Image.FLIP_TOP_BOTTOM)
self.size = width, height = im.size
data = im.tobytes()
self.handle = glGenTextures(1)
self.bind()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t)
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, data)
if mipmap:
glGenerateMipmap(GL_TEXTURE_2D)
示例3: __init__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def __init__(self, *commands, prefixes=None, strict=False):
"""Answers with image containing stylish quote."""
if not commands:
commands = ("цитата",)
super().__init__(*commands, prefixes=prefixes, strict=strict)
self.q = Image.open(self.get_path("q.png")).resize((40, 40), Image.LANCZOS)
self.qf = self.q.copy().transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.FLIP_TOP_BOTTOM)
self.f = ImageFont.truetype(self.get_path("font.ttf"), 24)
self.fs = ImageFont.truetype(self.get_path("font.ttf"), 16)
self.fss = ImageFont.truetype(self.get_path("font.ttf"), 15)
example = self.command_example()
self.description = [f"Генератор цитат",
f"{example} [титул] - перешлите сообщение и укажите титул (по желанию) и "
"получите цитату!"]
示例4: processBackground
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def processBackground(self):
if self.data.backgroundFile == "" or os.path.isdir(self.data.backgroundFile) or not os.path.isfile(self.data.backgroundFile):
self.data.backgroundTexture = None
self.data.backgroundManualReg = []
self.updateAlignmentInConfig()
self.data.backgroundRedraw = True
return
else:
img = PILImage.open(self.data.backgroundFile)
img.thumbnail((1920, 1080), PILImage.ANTIALIAS)
img = img.transpose(PILImage.FLIP_TOP_BOTTOM)
imgBytes = BytesIO()
img.save(imgBytes, format="png")
imgBytes.seek(0)
texture = CoreImage(imgBytes, ext="png").texture
self.data.backgroundTexture = texture
if self.data.backgroundManualReg:
# Already have centers to use; just go on to warp_image
self.warp_image()
else:
# Start the manual alignment process
self.realignBackground()
示例5: vflip
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def vflip(img):
"""Vertically flip the given PIL Image.
Args:
img (PIL Image): Image to be flipped.
Returns:
PIL Image: Vertically flipped image.
"""
is_numpy = isinstance(img, np.ndarray)
if not _is_pil_image(img):
if is_numpy:
img = Image.fromarray(img)
else:
raise TypeError(
'img should be PIL Image or numpy array. \
Got {}'.format(type(img)))
img = img.transpose(Image.FLIP_TOP_BOTTOM)
if is_numpy:
img = np.array(img)
return img
示例6: __init__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def __init__(self, value):
if isinstance(value, str):
value = Path(value)
if isinstance(value, Path):
self.path = Path(value)
self._texture = loader.loadTexture(Filename.fromOsSpecific(str(value)))
self._cached_image = None # for get_pixel() method
elif isinstance(value, PandaTexture):
self._texture = value
else:
from PIL import Image
image = value
self._texture = PandaTexture()
self._texture.setup2dTexture(image.width, image.height, PandaTexture.TUnsignedByte, PandaTexture.FRgba)
self._texture.setRamImageAs(image.transpose(Image.FLIP_TOP_BOTTOM).tobytes(), image.mode)
self._cached_image = image.transpose(Image.FLIP_TOP_BOTTOM)
self.path = None
self.filtering = Texture.default_filtering
示例7: flip
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def flip(self, lr, hr):
mode = random.choice([0, 1, 2, 3])
if mode == 0:
pass
elif mode == 1:
lr = lr.transpose(Image.FLIP_LEFT_RIGHT)
hr = hr.transpose(Image.FLIP_LEFT_RIGHT)
pass
elif mode == 2:
lr = lr.transpose(Image.FLIP_TOP_BOTTOM)
hr = hr.transpose(Image.FLIP_TOP_BOTTOM)
pass
elif mode == 3:
lr = lr.transpose(Image.FLIP_LEFT_RIGHT)
hr = hr.transpose(Image.FLIP_LEFT_RIGHT)
lr = lr.transpose(Image.FLIP_TOP_BOTTOM)
hr = hr.transpose(Image.FLIP_TOP_BOTTOM)
pass
return lr, hr
示例8: load_texture
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def load_texture(path, texture):
glBindTexture(GL_TEXTURE_2D, texture)
# Set the texture wrapping parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
# Set texture filtering parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
# load image
image = Image.open(path)
image = image.transpose(Image.FLIP_TOP_BOTTOM)
img_data = image.convert("RGBA").tobytes()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_data)
return texture
# for use with pygame
示例9: transform_xy
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def transform_xy(self, x, y, rng):
if rng.uniform(0.0, 1.0) < self.chance:
x = x if not isinstance(x, ImageType) else x.transpose(Image.FLIP_TOP_BOTTOM)
y = y if not isinstance(y, ImageType) else y.transpose(Image.FLIP_TOP_BOTTOM)
return x, y
示例10: __call__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def __call__(self, img):
if random.random() < 0.5:
return img.transpose(Image.FLIP_TOP_BOTTOM)
return img
示例11: __call__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def __call__(self, images, mask):
"""Randomly flips images and their mask top to bottom.
Args:
images: the PIL.Image image to transform.
mask: the PIL.Image mask to transform.
Returns:
The PIL.Image (images, mask) tuple with either images and mask flipped or none of them flipped.
"""
if random.random() < self.p:
return [v.transpose(Image.FLIP_TOP_BOTTOM) for v in images], mask.transpose(Image.FLIP_TOP_BOTTOM)
else:
return images, mask
示例12: drawCourse
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def drawCourse(cjson):
global root
global canvas
global canvas_image
data = drawCourseAsImage(cjson)
im = Image.fromarray((255.0*data).astype(np.uint8), 'RGB').resize((image_width, image_height), Image.NEAREST)
im = im.transpose(Image.FLIP_TOP_BOTTOM)
cim = ImageTk.PhotoImage(image=im)
canvas.img = cim # Need to save reference to ImageTK
canvas.itemconfig(canvas_image, image = cim)
drawScorecard(cjson)
root.update()
示例13: train_mapper
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def train_mapper(sample):
img_path, label, crop_size, resize_size = sample
try:
img = Image.open(img_path)
# 统一图片大小
img = img.resize((resize_size, resize_size), Image.ANTIALIAS)
# 随机水平翻转
r1 = random.random()
if r1 > 0.5:
img = img.transpose(Image.FLIP_LEFT_RIGHT)
# 随机垂直翻转
r2 = random.random()
if r2 > 0.5:
img = img.transpose(Image.FLIP_TOP_BOTTOM)
# 随机角度翻转
r3 = random.randint(-3, 3)
img = img.rotate(r3, expand=False)
# 随机裁剪
r4 = random.randint(0, int(resize_size - crop_size))
r5 = random.randint(0, int(resize_size - crop_size))
box = (r4, r5, r4 + crop_size, r5 + crop_size)
img = img.crop(box)
# 把图片转换成numpy值
img = np.array(img).astype(np.float32)
# 转换成CHW
img = img.transpose((2, 0, 1))
# 转换成BGR
img = img[(2, 1, 0), :, :] / 255.0
return img, int(label)
except:
print("%s 该图片错误,请删除该图片并重新创建图像数据列表" % img_path)
# 获取训练的reader
示例14: __call__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def __call__(self, img):
"""
Args:
img (PIL.Image): Image to be flipped.
Returns:
PIL.Image: Randomly flipped image.
"""
if self.p < 0.5:
if isinstance(img, np.ndarray):
return np.flipud(img).copy()
else:
return img.transpose(Image.FLIP_TOP_BOTTOM)
return img
示例15: __call__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_TOP_BOTTOM [as 别名]
def __call__(self, img, label):
"""
Args:
img (PIL Image): Image to be flipped.
Returns:
PIL Image: Randomly flipped image.
"""
if random.random() < self.p:
img = img.transpose(Image.FLIP_LEFT_RIGHT)
label = label.transpose(Image.FLIP_LEFT_RIGHT) #left or right
if random.random() < self.p:
img = img.transpose(Image.FLIP_TOP_BOTTOM)
label = label.transpose(Image.FLIP_TOP_BOTTOM) # bottom or top
return img, label