Python PIL.Image.ROTATE_90 Examples
The following are 30
code examples of PIL.Image.ROTATE_90().
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
.

Example #1
Source File: test_color_lut.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_channels_order(self): g = Image.linear_gradient('L') im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90), g.transpose(Image.ROTATE_180)]) # Reverse channels by splitting and using table self.assert_image_equal( Image.merge('RGB', im.split()[::-1]), im._new(im.im.color_lut_3d('RGB', Image.LINEAR, 3, 2, 2, 2, [ 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, ])))
Example #2
Source File: test_file_libtiff.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_g4_write(self): """Checking to see that the saved image is the same as what we wrote""" test_file = "Tests/images/hopper_g4_500.tif" orig = Image.open(test_file) out = self.tempfile("temp.tif") rot = orig.transpose(Image.ROTATE_90) self.assertEqual(rot.size, (500, 500)) rot.save(out) reread = Image.open(out) self.assertEqual(reread.size, (500, 500)) self._assert_noerr(reread) self.assert_image_equal(reread, rot) self.assertEqual(reread.info['compression'], 'group4') self.assertEqual(reread.info['compression'], orig.info['compression']) self.assertNotEqual(orig.tobytes(), reread.tobytes())
Example #3
Source File: __init__.py From photobooth with GNU Affero General Public License v3.0 | 6 votes |
def __init__(self, config, comm, CameraModule): super().__init__() self._comm = comm self._cfg = config self._cam = CameraModule self._cap = None self._pic_dims = None self._is_preview = self._cfg.getBool('Photobooth', 'show_preview') self._is_keep_pictures = self._cfg.getBool('Storage', 'keep_pictures') rot_vals = {0: None, 90: Image.ROTATE_90, 180: Image.ROTATE_180, 270: Image.ROTATE_270} self._rotation = rot_vals[self._cfg.getInt('Camera', 'rotation')]
Example #4
Source File: media.py From asm3 with GNU General Public License v3.0 | 6 votes |
def rotate_image(imagedata, clockwise = True): """ Rotate an image. clockwise: Rotate 90 degrees clockwise, if false rotates anticlockwise """ try: inputd = asm3.utils.bytesio(imagedata) im = Image.open(inputd) if clockwise: im = im.transpose(Image.ROTATE_270) else: im = im.transpose(Image.ROTATE_90) output = asm3.utils.bytesio() im.save(output, "JPEG") rotated_data = output.getvalue() output.close() return rotated_data except Exception as err: asm3.al.error("failed rotating image: %s" % str(err), "media.rotate_image") return imagedata
Example #5
Source File: reconstruct.py From waifu2x-chainer with MIT License | 6 votes |
def get_tta_patterns(src, n): src_lr = src.transpose(Image.FLIP_LEFT_RIGHT) patterns = [ [src, None], [src.transpose(Image.ROTATE_90), inv(-90)], [src.transpose(Image.ROTATE_180), inv(-180)], [src.transpose(Image.ROTATE_270), inv(-270)], [src_lr, inv(0, True)], [src_lr.transpose(Image.ROTATE_90), inv(-90, True)], [src_lr.transpose(Image.ROTATE_180), inv(-180, True)], [src_lr.transpose(Image.ROTATE_270), inv(-270, True)], ] if n == 2: return [patterns[0], patterns[4]] elif n == 4: return [patterns[0], patterns[2], patterns[4], patterns[6]] elif n == 8: return patterns return [patterns[0]]
Example #6
Source File: model.py From chinese_ocr with MIT License | 6 votes |
def eval_angle(im,detectAngle=False): """ 估计图片偏移角度 @@param:im @@param:detectAngle 是否检测文字朝向 """ angle = 0 img = np.array(im) if detectAngle: angle = angle_detect(img=np.copy(img))##文字朝向检测 if angle==90: im = Image.fromarray(im).transpose(Image.ROTATE_90) elif angle==180: im = Image.fromarray(im).transpose(Image.ROTATE_180) elif angle==270: im = Image.fromarray(im).transpose(Image.ROTATE_270) img = np.array(im) return angle,img
Example #7
Source File: transforms.py From robosat with MIT License | 5 votes |
def __init__(self, p, degree): """Creates an `JointRandomRotation` instance. Args: p: the probability for rotating. """ self.p = p methods = {90: Image.ROTATE_90, 180: Image.ROTATE_180, 270: Image.ROTATE_270} if degree not in methods.keys(): raise NotImplementedError("We only support multiple of 90 degree rotations for now") self.method = methods[degree]
Example #8
Source File: dete_loader.py From Text-Recognition with GNU Lesser General Public License v2.1 | 5 votes |
def rotate(self, image, target, link, contour, angle): if angle == 0: if link is None: return image, target, contour return image, target, link, contour elif angle == 90: image = image.transpose(Image.ROTATE_90) target = target.transpose(Image.ROTATE_90) link = np.rot90(link) contour_f = self.contour_rotate(contour, 90, image.size[0], image.size[1]) elif angle == 180: image = image.transpose(Image.ROTATE_180) target = target.transpose(Image.ROTATE_180) link = np.rot90(np.rot90(link)) contour_f = self.contour_rotate(contour, 180, image.size[1], image.size[0]) elif angle == 270: image = image.transpose(Image.ROTATE_270) target = target.transpose(Image.ROTATE_270) link = np.rot90(np.rot90(np.rot90(link))) contour_f = self.contour_rotate(contour, 270, image.size[0], image.size[1]) if link is None: return image, target, contour_f return image, target, link, contour_f
Example #9
Source File: rotate_dataset.py From self-supervised-da with MIT License | 5 votes |
def rotate(self, img, rot): if rot == 0: img_rt = img elif rot == 90: img_rt = img.transpose(Image.ROTATE_90) elif rot == 180: img_rt = img.transpose(Image.ROTATE_180) elif rot == 270: img_rt = img.transpose(Image.ROTATE_270) else: raise ValueError('Rotation angles should be in [0, 90, 180, 270]') return img_rt
Example #10
Source File: controller.py From inbac with MIT License | 5 votes |
def rotate_image(self): if self.model.current_image is not None: rotated_image = self.model.current_image.transpose(Image.ROTATE_90) self.model.current_image.close() self.model.current_image = None self.display_image_on_canvas(rotated_image)
Example #11
Source File: text.py From Waveshare-E-Ink with MIT License | 5 votes |
def __init__(self, width, height, text, xtext=6, ytext=6, chars=14, font_file=None): image = Image.new('1', (width, height), WHITE) if font_file == None: font_file = FONT_DEFAULT font = ImageFont.truetype(FONT_PATH + font_file, FONT_SIZE) draw = ImageDraw.Draw(image) w = textwrap.TextWrapper(width=chars, break_long_words=False) #, replace_whitespace=False) for line in text.splitlines(): for frag in w.wrap(line): #print("Line: '%s'" % frag) width, height = font.getsize(frag) draw.text((xtext, ytext), frag, font=font, fill=BLACK) ytext += height self._image = image.transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.ROTATE_90)
Example #12
Source File: icon.py From Waveshare-E-Ink with MIT License | 5 votes |
def __init__(self, image, icon_file, xstart=14, ystart=14): icon = Image.open(icon_file).convert('RGBA') icon = icon.transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.ROTATE_90) self._name = icon_file self._image = image self._width, self._height = icon.size self._image.paste(icon, (xstart, ystart, xstart+self._width, ystart+self._height), mask=icon)
Example #13
Source File: test_image_transform.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_rotate_90_deg(self): self._test_rotate(90, Image.ROTATE_90)
Example #14
Source File: test_color_lut.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_identities(self): g = Image.linear_gradient('L') im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90), g.transpose(Image.ROTATE_180)]) # Fast test with small cubes for size in [2, 3, 5, 7, 11, 16, 17]: self.assert_image_equal(im, im._new( im.im.color_lut_3d('RGB', Image.LINEAR, *self.generate_identity_table(3, size)))) # Not so fast self.assert_image_equal(im, im._new( im.im.color_lut_3d('RGB', Image.LINEAR, *self.generate_identity_table(3, (2, 2, 65)))))
Example #15
Source File: test_color_lut.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_identities_4_channels(self): g = Image.linear_gradient('L') im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90), g.transpose(Image.ROTATE_180)]) # Red channel copied to alpha self.assert_image_equal( Image.merge('RGBA', (im.split()*2)[:4]), im._new(im.im.color_lut_3d('RGBA', Image.LINEAR, *self.generate_identity_table(4, 17))))
Example #16
Source File: test_color_lut.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_copy_alpha_channel(self): g = Image.linear_gradient('L') im = Image.merge('RGBA', [g, g.transpose(Image.ROTATE_90), g.transpose(Image.ROTATE_180), g.transpose(Image.ROTATE_270)]) self.assert_image_equal(im, im._new( im.im.color_lut_3d('RGBA', Image.LINEAR, *self.generate_identity_table(3, 17))))
Example #17
Source File: test_color_lut.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_numpy_formats(self): g = Image.linear_gradient('L') im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90), g.transpose(Image.ROTATE_180)]) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.float32)[:-1] with self.assertRaisesRegex(ValueError, "should have table_channels"): im.filter(lut) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), lambda r, g, b: (r, g, b)) lut.table = (numpy.array(lut.table, dtype=numpy.float32) .reshape((7 * 9 * 11), 3)) with self.assertRaisesRegex(ValueError, "should have table_channels"): im.filter(lut) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.float16) self.assert_image_equal(im, im.filter(lut)) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.float32) self.assert_image_equal(im, im.filter(lut)) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.float64) self.assert_image_equal(im, im.filter(lut)) lut = ImageFilter.Color3DLUT.generate((7, 9, 11), lambda r, g, b: (r, g, b)) lut.table = numpy.array(lut.table, dtype=numpy.int32) im.filter(lut) lut.table = numpy.array(lut.table, dtype=numpy.int8) im.filter(lut)
Example #18
Source File: test_color_lut.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_apply(self): lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b)) g = Image.linear_gradient('L') im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90), g.transpose(Image.ROTATE_180)]) self.assertEqual(im, im.filter(lut))
Example #19
Source File: test_image_paste.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def gradient_RGB(self): return Image.merge('RGB', [ self.gradient_L, self.gradient_L.transpose(Image.ROTATE_90), self.gradient_L.transpose(Image.ROTATE_180), ])
Example #20
Source File: test_image_paste.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def gradient_RGBA(self): return Image.merge('RGBA', [ self.gradient_L, self.gradient_L.transpose(Image.ROTATE_90), self.gradient_L.transpose(Image.ROTATE_180), self.gradient_L.transpose(Image.ROTATE_270), ])
Example #21
Source File: test_image_paste.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def gradient_RGBa(self): return Image.merge('RGBa', [ self.gradient_L, self.gradient_L.transpose(Image.ROTATE_90), self.gradient_L.transpose(Image.ROTATE_180), self.gradient_L.transpose(Image.ROTATE_270), ])
Example #22
Source File: test_imagefont.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_rotated_transposed_font_get_mask(self): # Arrange text = "mask this" font = self.get_font() orientation = Image.ROTATE_90 transposed_font = ImageFont.TransposedFont( font, orientation=orientation) # Act mask = transposed_font.getmask(text) # Assert self.assertEqual(mask.size, (13, 108))
Example #23
Source File: BFLIM.py From 3DSkit with GNU General Public License v3.0 | 5 votes |
def deswizzle(self, img): if self.verbose and self.swizzle != 0: print('Deswizzling') if self.swizzle == 4: img = img.transpose(Image.ROTATE_90) elif self.swizzle == 8: img = img.transpose(Image.ROTATE_90) img = img.transpose(Image.FLIP_TOP_BOTTOM) return img
Example #24
Source File: __init__.py From platypush with MIT License | 5 votes |
def __init__(self, fps=16, skip_frames=2, scale_factor=1, rotate=0, rawrgb_path=None, **kwargs): """ :param fps: Frames per seconds (default: 16) :param skip_frames: Number of frames to be skipped on sensor initialization/warmup (default: 2) :param scale_factor: The camera outputs 24x32 pixels artifacts. Use scale_factor to scale them up to a larger image (default: 1) :param rotate: Rotation angle in degrees (default: 0) :param rawrgb_path: Specify it if the rawrgb executable compiled from https://github.com/pimoroni/mlx90640-library is in another folder than `<directory of this file>/lib/examples`. """ from PIL import Image super().__init__(**kwargs) self._rotate_values = { 90: Image.ROTATE_90, 180: Image.ROTATE_180, 270: Image.ROTATE_270, } if not rawrgb_path: rawrgb_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib', 'examples', 'rawrgb') rawrgb_path = os.path.abspath(os.path.expanduser(rawrgb_path)) assert fps > 0 assert skip_frames >= 0 assert os.path.isfile(rawrgb_path) self.fps = fps self.rotate = rotate self.skip_frames = skip_frames self.scale_factor = scale_factor self.rawrgb_path = rawrgb_path self._capture_proc = None
Example #25
Source File: robot_backend_2.py From fluxclient with GNU Affero General Public License v3.0 | 5 votes |
def scan_oneshot(self): self.send_cmd(b"oneshot") images = [] while True: resp = self.get_resp() if resp.startswith("binary "): mime, img_buff = self.recv_binary_buff(resp) img_buff.seek(0) try: img = Image.open(img_buff) except OSError: raise RobotError("Image broken", error_symbol=("FILE_BROKEN", )) if img.size[0] >= 720: img = img.transpose(Image.ROTATE_90) fake_file = BytesIO() img.save(fake_file, "jpeg") images.append((mime, fake_file.getvalue())) else: images.append((mime, img_buff.getvalue())) elif resp == "ok": return images else: raise_error(resp)
Example #26
Source File: st7735s.py From spidriver with BSD 3-Clause "New" or "Revised" License | 5 votes |
def loadimage(self, a): im = Image.open(a) if im.size[0] > im.size[1]: im = im.transpose(Image.ROTATE_90) w = 160 * im.size[0] // im.size[1] im = im.resize((w, 160), Image.ANTIALIAS) (w, h) = im.size if w > 128: im = im.crop((w // 2 - 64, 0, w // 2 + 64, 160)) elif w < 128: c = Image.new("RGB", (128, 160)) c.paste(im, (64 - w // 2, 0)) im = c st.setAddrWindow(0, 0, 127, 159) st.writeData(as565(im.convert("RGB")))
Example #27
Source File: __init__.py From core with Apache License 2.0 | 5 votes |
def transpose_image(image, method): """"Transpose (i.e. flip or rotate in 90° multiples) an image. Given a PIL.Image ``image`` and a transposition mode ``method``, apply the respective operation: - ``PIL.Image.FLIP_LEFT_RIGHT``: all pixels get mirrored at half the width of the image - ``PIL.Image.FLIP_TOP_BOTTOM``: all pixels get mirrored at half the height of the image - ``PIL.Image.ROTATE_180``: all pixels get mirrored at both, the width and half the height of the image, i.e. the image gets rotated by 180° counter-clockwise - ``PIL.Image.ROTATE_90``: rows become columns (but counted from the right) and columns become rows, i.e. the image gets rotated by 90° counter-clockwise; width becomes height and vice versa - ``PIL.Image.ROTATE_270``: rows become columns and columns become rows (but counted from the bottom), i.e. the image gets rotated by 270° counter-clockwise; width becomes height and vice versa - ``PIL.Image.TRANSPOSE``: rows become columns and vice versa, i.e. all pixels get mirrored at the main diagonal; width becomes height and vice versa - ``PIL.Image.TRANSVERSE``: rows become columns (but counted from the right) and columns become rows (but counted from the bottom), i.e. all pixels get mirrored at the opposite diagonal; width becomes height and vice versa Return a new PIL.Image. """ LOG.debug('transposing image with %s', membername(Image, method)) return image.transpose(method)
Example #28
Source File: __init__.py From core with Apache License 2.0 | 5 votes |
def adjust_canvas_to_transposition(size, method): """Calculate the flipped image size after transposition. Given a numpy array ``size`` of an original canvas (width and height), and a transposition mode ``method`` (see ``transpose_image``), calculate the new size after transposition. Return a numpy array of the enlarged width and height. """ if method in [Image.ROTATE_90, Image.ROTATE_270, Image.TRANSPOSE, Image.TRANSVERSE]: size = size[::-1] return size
Example #29
Source File: display.py From IT8951 with MIT License | 5 votes |
def _set_rotate(self, rotate): methods = { None : None, 'CW' : Image.ROTATE_270, 'CCW' : Image.ROTATE_90, 'flip' : Image.ROTATE_180, } if rotate not in methods: raise ValueError("invalid value for 'rotate'---options are None, 'CW', 'CCW', and 'flip'") self._rotate_method = methods[rotate]
Example #30
Source File: util.py From proSR with GNU General Public License v3.0 | 5 votes |
def random_rot90(img, r=None): if r is None: r = random.random() * 4 # TODO Check and rewrite func if r < 1: return img.transpose(Image.ROTATE_90) elif r < 2: return img.transpose(Image.ROTATE_270) elif r < 3: return img.transpose(Image.ROTATE_180) else: return img