python-imaging-library

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

微笑、不失礼 提交于 2021-02-07 19:57:08
问题 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

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

眉间皱痕 提交于 2021-02-07 19:56:54
问题 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

Search image for color. Return X, Y

帅比萌擦擦* 提交于 2021-02-07 10:01:59
问题 I've been looking all over for a way to find a specific color in a image (screen capture), and return the the position of of the color (x,y). I've had some tries, but not managed to do a proper search. The result should be the first pixel found with that color. I tought maybe PIL will be to any help. So I tried something like this, problem now is that it returns EVERY position, found with that color: Fixed: def FindColor(r,g,b): image = ImageGrab.grab() for x in range(1, 400): for y in range

Rotating a square in PIL

梦想与她 提交于 2021-02-07 08:32:30
问题 With PIL, I want to draw a rotated square on an image, by specifying the square side length, and the rotation angle. The square should be white, and the background grey. For example, the following image has a rotation of 45 degrees: The only way I know how to do rotations in PIL is by rotating the entire image. But if I start with the following image: And then rotate it by 45 degrees, I get this: That method just introduces black parts to fill in the "undefined" region of the image. How can I

Rotating a square in PIL

ⅰ亾dé卋堺 提交于 2021-02-07 08:31:14
问题 With PIL, I want to draw a rotated square on an image, by specifying the square side length, and the rotation angle. The square should be white, and the background grey. For example, the following image has a rotation of 45 degrees: The only way I know how to do rotations in PIL is by rotating the entire image. But if I start with the following image: And then rotate it by 45 degrees, I get this: That method just introduces black parts to fill in the "undefined" region of the image. How can I

Rotating a square in PIL

僤鯓⒐⒋嵵緔 提交于 2021-02-07 08:30:03
问题 With PIL, I want to draw a rotated square on an image, by specifying the square side length, and the rotation angle. The square should be white, and the background grey. For example, the following image has a rotation of 45 degrees: The only way I know how to do rotations in PIL is by rotating the entire image. But if I start with the following image: And then rotate it by 45 degrees, I get this: That method just introduces black parts to fill in the "undefined" region of the image. How can I

Pillow resize pixelating images - Django/Pillow

亡梦爱人 提交于 2021-02-07 07:16:24
问题 I am developing an image uploader in Django. After the image has been uploaded and saved on disk, I'm trying to resize the saved image while maintaing its aspect ratio. I am using Pillow for image processing/resizing. The problem arises when I try to resize the image, it's getting pixelated even though the resized image's aspect ratio is same as that of the original image. Original Saved Image : https://www.dropbox.com/s/80yk6tnwt3xnoun/babu_980604.jpeg Resized Pixelated Image: https://www

Python - Convert image to a string of pixel values

那年仲夏 提交于 2021-02-07 04:01:19
问题 I have a .jpg image captured from a webcam. It is a greyscale image. I need to convert the image to a string of its pixels like so: "255 232 45 678 56 23....345 76 44 767 433 345" How do I go about doing this? Also, would changing the size of the image change these values? 回答1: Assuming you have the image represented as a numpy array (since the question is tagged as OpenCV related, then this is likely the case), then to obtain the result you want, I'd take the following steps. First flatten

How to turn grayscale into false color using PIL?

别说谁变了你拦得住时间么 提交于 2021-02-07 03:48:51
问题 I can't seem to figure out how to take my grayscale function and change it to give me false color. I know I need to break each color (R,G,B) into ranges and then assign colors based on the range for each color. Does anyone have any idea how this can work? def grayscale(pic): (width,height) = pic.size for y in range (height): for x in range(width): pix = cp.getpixel((x,y)) (r, g, b) = pix avg = (r + g + b)//3 newPix = (avg, avg, avg) cp.putpixel((x,y),newPix) return cp 回答1: Since you never

How to turn grayscale into false color using PIL?

让人想犯罪 __ 提交于 2021-02-07 03:47:43
问题 I can't seem to figure out how to take my grayscale function and change it to give me false color. I know I need to break each color (R,G,B) into ranges and then assign colors based on the range for each color. Does anyone have any idea how this can work? def grayscale(pic): (width,height) = pic.size for y in range (height): for x in range(width): pix = cp.getpixel((x,y)) (r, g, b) = pix avg = (r + g + b)//3 newPix = (avg, avg, avg) cp.putpixel((x,y),newPix) return cp 回答1: Since you never