473,795 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python Imaging Library (PIL) question

Sid
Hi,

I am tryin to copy an image into my own data structure(a sort of 2d array
for further FFT). I've banged my head over the code for a couple of hours
now. The simplified version of my problem is below.

#-----------------Code------------------------

import Image
pic = Image.open("Ima ges/a.jpg")
(picdata,width, height) = (pic.load(),pic .size[0],pic.size[1])

picMap = [[0] * width ] * height #matrix needed for FFT

print "------Printing PIC MAP------"
for h in range(0,height) :
for w in range(0,width):
print picMap[h][w]," ", #everything initialized to ZERO...this is
ok
print "\n"
print "------Copying to PIC MAP------"
for h in range(0, height):
for w in range(0, width):
picMap[h][w] = picdata[w,h] #problem lies here????
print picMap[h][w]," ", #Seems to copy perfectly here as the
output shows
print "\n"
print "------Printing PIC MAP AGAIN------"
for h in range(0,height) :
for w in range(0,width):
print picMap[h][w]," ", #Should print the values as above, but
doesn't
print "\n"

#-----------------Code End------------------------

Hopefully someone would take a look and let me know what i'm doing
something wrong here.

Thanks a lot
-Sid
Oct 20 '08 #1
2 1668
On Oct 20, 2:14*pm, Sid <sidmitra85-...@yahoo.co.in wrote:
Hi,

* I am tryin to copy an image into my own data structure(a sort of 2d array *
for further FFT). I've banged my head over the code for a couple of hours*
now. The simplified version of *my problem is below.

#-----------------Code------------------------

import Image
pic = Image.open("Ima ges/a.jpg")
(picdata,width, height) *= (pic.load(),pic .size[0],pic.size[1])

picMap = [[0] * width ] * height * * * *#matrix needed for FFT

print "------Printing PIC MAP------"
for h in range(0,height) :
* * *for w in range(0,width):
* * * * *print picMap[h][w]," ", #everything initialized to ZERO...this is *
ok
* * *print "\n"

print "------Copying to *PIC MAP------"
for h in range(0, height):
* * *for w in range(0, width):
* * * * *picMap[h][w] = picdata[w,h] #problem lies here????
* * * * *print picMap[h][w]," ", *#Seems to copy perfectly here as the *
output shows
* * *print "\n"

print "------Printing PIC MAP AGAIN------"
for h in range(0,height) :
* * *for w in range(0,width):
* * * * *print picMap[h][w]," ", *#Should print the values asabove, but *
doesn't
* * *print "\n"

#-----------------Code End------------------------

Hopefully someone would take a look and let me know what i'm doing *
something wrong here.

Thanks a lot
-Sid
The problem is likely to do with the line
picMap = [[0] * width ] * height

The first [0]*width creates a list, then the *height repeats the
reference to the same list. See, for example
http://mail.python.org/pipermail/tut...er/010414.html. It
prints okay in the middle section because the items have just been
stored. Later iterations in that same loop are replacing array
elements that have already been printed. The link explains the problem
and shows a way to avoid this. You might also consider using Numpy, it
has explicit functions to zero any dimension array.

Oct 21 '08 #2
Sid
The problem is likely to do with the line
picMap = [[0] * width ] * height
yeah the problem was with that specific line. The snippet from your link
worked by
replacing the previous declaration by

picMap = [[0] * 3 for x in xrange(height)]

Thanks,
-Sid
Oct 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2375
by: Fuzzyman | last post by:
I'll post this to the image-sig as well, but the audience is a bit wider here. I've just upgraded to Python 2.4. I've installed the free microsoft optimising compiler and hacked distutils to use it - following the instructiosn from http://www.vrplumber.com/programming/mstoolkit/ . It works great and I've built a windows installer for PyCrypto 2.0. I'm attempting to compile PIL for python 2.4. The build instructions for windows say :
0
1226
by: amaltasb | last post by:
Hi, I am hosting python applicaitions on a shared hositng so I dont have enough privilages, I have installed python in my home folder, through Automatic installer > extratools.php I want to install Python imaging library module. I just copied the PIL in my py24 folder and also in site packages, but its not working. How can I install PIL using extratools.php
2
1876
by: Tim Adler | last post by:
Hey everybody, I'm quite new to Python. I'm working on a webproject with Django and need to install the Python Imaging Library. It worked fine under Mac OS but when I try it on my Linux server. It gives me this error: PasteBin Link: http://phpfi.com/179314 I don't really know what is wrong. Can somebody point me directions. I really need the PIL to work.
2
2741
by: moishyyehuda | last post by:
can I download Python Imaging Library (PIL) for linux.
3
2174
by: bsagert | last post by:
I downloaded BeautifulSoup.py from http://www.crummy.com/software/BeautifulSoup/ and being a n00bie, I just placed it in my Windows c:\python25\lib\ file. When I type "import beautifulsoup" from the interactive prompt it works like a charm. This seemed too easy in retrospect. Then I downloaded the PIL (Python Imaging Library) module from http://www.pythonware.com/products/pil/. Instead of a simple file that BeautifulSoup sent me, PIL is...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.