FAQ Database Discussion Community


Python scp copy images from image_urls to server

python,python-imaging-library,urllib,scp
I have written one function which recieves a url and copy it to all server. Server remote path is stored in db. def copy_image_to_server(image_url): server_list = ServerData.objects.values_list('remote_path', flat=True).filter(active=1) file = cStringIO.StringIO(urllib.urlopen(image_url).read()) image_file = Image.open(file) image_file.seek(0) for remote_path in server_list: os.system("scp -i ~/.ssh/haptik %s %s " % (image_file, remote_path)) I am...

Updating Tkinter Label with an Image

python,tkinter,python-imaging-library
Well I got a "small" problem with updating a label using Tkinter and PIL. As soon as I press the cheese Button it should display foo2, but it just displays a white screen. Any suggestions? Here is my code: from PIL import Image as Im from Tkinter import * class...

PIL: overlaying images with different dimensions and aspect ratios

python,python-imaging-library
I've been attempting to overlay two images in python to match coordinates, the top left and bottom right corners have the same coordinates and their aspects are almost identical bar a few pixels. Although they are different resolutions. Using PIL I have been able to overlay the images, though after...

what is the valid format for a tiff image in python

image,python-3.x,image-processing,python-imaging-library,tiff
How do I write a valid tiff image in python with my own data for the tiff file? I've tried doing a few things using PIL and it's not a valid image. If you could answer with some sample code of making a tiff image then editing the data using...

Create circular image PIL Tkinter

python,user-interface,tkinter,python-imaging-library
Currently I have a zoom feature in my application that works very well, however I'd like the actual zoom box to be a circle instead. Here's what the current zoom looks like: the zoomed in rectangle is where the mouse pointer location is, and surrounding area is zoomed in. But...

Crop image with settable center and scale in Python PIL

python,image,zoom,python-imaging-library,crop
I would like to crop an image using PIL, although it could be some other module. I need the method to crop with a scale factor, ie 1.5 meaning that the output would be 1.5x zoomed in. Additionally, I would need to set the center where it zooms. This means...

Error importing PIL when using cx_freeze

python,python-3.x,python-imaging-library,cx-freeze
I've been at this the whole day now and I'm about throw my computer out the window. I made a UI using tkinter, matplotlib and PIL. If I run the code this works perfectly, however when freezing using cx_freeze, I get the following when doing python setup.py build: c:\Python33>python setup.py...

Can a numpy array be compared to an integer?

python,arrays,numpy,python-imaging-library,linear
This was in some code that I'll have to use for a homework: from PIL import Image import numpy as np img = np.array(Image.open("image.png"))[:,:,0] Known = (img > 0).astype(int) What does the last line - Known = (img > 0).astype(int) - do? (I tried looking it up, but it's hard...

Cannot construct tkinter.PhotoImage from PIL Image

python,tkinter,resize,python-imaging-library,resize-image
I try to show a image in a label when I push a button, but the image are too large and I have tried to resize the image. I have created this function: def image_resize(imageFile): width = 500 height = 300 image = Image.open(imageFile) im2 = image.resize((width, height), Image.ANTIALIAS) return...

How to force Pillow to resize an image to an arbitrary size?

python,image-processing,python-imaging-library
I need to resize images, from all different sizes to 144x144. All sizes: from 968x565, from 25x48, from 400x400, etc. Don't know the input. I'm using Pillow library from Python. I don't mind losing aspect ratio. Problem is: when using resize method, some images get complete random sizes. Not always,...

Install PIL without pypi

python,python-imaging-library,restriction,pillow
I need to install pillow (PIL fork) using either easy_install or source. Due to the restrictions on the computer at school I'm using, I can't access python.org, or pip. I have a portable python installation, which is legal under my school's policy because I can put it in my personal...

How to create thumbnails using opencv-python?

python,opencv,image-processing,python-imaging-library
I'm trying to downsample my image(using anti-aliasing) using Python-Pillow's im.thumbnail() method. My code looks like: MAXSIZE = 1024 im.thumbnail(MAXSIZE, Image.ANTIALIAS) Can you tell me some alternative in opencv-python to perform this re-sizing operation ?...

Combine several images horizontally with Python

python-2.7,python-imaging-library,paste
I am trying to horizontally combine some JPEG images in Python. Problem: I have 3 images - each is 148 X 95 - see attached. I just made 3 copies of the same image - that is why they are the same. My attempt: I am trying to horizontally join...

Difference between from PIL import Image and import Image

