python-imaging-library

Strange PIL.Image.fromarray behaviour with numpy zeros and ones in mode='1'

给你一囗甜甜゛ 提交于 2021-02-10 12:20:31
问题 There should be some kinda puzzle for me. Accordingly to PIL documentation it has different image modes (as 1, L, 8, RGB, RGBA, and so on), but I was interested about mode '1' (1-bit pixels, black and white, stored with one pixel per byte). I've created 2 matrices size 100 by 100: first only zeroes (np.zeros) and second only ones (np.ones), expecting totally black image with ones, and white image with zeros in mode '1' for Black and White image only. Picture of result Question: what I'm doing

PIL change color channel intensity

你离开我真会死。 提交于 2021-02-10 06:28:26
问题 I want to make a color picker, which recolors a png texture while preserving transparency in python3. I only want the brighter parts of the image to be recolored, but also keep the gradient. The only option the I could think of was to adjust the color channel intensity, however I did not find anything like that in the PIL docs. How do I change the color channel intensity? My PNG texture is loaded in ARGB mode and can be found >>here<<. Original Image: 回答1: I dreamt up an approach for this:

How to resize an image according to a reference point in another

百般思念 提交于 2021-02-09 10:34:34
问题 I currently have two images (im1 and im2) with pixel dimensions of (1725, 1580). im2 however possesses a large border around it that i had to create to ensure that the images were of the same size. im2 was originally (1152, 864). As such. when i overlay im2 ontop of im1 using PIL.Image.blend , im2 appears overlayed onto im1, but is a lot smaller. I have 2 distinct reference points on the images i think i could use (present on im1 and im2) to rescale im2 (zoom it in somehow?) to overlay im2

How to resize an image according to a reference point in another

人盡茶涼 提交于 2021-02-09 10:32:35
问题 I currently have two images (im1 and im2) with pixel dimensions of (1725, 1580). im2 however possesses a large border around it that i had to create to ensure that the images were of the same size. im2 was originally (1152, 864). As such. when i overlay im2 ontop of im1 using PIL.Image.blend , im2 appears overlayed onto im1, but is a lot smaller. I have 2 distinct reference points on the images i think i could use (present on im1 and im2) to rescale im2 (zoom it in somehow?) to overlay im2

Taking screenshots with PIL

若如初见. 提交于 2021-02-08 09:29:28
问题 I'm working on script that take screenshot every 1 min but there is one problem that when I save it gives me invalid argument and I don't know why that is. Code: from PIL import ImageGrab from PIL import Image import time import datetime import os def screenShot(): while True: try: date = str(datetime.date.today()) hour=str(datetime.datetime.now().strftime("%H")) os.makedirs("D:/mine/" + date + "/" + hour) except OSError,e: if e.errno != 17: raise time.sleep(1) pass while True: date = str

Preserving image type info in PIL when cropping

陌路散爱 提交于 2021-02-08 03:31:34
问题 I am using the excellent modification to Python's PIL by Etienne from here. What I need is exactly what the modification does - to save a JPEG file using the same quantization tables as the original. Doing it through that modification seems elegant, I'm currently achieving that by using a hodgepodge of C code. My problem is that I get a JPEG file object in PIL, but after any modification it becomes an object of some other type. What I want is to take the image, crop it and save it with the

Preserving image type info in PIL when cropping

北城余情 提交于 2021-02-08 03:31:00
问题 I am using the excellent modification to Python's PIL by Etienne from here. What I need is exactly what the modification does - to save a JPEG file using the same quantization tables as the original. Doing it through that modification seems elegant, I'm currently achieving that by using a hodgepodge of C code. My problem is that I get a JPEG file object in PIL, but after any modification it becomes an object of some other type. What I want is to take the image, crop it and save it with the

How can I pass an image to a template in Django?

梦想与她 提交于 2021-02-07 21:43:51
问题 Suppose that the corresponding function in views.py looks like from PIL import Image def get_img(request, img_source) base_image = Image.open(os.getcwd() + '/deskprod/media/img/'+ img_source + ".png") #Some editing of base_image done with PIL that prevents image from being directly loaded in html return render_to_response('get_img.html', { 'base_image': base_image}, context_instance=RequestContext(request)) How can I then display base_image in the get_img.html template? 回答1: You should

Rotate, scale and translate 2D coordinates?

泪湿孤枕 提交于 2021-02-07 20:11:10
问题 I'm am working on a project at the moment where I am trying to create a Hilbert curve using the Python Imaging Library. I have created a function which will generate new coordinates for the curve through each iteration and place them into various lists which then I want to be able to move, rotate and scale. I was wondering if anyone could give me some tips or a way to do this as I am completely clueless. Still working on the a lot of the code. #! usr/bin/python import Image, ImageDraw import

How do I crop an image on a white background with python?

倖福魔咒の 提交于 2021-02-07 19:59:23
问题 I am scanning old photos, so I have the image and a white background from the scanner. My aim is to take the picture, removing the white background. How can I do that ? An example picture is the following: My simple approach: import os import time from PIL import Image from collections import Counter import numpy as np def get_cropped_image(image, crop_folder, threshold): image_name = image.split("\\")[-1] im = Image.open(image) pixels = im.load() width, height = im.size rows = [] for h_index