python-imaging-library

How to convert list of integers to image?

蓝咒 提交于 2020-03-04 15:34:45
问题 I am using a SFM5020 fingerprint scanner and I am using pysfm library. I have a function that reads fingerprint data and gives template data of length 10909 in the form of a list. I want to convert it to an image. Can you please help me on this? I don't know the height and width, I just know the length of the template data which is 10909. Here's a section of such template data: template_data = [16, 1, 0, 0, 64, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 84, 1, 0, 0, 0, 0, 0, 255, 255,

PIL round edges and add border

孤人 提交于 2020-03-01 23:55:22
问题 I'm currently using this method to round the edges on images for my users: def _add_corners(self, im, rad=100): circle = Image.new('L', (rad * 2, rad * 2), 0) draw = ImageDraw.Draw(circle) draw.ellipse((0, 0, rad * 2, rad * 2), fill=255) alpha = Image.new('L', im.size, "white") w, h = im.size alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0)) alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad)) alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0)) alpha.paste(circle.crop(

Break long drawn text to multiple lines with Pillow

时间秒杀一切 提交于 2020-02-25 08:03:49
问题 I'm creating a small python program that draws text on a small 128x48 image. It works fine for text that only reaches width of 120, but I can't figure out how to have longer text split into an additional line. How do I go about doing so? I've attempted using textwrap3, but I couldn't get it to work with Pillow. The program creates 128x48 images files with a black background and yellow centered text, that is later supposed to be viewed on a device that outputs up to 480i, so simply making the

Break long drawn text to multiple lines with Pillow

半城伤御伤魂 提交于 2020-02-25 08:03:38
问题 I'm creating a small python program that draws text on a small 128x48 image. It works fine for text that only reaches width of 120, but I can't figure out how to have longer text split into an additional line. How do I go about doing so? I've attempted using textwrap3, but I couldn't get it to work with Pillow. The program creates 128x48 images files with a black background and yellow centered text, that is later supposed to be viewed on a device that outputs up to 480i, so simply making the

Python - Make Text Slanted with PIL Library

怎甘沉沦 提交于 2020-02-24 20:58:19
问题 I'd like to control the slantiness (italic) of a text according a given degree and direction (left or right tilt) similar as presented in the image below: I have stumble upon this great answer: How does perspective transformation work in PIL?, played with the code, and read the documentation of AFFINE but it's still isn't clear enough for me. Can someone please explain me (mathematic and logic wise), how can I do this? Thank you. 回答1: To generate some text we can use any method, here I am

extract data from the overlapping letters in a image

爱⌒轻易说出口 提交于 2020-02-24 12:21:13
问题 Input image: i want to extract the data from the image ( ocr ) code which i tried: import cv2 import textract import numpy as np img = cv2.imread('/home/ajay/Desktop/name.jpg',0) # img = cv2.imread('path_to_your_image', 0) _, blackAndWhite = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV) nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(blackAndWhite, None, None, None, 8, cv2.CV_32S) sizes = stats[1:, -1] #get CC_STAT_AREA component img2 = np.zeros((labels.shape), np

extract data from the overlapping letters in a image

牧云@^-^@ 提交于 2020-02-24 12:20:30
问题 Input image: i want to extract the data from the image ( ocr ) code which i tried: import cv2 import textract import numpy as np img = cv2.imread('/home/ajay/Desktop/name.jpg',0) # img = cv2.imread('path_to_your_image', 0) _, blackAndWhite = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV) nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(blackAndWhite, None, None, None, 8, cv2.CV_32S) sizes = stats[1:, -1] #get CC_STAT_AREA component img2 = np.zeros((labels.shape), np

Fill an image with color but keep the alpha (Color overlay in PIL)

吃可爱长大的小学妹 提交于 2020-02-24 10:52:07
问题 Basically, I'm trying to make a function that will take a given image and a color. for each pixel in the image, it will keep the original alpha value but will change the color to the given one. for example, if the function gets the arrow image below and the color red, It will output the following image: In Photoshop and other image editors, this effect called "color overlay". Is there any quick and easy way of achieving the same result in PIL? Thanks in advance! (; 回答1: One way of doing it is

Could not import PILLOW_VERSION from PIL

被刻印的时光 ゝ 提交于 2020-02-23 09:15:42
问题 While importing, Python(anaconda) gives the following error: ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' I tried removing pillow and then conda install but the error persists. Please help 回答1: Pillow 7.0.0 removed PILLOW_VERSION , you should use __version__ in your own code instead. https://pillow.readthedocs.io/en/stable/deprecations.html#pillow-version-constant Edit (2020-01-16): If using torchvision, this has been fixed in v0.5.0. To fix: Require torchvision>=0.5.0 If

Could not import PILLOW_VERSION from PIL

独自空忆成欢 提交于 2020-02-23 09:15:11
问题 While importing, Python(anaconda) gives the following error: ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' I tried removing pillow and then conda install but the error persists. Please help 回答1: Pillow 7.0.0 removed PILLOW_VERSION , you should use __version__ in your own code instead. https://pillow.readthedocs.io/en/stable/deprecations.html#pillow-version-constant Edit (2020-01-16): If using torchvision, this has been fixed in v0.5.0. To fix: Require torchvision>=0.5.0 If