python,python-imaging-library,homebrew,macports,pillow
I tried to use Python's Image Module on my Mac (new to mac)and I had trouble setting it up. I have Yosemite and some of the posts that I found online didn't work. I ended up installing Homebrew and I finally got PIL on my computer. However, instead of using...

Image not Found using PIL and Urllib to retrieve URL

python,python-2.7,tkinter,python-imaging-library,urllib
I keep receiving the following error no matter what image url I try to use: line 76, in <module> radar = Label(root, image = im) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2556, in __init__ Widget.__init__(self, master, 'label', cnf, kw) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2055, in __init__ (widgetName, self._w) + extra + self._options(cnf)) TclError: image...

Import pillow without installing

python,python-3.x,python-imaging-library,pillow
I am working on a Python project that requires PIL to show images. However, the computers that I am working on often do not allow me to install things, and have a very bare bones python setup. For this reason, most of the modules that I need I simply place...

How to gauss-filter (blur) a floating point numpy array

python,numpy,filtering,python-imaging-library
I have got a numpy array a of type float64. How can I blur this data with a Gauss filter? I have tried from PIL import Image, ImageFilter image = Image.fromarray(a) filtered = image.filter(ImageFilter.GaussianBlur(radius=7)) , but this yields ValueError: 'image has wrong mode'. (It has mode F.) I could create...

How to paste an image onto a larger image using Pillow?

python,python-imaging-library,pillow
I've got a fairly simple code file: from PIL import Image til = Image.new("RGB",(50,50)) im = Image.open("tile.png") #25x25 til.paste(im) til.paste(im,(23,0)) til.paste(im,(0,23)) til.paste(im,(23,23)) til.save("testtiles.png") However, when I attempt to run it, I get the following error: Traceback (most recent call last): til.paste(im) File "C:\Python27\lib\site-packages\PIL\Image.py", line 1340, in paste self.im.paste(im, box) ValueError:...

Photologue UnsupportedOperation('fileno',)

python,django,python-imaging-library,pillow
I have used Photologue on many projects on different servers and never had this problem before. When Photologue calls this function self.create_size(photosize) I receive this error UnsupportedOperation('fileno',) I have googled for answers and found out that it may be caused by PIL and Pillow being both installed on the server....

Strange Pillow exception while saving cropped image

python,python-2.7,python-imaging-library
We have the following code: img = Image.open(FileSystemStorage().path(relpath)) coords = [ cd['crop_start_x'], cd['crop_start_y'], cd['crop_end_x'], cd['crop_end_y'] ] cropped_img = img.crop(coords) cropped_path = "%s-cropped%s" % os.path.splitext(relpath) tasks.delete_temporary_file.delay(fss.path(relpath)) cropped_img.save(fss.path(cropped_path)) When trying to save the cropped image, we get a strange "Not a valid number of quantization tables. Should be between 1 and 4."...

