Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'indexing': 0.07; 'modify': 0.07; 'nested': 0.07; 'subject:file': 0.07; 'url:products': 0.07; 'blue': 0.09; 'integers': 0.09; 'module)': 0.09; 'pil': 0.09; 'pixels': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'subject:Help': 0.11; 'python': 0.11; 'stored': 0.12; '(excluding': 0.16; '.open': 0.16; '1024)': 0.16; '255': 0.16; 'astronomical': 0.16; 'comet': 0.16; 'data)': 0.16; 'green,': 0.16; 'luck,': 0.16; 'mine.': 0.16; 'red,': 0.16; 'simplest': 0.16; 'subject:array': 0.16; 'tuple': 0.16; 'uppercase': 0.16; 'folder': 0.16; 'url:)': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'trying': 0.19; 'pfxlen:0': 0.19; 'written': 0.21; 'example': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'install': 0.23; 'load': 0.23; 'integer': 0.24; 'skip:i 40': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'record': 0.27; 'array': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'piece': 0.31; 'file': 0.32; 'class': 0.32; 'this.': 0.32; 'url:python': 0.33; 'could': 0.34; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; 'done': 0.36; 'method': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'changing': 0.37; 'list': 0.37; 'project': 0.37; 'list.': 0.37; 'area': 0.37; 'sometimes': 0.38; 'skip:& 10': 0.38; 'lists.': 0.38; 'url:library': 0.38; 'files': 0.38; 'skip:& 20': 0.39; 'embedded': 0.39; 'called': 0.40; 'how': 0.40; 'read': 0.60; 'skip:2 20': 0.60; 'length': 0.61; 'url:3': 0.61; 'pick': 0.64; 'provide': 0.64; 'different': 0.65; 'taking': 0.65; 'to:addr:gmail.com': 0.65; 'series': 0.66; 'here': 0.66; 'channels': 0.68; 'difficulty': 0.68; 'readers': 0.68; '(ie': 0.84; 'faster.': 0.84; 'homework': 0.84; 'do:': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=buk4xvCGUAH8n5pi5MvT718eGG1PO3zXc0vyVWCKmT8=; b=JEIrUKtEWq7eubTjzVYc7/P+dqfY31Rs96YW14MSetX0G0591sgfzOof1kEcweHA+u +x9+hG8Wat8KI3MabpN/qvPooRHl62w+OQqtrX3oo8Ouj6mFQxnYBVBiwDdJQxVFuMmv zvM3DTxr1ukiutSvfMpi2PKa+k0+qFKQhZ9JPQ3GO/ABUPtJRP2IvGH9+x9j9wN1sDwQ 7ylthgUVg4wId94vS5FJO4zBSXA7Oo94yGPQFVEH/hxcamLPrZHY0nXB4wRKeepV4B8M TEFgg/UBo2OeoBzOIg6VsbkD6Ckqo5yIhQ0ac/Ee+SDCeUjVibFpvAsM6fhtcnUO5VWI OmUg== X-Received: by 10.112.158.106 with SMTP id wt10mr6643736lbb.75.1367857754669; Mon, 06 May 2013 09:29:14 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Joshua Landau Date: Mon, 6 May 2013 17:28:34 +0100 Subject: Re: Help with loading file into an array To: peter berrett Content-Type: multipart/alternative; boundary=001a11c2a9b89207fd04dc0f33f7 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 164 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367857762 news.xs4all.nl 15946 [2001:888:2000:d::a6]:41160 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44836 --001a11c2a9b89207fd04dc0f33f7 Content-Type: text/plain; charset=ISO-8859-1 On 5 May 2013 07:06, peter berrett wrote: > I am trying to build a program that can find comets in a series of > astronomical images. I have already written functions to find the comet in > a series of images, the data of which is stored in embedded lists. > > The area I am having difficulty with is take a standard gif file (1024 x > 1024) and reading it into an array or embedded lists. > This is not what you should really be doing. There are specialised things for this. Take a look at PIL (http://www.pythonware.com/products/pil/). It will install as "Image" and from there you can do: import Image image = Image.open("FILE") pixels = image.load() and access the pixels like: pixels[x, y] # You get (r, g, b) tuple of integers from 0 to 255 > In a nutshell here is an example of what I want to do > > Let's say I have a gif file called 20130428_0000_c2_1024.gif in a folder > called c:\comets > > I want to read the data from that gif file taking the red data (excluding > the green and blue data) and store that in an array called Image[][] which > is a nested array length 1024 with a list in each item of 1024 length (ie > 1024 x 1024) > *Ahem*: 1) Python standard is to only uppercase class (and sometimes module) names, so it should just be "image". 2) Technically, you mean list. 3) Chose the above method instead, so instead of indexing it with "image[x][y]" you use "image[x, y]". Now, you only want the red channel. What this means is that you want to "split" the image into channels before using image.load(): import Image image = Image.open("FILE") image.load() # .open is lazy, so you have to load now red, green, blue = image.split() red_pixels = red.load() And you access as before: red_pixels[x, y] # You get integer from 0 to 255 Could someone please provide a piece of code to do the above so I can then > go on to modify it to pick up different files from different folders? In > particular I am keen to seen how you read in the data and also how you > change the directory from which you are reading the image. > Changing directories is done with "os.chdir" ( http://docs.python.org/3/library/os.html#os.chdir). > For the record this is not for homework but is a pet project of mine. I > have already written a version of the program in Justbasic but python is > faster. I am also interested in readers views as to which is the simplest > and best way to achieve what I am trying to do. > Thanks for the clarification, btw. Good luck, as well. --001a11c2a9b89207fd04dc0f33f7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 5 May 2013 07:06, peter berrett <<= a href=3D"mailto:pwberrett@gmail.com" target=3D"_blank">pwberrett@gmail.com= > wrote:
I am trying to build a program that can find comets in a series of astronom= ical images. I have already written functions to find the comet in a series= of images, the data of which is stored in embedded lists.

The area I am having difficulty with is take a standard gif file (1024 x 10= 24) and reading it into an array or embedded lists.
This is not what you should really be doing. There are special= ised things for this.

It= will install as "Image" and from there you can do:

import Image
image =3D Image.open("FILE")
pixels =3D image.load()

and access the pix= els like:

pixels[x, y] # You get (r, g, b) tuple o= f integers from 0 to 255
=A0
In a nutshell here is an example of what I want to do

Let's say I have a gif file called 20130428_0000_c2_1024.gif in a folde= r called c:\comets

I want to read the data from that gif file taking the red data (excluding t= he green and blue data) and store that in an array called Image[][] which i= s a nested array length 1024 with a list in each item of 1024 length (ie 10= 24 x 1024)
=A0
*Ahem*:
1) Python standard is to = only uppercase class (and sometimes module) names, so it should just be &qu= ot;image".
2) Technically, you mean list.
3) Chose= the above method instead, so instead of indexing it with "image[x][y]= " you use "image[x, y]".

Now, you only want the red channel. What this means is = that you want to "split" the image into channels before using ima= ge.load():

import Image

image =3D Image.open("FILE")
image.load() # .open = is lazy, so you have to load now

red, green,= blue =3D image.split()
red_pixels =3D red.load()

<= /div>
And you access as before:

red_pixels[x, y] # = You get integer from 0 to 255

Could someone please provide a piece of code to do the above so I can then = go on to modify it to pick up different files from different folders? In pa= rticular I am keen to seen how you read in the data and also how you change= the directory from which you are reading the image.

Changing directories is done with "os= .chdir" (http://docs.python.org/3/library/os.html#os.chdir).
=A0
For the record this is not for homework but is a pet project of mine. I hav= e already written a version of the program in Justbasic but python is faste= r. I am also interested in readers views as to which is the simplest and be= st way to achieve what I am trying to do.

Thanks for the clarification, btw. Good lu= ck, as well.=A0
--001a11c2a9b89207fd04dc0f33f7--