Python PIL.Image.FLIP_TOP_BOTTOM Examples
The following are 30
code examples of PIL.Image.FLIP_TOP_BOTTOM().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PIL.Image
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: predict.py From Custom-vision-service-iot-edge-raspberry-pi with MIT License | 7 votes |
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
Example #2
Source File: quote.py From sketal with MIT License | 6 votes |
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} [титул] - перешлите сообщение и укажите титул (по желанию) и " "получите цитату!"]
Example #3
Source File: texture.py From ursina with MIT License | 6 votes |
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
Example #4
Source File: preprocess.py From instance-segmentation-pytorch with GNU General Public License v3.0 | 6 votes |
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
Example #5
Source File: images_stub.py From python-compat-runtime with Apache License 2.0 | 6 votes |
def _CorrectOrientation(self, image, orientation): """Use PIL to correct the image orientation based on its EXIF. See JEITA CP-3451 at http://www.exif.org/specifications.html, Exif 2.2, page 18. Args: image: source PIL.Image.Image object. orientation: integer in range (1,8) inclusive, corresponding the image orientation from EXIF. Returns: PIL.Image.Image with transforms performed on it. If no correction was done, it returns the input image. """ if orientation == 2: image = image.transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 3: image = image.rotate(180) elif orientation == 4: image = image.transpose(Image.FLIP_TOP_BOTTOM) elif orientation == 5: image = image.transpose(Image.FLIP_TOP_BOTTOM) image = image.rotate(270) elif orientation == 6: image = image.rotate(270) elif orientation == 7: image = image.transpose(Image.FLIP_LEFT_RIGHT) image = image.rotate(270) elif orientation == 8: image = image.rotate(90) return image
Example #6
Source File: utils.py From Anime-Super-Resolution with MIT License | 6 votes |
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
Example #7
Source File: core.py From pg with MIT License | 6 votes |
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)
Example #8
Source File: predict-amd64.py From Custom-vision-service-iot-edge-raspberry-pi with MIT License | 6 votes |
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
Example #9
Source File: backgroundMenu.py From GroundControl with GNU General Public License v3.0 | 6 votes |
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()
Example #10
Source File: TextureLoader.py From Learn-OpenGL-in-python with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #11
Source File: transform.py From SegAN with MIT License | 5 votes |
def __call__(self, img): return img.transpose(Image.FLIP_TOP_BOTTOM)
Example #12
Source File: augmentations.py From pytorch-semseg with MIT License | 5 votes |
def __call__(self, img, mask): if random.random() < self.p: return (img.transpose(Image.FLIP_TOP_BOTTOM), mask.transpose(Image.FLIP_TOP_BOTTOM)) return img, mask
Example #13
Source File: headless.py From moderngl-window with MIT License | 5 votes |
def render(self, time, frame_time): """Render one frame, save to png and close it""" # Fill currently bound framebuffer with while background self.ctx.clear(1, 1, 1, 1) # Render the geometry self.vao.render(mode=moderngl.TRIANGLES) # Wait for all rendering calls to finish (Might not be needed) self.ctx.finish() image = Image.frombytes('RGBA', self.wnd.fbo.size, self.wnd.fbo.read(components=4)) image = image.transpose(Image.FLIP_TOP_BOTTOM) image.save('triangle.png', format='png') self.wnd.close()
Example #14
Source File: extract_edof.py From dual-camera-edof with GNU General Public License v2.0 | 5 votes |
def extract_edof(data, idx, fname): if data[idx + 4:idx + 8] != b'edof': print("ERROR: Frame is not EDOF") return False idx += 8 columns = int.from_bytes(data[idx + 16: idx + 18], byteorder='little') rows = int.from_bytes(data[idx + 18: idx + 20], byteorder='little') print("\t* found EDOF at %d with geometry=%dx%d" % (idx, columns, rows)) orientation = data[idx + 7] idx += 68 img = Image.frombuffer('L', (columns, rows), data[idx:], 'raw', 'L', 0, 0) if orientation == 0x10: img = img.transpose(Image.FLIP_TOP_BOTTOM) elif orientation == 0x12: img = img.transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 0x13: img = img.transpose(Image.TRANSPOSE) if show_edof: img.show() if save_edof: outfname = (''.join(fname.split('.')[:-1])) + '-EDOF.png' print("\t * saving to %s" % outfname) img.save(outfname) return True
Example #15
Source File: renderer.py From strike-with-a-pose with GNU General Public License v3.0 | 5 votes |
def set_up_obj(self, obj_f, mtl_f): (packed_arrays, vertices) = parse_obj_file(obj_f) self.hom_vertices = np.hstack([vertices, np.ones(len(vertices))[:, None]]) (mtl_infos, sub_objs) = parse_mtl_file(mtl_f) render_objs = [] vbos = {} vaos = {} textures = {} for sub_obj in sub_objs: if sub_obj not in packed_arrays: print("Skipping {0}.".format(sub_obj)) continue render_objs.append(sub_obj) packed_array = packed_arrays[sub_obj] vbo = self.ctx.buffer(packed_array.flatten().astype("f4").tobytes()) vbos[sub_obj] = vbo # Recall that "in_vert", "in_norm", and "in_text" are the inputs to the # vertex shader. vao = self.ctx.simple_vertex_array( self.prog, vbo, "in_vert", "in_norm", "in_text" ) vaos[sub_obj] = vao if "map_Kd" in mtl_infos[sub_obj]: texture_f = mtl_infos[sub_obj]["map_Kd"] texture_img = ( Image.open("/".join(obj_f.split("/")[:-1]) + "/" + texture_f) .transpose(Image.FLIP_TOP_BOTTOM) .convert("RGBA") ) # Initialize texture from image. texture = self.ctx.texture(texture_img.size, 4, texture_img.tobytes()) texture.build_mipmaps() textures[sub_obj] = texture self.mtl_infos = mtl_infos self.render_objs = render_objs self.vbos = vbos self.vaos = vaos self.textures = textures
Example #16
Source File: preprocess.py From AutoDL with Apache License 2.0 | 5 votes |
def augmentation(sample, is_training): """ augmentation """ image_array = sample.reshape(3, image_size, image_size) rgb_array = np.transpose(image_array, (1, 2, 0)) img = Image.fromarray(rgb_array, 'RGB') if is_training: # pad and crop img = ImageOps.expand(img, (4, 4, 4, 4), fill=0) # pad to 40 * 40 * 3 left_top = np.random.randint(9, size=2) # rand 0 - 8 img = img.crop((left_top[0], left_top[1], left_top[0] + image_size, left_top[1] + image_size)) if FLAGS.random_flip_left_right: if np.random.randint(2): img = img.transpose(Image.FLIP_LEFT_RIGHT) if FLAGS.random_flip_up_down: if np.random.randint(2): img = img.transpose(Image.FLIP_TOP_BOTTOM) if FLAGS.random_brightness: delta = np.random.uniform(-0.3, 0.3) + 1. img = ImageEnhance.Brightness(img).enhance(delta) img = np.array(img).astype(np.float32) # per_image_standardization img_float = img / 255.0 num_pixels = img_float.size img_mean = img_float.mean() img_std = img_float.std() scale = np.maximum(np.sqrt(num_pixels), img_std) img = (img_float - img_mean) / scale img = np.transpose(img, (2, 0, 1)) return img
Example #17
Source File: utils.py From DTC with MIT License | 5 votes |
def __call__(self, old_image): xtranslation, ytranslation = np.random.randint(-self.max_translation, self.max_translation + 1, size=2) xpad, ypad = abs(xtranslation), abs(ytranslation) xsize, ysize = old_image.size flipped_lr = old_image.transpose(Image.FLIP_LEFT_RIGHT) flipped_tb = old_image.transpose(Image.FLIP_TOP_BOTTOM) flipped_both = old_image.transpose(Image.ROTATE_180) new_image = Image.new("RGB", (xsize + 2 * xpad, ysize + 2 * ypad)) new_image.paste(old_image, (xpad, ypad)) new_image.paste(flipped_lr, (xpad + xsize - 1, ypad)) new_image.paste(flipped_lr, (xpad - xsize + 1, ypad)) new_image.paste(flipped_tb, (xpad, ypad + ysize - 1)) new_image.paste(flipped_tb, (xpad, ypad - ysize + 1)) new_image.paste(flipped_both, (xpad - xsize + 1, ypad - ysize + 1)) new_image.paste(flipped_both, (xpad + xsize - 1, ypad - ysize + 1)) new_image.paste(flipped_both, (xpad - xsize + 1, ypad + ysize - 1)) new_image.paste(flipped_both, (xpad + xsize - 1, ypad + ysize - 1)) new_image = new_image.crop((xpad - xtranslation, ypad - ytranslation, xpad + xsize - xtranslation, ypad + ysize - ytranslation)) return new_image
Example #18
Source File: functional.py From Facial-Expression-Recognition.Pytorch with MIT License | 5 votes |
def vflip(img): """Vertically flip the given PIL Image. Args: img (PIL Image): Image to be flipped. Returns: PIL Image: Vertically flipped image. """ if not _is_pil_image(img): raise TypeError('img should be PIL Image. Got {}'.format(type(img))) return img.transpose(Image.FLIP_TOP_BOTTOM)
Example #19
Source File: functional.py From SPG with MIT License | 5 votes |
def vflip(img): """Vertically flip the given PIL Image. Args: img (PIL Image): Image to be flipped. Returns: PIL Image: Vertically flipped image. """ if not _is_pil_image(img): raise TypeError('img should be PIL Image. Got {}'.format(type(img))) return img.transpose(Image.FLIP_TOP_BOTTOM)
Example #20
Source File: functional.py From ACoL with MIT License | 5 votes |
def vflip(img): """Vertically flip the given PIL Image. Args: img (PIL Image): Image to be flipped. Returns: PIL Image: Vertically flipped image. """ if not _is_pil_image(img): raise TypeError('img should be PIL Image. Got {}'.format(type(img))) return img.transpose(Image.FLIP_TOP_BOTTOM)
Example #21
Source File: windows.py From ATX with Apache License 2.0 | 5 votes |
def screen(self): """PIL Image of current window screen. reference: https://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx""" hwnd = win32gui.GetDesktopWindow() left, top, right, bottom = self.rect width, height = right-left, bottom-top # copy bits to temporary dc win32gui.BitBlt(self._hdcmem, 0, 0, width, height, self._hdcwin, left, top, win32con.SRCCOPY) # read bits into buffer windll.gdi32.GetDIBits(self._hdcmem, self._hbmp.handle, 0, height, self._buf, ctypes.byref(self._bi), win32con.DIB_RGB_COLORS) # make a PIL Image img = Image.frombuffer('RGB', (width, height), self._buf, 'raw', 'BGRX', 0, 1) img = img.transpose(Image.FLIP_TOP_BOTTOM) return img
Example #22
Source File: heightmap.py From shadow-mapper with ISC License | 5 votes |
def to_image(self): data = self.heights rescaled = (255.0 / data.max() * (data - data.min())).astype(numpy.uint8) return Image.fromarray(rescaled).transpose(Image.FLIP_TOP_BOTTOM)
Example #23
Source File: shadowmap.py From shadow-mapper with ISC License | 5 votes |
def to_image(self): data = self.render() rescaled = (255.0 / data.max() * (data - data.min())).astype(numpy.uint8) return Image.fromarray(rescaled).transpose(Image.FLIP_TOP_BOTTOM)
Example #24
Source File: img_pil.py From Tickeys-linux with MIT License | 5 votes |
def save(filename, width, height, fmt, pixels, flipped=False): image = PILImage.fromstring(fmt.upper(), (width, height), pixels) if flipped: image = image.transpose(PILImage.FLIP_TOP_BOTTOM) image.save(filename) return True # register
Example #25
Source File: img_pil.py From Tickeys-linux with MIT License | 5 votes |
def save(filename, width, height, fmt, pixels, flipped=False): image = PILImage.fromstring(fmt.upper(), (width, height), pixels) if flipped: image = image.transpose(PILImage.FLIP_TOP_BOTTOM) image.save(filename) return True # register
Example #26
Source File: transform.py From MCD_DA with MIT License | 5 votes |
def __call__(self, img): if random.random() < 0.5: return img.transpose(Image.FLIP_TOP_BOTTOM) return img
Example #27
Source File: transform.py From MCD_DA with MIT License | 5 votes |
def __call__(self, img): return img.transpose(Image.FLIP_TOP_BOTTOM)
Example #28
Source File: dataset.py From BraTs with MIT License | 5 votes |
def vflip(img): """Vertically flip the given PIL Image. Args: img (PIL Image): Image to be flipped. Returns: PIL Image: Vertically flipped image. """ if not _is_pil_image(img): raise TypeError('img should be PIL Image. Got {}'.format(type(img))) return img.transpose(Image.FLIP_TOP_BOTTOM)
Example #29
Source File: datasets.py From amdim-public with MIT License | 5 votes |
def __call__(self, old_image): xtranslation, ytranslation = np.random.randint(-self.max_translation, self.max_translation + 1, size=2) xpad, ypad = abs(xtranslation), abs(ytranslation) xsize, ysize = old_image.size flipped_lr = old_image.transpose(Image.FLIP_LEFT_RIGHT) flipped_tb = old_image.transpose(Image.FLIP_TOP_BOTTOM) flipped_both = old_image.transpose(Image.ROTATE_180) new_image = Image.new("RGB", (xsize + 2 * xpad, ysize + 2 * ypad)) new_image.paste(old_image, (xpad, ypad)) new_image.paste(flipped_lr, (xpad + xsize - 1, ypad)) new_image.paste(flipped_lr, (xpad - xsize + 1, ypad)) new_image.paste(flipped_tb, (xpad, ypad + ysize - 1)) new_image.paste(flipped_tb, (xpad, ypad - ysize + 1)) new_image.paste(flipped_both, (xpad - xsize + 1, ypad - ysize + 1)) new_image.paste(flipped_both, (xpad + xsize - 1, ypad - ysize + 1)) new_image.paste(flipped_both, (xpad - xsize + 1, ypad + ysize - 1)) new_image.paste(flipped_both, (xpad + xsize - 1, ypad + ysize - 1)) new_image = new_image.crop((xpad - xtranslation, ypad - ytranslation, xpad + xsize - xtranslation, ypad + ysize - ytranslation)) return new_image
Example #30
Source File: voc_utils.py From Pytorch-Project-Template with MIT License | 5 votes |
def __call__(self, img): if random.random() < 0.5: return img.transpose(Image.FLIP_TOP_BOTTOM) return img