python-imaging-library

Mode Mismatch when merging images with PIL

删除回忆录丶 提交于 2021-01-28 02:06:24
问题 I am passing the name of a .jpg file. def split_image_into_bands(filename): img = Image.open(filename) data = img.getdata() red = [(d[0], 0, 0) for d in data] # List Comprehension! green = [(0, d[1], 0) for d in data] blue = [(0, 0, d[2]) for d in data] img.putdata(red) img.save(os.path.splitext(filename)[0] + "_red.jpg") img.putdata(green) img.save(os.path.splitext(filename)[0] + "_green.jpg") img.putdata(blue) img.save(os.path.splitext(filename)[0] + "_blue.jpg") # Put the 3 images back

How to use my own bitmap font in PIL.ImageFont?

六月ゝ 毕业季﹏ 提交于 2021-01-28 02:03:50
问题 I created a bitmap font, basically a 256x256 png image where each character occupies 8x8 tile. I want to use it with Pillow as ImageFont but there's no info on this in Pillow docs. It says I can load bitmap fonts like this font = ImageFont.load("arial.pil") but "PIL uses its own font file format to store bitmap fonts." so I guess png file won't work. How can I tell PIL to use said bitmap and where each character is on it? 回答1: Not a complete answer, but too much for a comment, and it may be

Scipy.misc.imread flatten argument — converting to grey scale

耗尽温柔 提交于 2021-01-28 01:50:21
问题 I'm trying to understand how this method transform an image in grey scale (if it uses a simple mean or a weighted mean) -- I have to reference this method. From the documentation I know that this method calls the convert(‘F’) method. From Pillow/PIL source code, I can find this method, however, I couldn't find what it does when the mode parameter is set to 'F'. Thank you. 回答1: In the docstring of the convert method of the Image object (seen in the code that you linked to), there is this: When

Remove anti-aliasing from an image

青春壹個敷衍的年華 提交于 2021-01-28 01:44:46
问题 I want to remove the antialiasing from an image. This code will get the 4 major colors from an image, compare each pixel to the 4 major colors and assign the closest color. import numpy as np from PIL import Image image = Image.open('pattern_2.png') image_nd = np.array(image) image_colors = {} for row in image_nd: for pxl in row: pxl = tuple(pxl) if not image_colors.get(pxl): image_colors[pxl] = 1 else: image_colors[pxl] += 1 sorted_image_colors = sorted(image_colors, key=image_colors.get,

Problem applying binary mask to an RGB image with numpy

依然范特西╮ 提交于 2021-01-27 20:41:15
问题 I'm trying to apply a binary mask to an RGB image with numpy I found this https://stackoverflow.com/a/26843467/4628384 but I don't have permissions to write a comment yet. Anyway I'm running into a problem; Any help much appreciated. def masktoRGB(self,image,image_mask): # create mask with same dimensions as image mask = np.zeros_like(image) # copy your image_mask to all dimensions (i.e. colors) of your image for i in range(3): mask[:,:,i] = image_mask.copy() # apply the mask to your image #

How to get value of pixels which are at a certain angle from another pixel?

坚强是说给别人听的谎言 提交于 2021-01-27 18:41:12
问题 I'm trying to implement a method where I have to obtain the values of all those pixels which forms a line at a certain angle through a pixel (i, j) Consider the following code snippet sum = image.getpixel(((i - 7), (j + 2))) + image.getpixel(((i - 6), (j + 2))) + image.getpixel( ((i - 5), (j + 1))) + image.getpixel( ((i - 4), (j + 1))) + image.getpixel(((i - 3), (j + 1))) + image.getpixel(((i - 2), (j + 1))) + image.getpixel( ((i - 1), j)) + image.getpixel((i, j)) + image.getpixel(((i + 1), j

Fill PIL ImageDraw Line partially

好久不见. 提交于 2021-01-27 18:33:14
问题 I'm trying to fill a line by a different color increasingly like a progress bar. This is the image: It was created with this code from PIL import Image, ImageDraw image = Image.new("RGBA", (300, 300), color="black") draw = ImageDraw.Draw(image) width = 7 image_w, image_h = image.size coord_a = image_w / 2, width coord_b = width, image_h / 2 coord_c = image_w / 2, image_h - width coord_d = image_w - width, image_h / 2 draw.line([coord_a, coord_b, coord_c, coord_d, coord_a], fill="red", width

“Pillow was built without XCB support”

。_饼干妹妹 提交于 2021-01-27 17:39:28
问题 I'm working on a program that uses ImageGrab in Pillow. I am getting the error mentioned in the title. I notice in the documentation that it says the generic pip install Pillow doesn't come with libxcb. I tried installing libxcb with pip install libxcb , but it apparently doesn't exist as that. I tried looking around on Google for it, but none of it helped. If anybody could point me to the specific library that I need to install and commands to run, I'd appreciate it! I should mention that

How to speed up image loading in pillow (python)?

你说的曾经没有我的故事 提交于 2021-01-27 14:30:15
问题 I want to use pillow for some simple handwritten image recognition, and it will be real-time so I will need to call my function 5-10 times a second. I'm loading the image and am only accessing 1 in 20^2 pixels so I really don't need all the image. I need to reduce the image loading time. I've never used a python image library and would appreciate all suggestions. from PIL import Image import time start = time.time() im = Image.open('ir/IMG-1949.JPG') width, height = im.size px = im.load()

Python PIL How do I convert 1 bit deep images to RGBA?

守給你的承諾、 提交于 2021-01-27 12:01:56
问题 Exactly like the title. I take a single-band image of mode "1" and open it using image = Image.open("picture.tif") I then try to convert it to RGBA with image.convert("RGBA") And then whenever I check the mode of it using print(image.mode) I get that it's still "1". I've even tried this using "L" (which is another single-band image mode) and still no luck. No matter what I do, it won't convert. Searching the web only seems to reveal converting from "RGBA" to "1" but I haven't been able to