With Python`s PIL, how to set DPI before loading an image?

python,image-processing,python-imaging-library,pythonmagick
I was trying to use PIL to open an (Illustrator) .eps-file, do some changes and save it. I want to set the document to 300 dpi, and color mode to cmyk before opening, creating or interpreting the object. First I tried the same with PythonMagick and it worked like this:...

Plot gradients using PIL in Python

python,image,python-imaging-library
I'm actually creating images using Python, the basics. The thing is that I'm actually using myImage = Image.new('RGB', (250, 250), 'rgb(155,89,182)') and well, this actually creates the image. But, is there a way to create an image with a background of the color I'm choosing but with gradients? Let me...

Some PIL.ImageFile attributes like LOAD_TRUNCATED_IMAGES are missed

python,python-imaging-library,intel-edison
I'm working on the Intel Edison that have custom distribution that built using Yocto project, the exact python version that I'm working on is 2.7.3 and the PIL version is 1.1.7. While trying to enable truncated images loading by setting the LOAD_TRUNCATED_IMAGES attribute to true, I found that it is...

How do I fix my error with PIL and numpy images

python,image,python-3.x,numpy,python-imaging-library
You have to run it in the folder with a couple images and run shuffle_all_images() and it will create new folder and randomly generate all of the values for each pixel. I think it has to do with not converting to numpy images as opposed to PIL images?, but I...

Python PIL - AttributeError: 'NoneType' object has no attribute 'save'

python,border,python-imaging-library,crop,trim
I use this code to delete the border of an image using PIL: def RemoveBlackBorders(img): bg = Image.new(img.mode, img.size, img.getpixel((0,0))) diff = ImageChops.difference(img, bg) diff = ImageChops.add(diff, diff, 2.0, -100) bbox = diff.getbbox() if bbox: return img.crop(bbox) from here And I use this to process all images contained in a...

Using Python to Resize Images when Greater than 1280 on either side

python,python-imaging-library,pillow
I want to use Python to resize any image based on the following 2 conditions. 1) If an image is landscape, get width, if greater than 1280 resize image width to 1280 maintaining aspect ratio. 2) If an image is portrait, get height, if greater than1280 resize height to 1280...

Resize url image using urllib and pil

python,python-2.7,io,python-imaging-library,urllib
I am looking to retrieve an image from a url, resize it (to fit appropriately in the GUI), and then display the image in the GUI. I believe I have the basic premise down...or at least I know how to retrieve and display an image. I have provided some sample...

PIL/Pillow IOError: cannot identify image file u'xxxx.jpg' (Windows only)

python,windows,python-imaging-library
I've constructed Python script and it works well on OS X/Linux but I'm having problems in Windows (see title). It's using Pillow module and the error originates in module PIL\Image.py on line 2274. My code: # -*- coding: utf-8 -*- import os import sys import urllib2 from PIL import Image,...

Can't run an infinite thread with Tkinter

python,multithreading,tkinter,python-imaging-library
The code below works, but if i make the thread an infinite loop (by uncommenting the line i=False) the window does'nt show anymore. What Am I missing? My goal is to keep updating the image while it's shown. from PIL import Image,ImageTk from tkinter import Tk,Canvas,NW,mainloop import threading from time...

Simple way to resize large number of image files

shell,image-processing,python-imaging-library
I have a folder which contains about 45000 jpeg images. Most of them are from 10KB - 20Kb. Now I want to write a script to resize all of them to fixed size 256x256. I wonder if there is any simple way to do that like: for a in *.jpg...

working with tiff files in python

python,image-processing,tkinter,python-imaging-library,tiff
First are tiff's grayscale? As I understand how tiff's work they can accept floating point numbers as most other image types cannot. I am attempting to do a linear interpolation for smooth coloring and need to put the floating point rgb array into this tiff image. What is the proper...

Python PIL: how understand hexadecimal code in ?

python,python-imaging-library
The code: >>> import Image >>> img = Image.open("mini.jpg") >>> print img.getdata() return: ImagingCore object at 0x7fb02637f330 I know that this represent an object of Python Image Libraries (PIL) in hexadecimal base. How can I translate this number code properly? It's a *jpg, size 34x34....

Load 64-bit raw image file in python

python,numpy,scipy,python-imaging-library
I am wondering how to load this image in python. I can load it in imageJ using the pictures settings, but I cannot figure out how to load it in python. ...

Tkinter being fickle with pictures, some are blank, others are not

python,python-2.7,tkinter,python-imaging-library
NOTE: The main problem hasn't been solved, but the code does work on a Windows PC, the problem has something to with the computer I'm using. As the title suggests, in my code, one image works perfectly fine, yet the other doesn't display correctly. I feel like I'm overlooking something...

How to Manipulate TIFF header values in Python (PIL)?

python,python-imaging-library,tiff
I can read in a TIFF image file via PIL just fine... im = Image.open('FRONT200BW_1.TIF') I can see the TIFF headers via: im.tag[270] 'returned description' Here's where I'm hitting a brick wall. I have a requirement to fiddle with Artist (315), Date_Time (306), Document_Name (269), Image_Description (270) and Page_Name (285)...

Image not saving after updating pixel color in PIL

python,python-2.7,python-imaging-library
I've generated barcode images in PNG format using HuBarcode, and have modified them to add a border of rgb(150, 150, 150) in hopes of accessing the pixels of that color to change them. I can access the pixel and get confirmation via print that the color is being changed, but...

How can I use introspection to get Python to tell me more about PIL ImagingCore objects?

python,python-imaging-library,introspection
Something I'm doing in PIL is giving me back an object of a class I don't recognize. It may be a fairly thin wrapper around a C data structure or something. How can I get Python to tell me where to look for more information? Here are some failed attempts...

PIL simple gradient and TypeError: an integer is required

python,python-imaging-library
I have seen numpy-->PIL int type issue, but it doesn't answer my question which is simpler, as it doesn't use numpy. Consider this example: import Image import math img = Image.new('L', (100, 50), 'white') a = 0.1 # factor for x in xrange(img.size[0]): for y in xrange(img.size[1]): # val: 0...

Sending an image in python without saving it

python,image,sockets,pygame,python-imaging-library
I've just started working with PIL and Pygame and I wanted to create a screen-sharing program. In order to take a screenshot I used ImageGrab.grab() and now I want to send it to another computer and open it in Pygame without saving it on any of the computers. This is...

What does the 3rd tuple value stand for in Pillow.Image.tile?

python,image,python-imaging-library,pillow
Could someone tell me what 106 stands for in the following output generated by printing the Pillow.Image.tile attribute? [('zip', (0, 0, 242, 80), 106, 'RGBA')] ...

Save pixel data in txt format in PIL

python,python-imaging-library,getpixel
My program is to extract the pixel from an image and to save the pixel data in text file for analysis. My picture is a binary image that gives only 255 and 0 's Here is the program from PIL import Image im=Image.open("thresh.jpg") pixel = im.load() row,column=im.size for y in...

How can I create a PNG image file from a list of pixel values in Python?

python,image,list,file,python-imaging-library
I can generate a list of pixel values from an existing image file using a procedure like the following: from PIL import Image image = Image.open("test.png") pixels = list(image.getdata()) width, height = image.size pixels = [pixels[i * width:(i + 1) * width] for i in xrange(height)] How could I convert...

PIL posterize- fix green pixels

python,python-imaging-library
I decided to write my own posterize function in PIL instead of using the provided one so that I could understand it more. Problem Sometimes, unexpected green pixels show up when using my posterize function that don't when using the built-in posterize function. Example The first picture is the input...

PIL Image.save results in incorrect pixel mapping

python,python-imaging-library
I am trying to read data from a JPEG using pillow, then save it to a new image, however, when I read the data from the newly saved image, it does not correspond to the data from the original! here is the script: from PIL import Image im1 = Image.open("original.jpg")...

Generate random colors (RGB)

python,random,python-imaging-library
I just picked up image processing in python this past week at the suggestion of a friend to generate patterns of random colors. I found this piece of script online that generates a wide array of different colors across the RGB spectrum. def random_color(): levels = range(32,256,32) return tuple(random.choice(levels) for...

How can I equalise intensity for a set of images?

python,python-imaging-library
I have hand-drawn a set of square tiles, over a period of time. They are essentially black ink on while paper. After scanning in, and sizing, I wrote some code to construct larger images from the tiles. However, i can see that they don't all have the same intensity of...

Opening Images as Arrays

python,arrays,image,numpy,python-imaging-library
I have a script that should open an image as a 2D array but I can't seem to make it work. I have tried using the numpy an PIL libraries. I tried this on different computers. The issue is that it opens the image as a 2D array on one...

Convert an images pixel value from rgb to grayscale manually python PIL?

python,python-imaging-library,grayscale
Im trying to use a specific gamma corrected grayscale implementation - Gleam to convert an images pixels to grayscale. How can i do this manually with PIL python? def tau_gamma_correct(pixel_channel): pixel_channel = pixel_channel**(1/2.2) return pixel_channel #@param: rgb #@result: returns grayscale value def gleam(rgb): #convert rgb tuple to list rgblist =...

How can I determine the length of a multi-page TIFF using Python Image Library (PIL)?

python,image-processing,python-imaging-library,tiff
I know that the Image.seek() and Image.tell() methods of PIL allow me to go to a particular frame, and list the current frame, respectively. I would like to know how many frames there are total. Is there a function for getting this info? Alternatively, is there a way in python...

Convert image to a digital matrix using python

python,arrays,numpy,python-imaging-library
I have an image "felix.png" (280x280). and I'm converting this image to digital matrix: from PIL import Image from numpy import array img = Image.open('felix.png') arr = array(img) the shape of this array is (280,280,3) and I wonder why each pixel is represented with 3 dimensional array? for example arr[0][0]...

Create an ICO working on XP with python from a PNG or JPG

python,python-2.7,windows-xp,python-imaging-library,ico
ICO created from PNG or JPG with python Pillow are not working on Windows XP. ICO works fine on Vista and later versions. I wrote a simple code which demonstrate that an ICO which was working on XP and saved with PIL break it on XP: from PIL import Image...

“Blending out” noise in images?

python,image,python-imaging-library
I don't know if there is an official name for this. I am trying to do some color analysis on a picture using Python on the pixel-level, but the problem is that sometimes there are little bits of pixels here and there that might have wildly different colors and mess...