Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83462

Re: Generate jpg files using line length (pixels) and orientation (degrees)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"""': 0.07; '40,': 0.09; '75,': 0.09; '[0,': 0.09; 'image,': 0.09; 'operand': 0.09; 'orientation,': 0.09; 'pil': 0.09; 'pixel': 0.09; 'pixels': 0.09; 'solution,': 0.09; 'subject:files': 0.09; 'subject:using': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; 'question.': 0.14; '&gt;&gt;': 0.16; "'rb')": 0.16; '105,': 0.16; '120,': 0.16; '60,': 0.16; 'be:': 0.16; 'centered': 0.16; 'coordinates': 0.16; 'csv': 0.16; 'exist.': 0.16; 'f.seek(0)': 0.16; 'feeding': 0.16; 'length,': 0.16; 'numpy': 0.16; 'padded': 0.16; 'param': 0.16; 'png': 0.16; 'range(0,': 0.16; 'stepping': 0.16; 'subject:Generate': 0.16; 'typeerror:': 0.16; '\xc2\xa0if': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; '&lt;': 0.19; 'thu,': 0.19; '>>>': 0.22; 'import': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; '&gt;&gt;&gt;': 0.24; 'orientation': 0.24; 'math': 0.24; 'cc:2**0': 0.24; '&gt;': 0.26; '15,': 0.26; 'skip:" 30': 0.26; 'code:': 0.26; 'defined': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'subject:) ': 0.29; 'skip:g 30': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; '255,': 0.31; 'img': 0.31; 'stated.': 0.31; 'file': 0.32; 'lists': 0.32; 'interface': 0.32; 'url:python': 0.33; '(most': 0.33; 'fri,': 0.33; 'skip:# 10': 0.33; 'skip:& 30': 0.33; 'problem': 0.35; 'subject: (': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'january': 0.37; 'positive': 0.37; 'skip:& 10': 0.38; 'thank': 0.38; 'files': 0.38; 'issue': 0.38; 'pm,': 0.38; 'recent': 0.39; 'space': 0.40; 'url:mail': 0.40; 'skip:\xc2 10': 0.60; 'up,': 0.60; 'black': 0.61; 'length': 0.61; 'skip:o 30': 0.61; 'range': 0.61; 'simple': 0.61; 'save': 0.62; 'email addr:gmail.com': 0.63; 'name': 0.63; '8bit%:10': 0.64; 'close': 0.67; 'determine': 0.67; 'ranges': 0.74; '.....': 0.78; '179': 0.84; '180': 0.84; '2015': 0.84; '360': 0.84; 'degrees,': 0.84; 'square,': 0.84; 'type(s)': 0.84; '800': 0.91; 'joel': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=hWJqJ1QvziIXjLdPO04VkOsmokTrl9aFbHDuGzfAWv8=; b=jQRARpPPXbK9AbUsqeUO73ChCFJOOxePJjxHJXYa7DySMAg+ymHSaw/sNOS8LTRflQ EJw3CN8mFMSHzWg+uBcWOw2kgYLRII8docXhy9/p2xqaVytm/bf+ZtuZ/XPUWKBf/+7H BBLQdW7RHw3TUFm9x0z5luNdl4ec3mdNJtl15vzwLtYIrNAzi7h+JOXsOD2/EeU8Mzlb ITkpMO2o85IXqUkwT7fWuAI5Z2i1O3jMliija7hX1pfF/eI2xJ0AKOeXwoOGET6pXeVd W3P3w8DoO6kzARZXjFvrIJ1ePAmkn/Y4uB9yDhu9Y+bEwlCriR6GGqZXqcnUzxa8SBQn +SPg==
MIME-Version 1.0
X-Received by 10.229.197.129 with SMTP id ek1mr19473086qcb.8.1420827495575; Fri, 09 Jan 2015 10:18:15 -0800 (PST)
In-Reply-To <1ae2a5c4-78ae-4831-ac01-b886e92c0468@googlegroups.com>
References <0f51bd21-7b0a-4ea0-8b13-27b1967d3b41@googlegroups.com> <m8mv27$k6e$2@dont-email.me> <m8nfs8$k6e$3@dont-email.me> <1ae2a5c4-78ae-4831-ac01-b886e92c0468@googlegroups.com>
Date Fri, 9 Jan 2015 13:18:14 -0500
Subject Re: Generate jpg files using line length (pixels) and orientation (degrees)
From Joel Goldstick <joel.goldstick@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type multipart/alternative; boundary=001a11c2bf762939d7050c3c2ea9
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17538.1420827512.18130.python-list@python.org> (permalink)
Lines 396
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1420827512 news.xs4all.nl 2891 [2001:888:2000:d::a6]:46855
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83462

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Jan 9, 2015 at 12:49 PM, <semeon.risom@gmail.com> wrote:

> On Thursday, 8 January 2015 20:54:38 UTC-6, Denis McMahon  wrote:
> > On Thu, 08 Jan 2015 22:07:03 +0000, Denis McMahon wrote:
> >
> > > On Thu, 08 Jan 2015 09:09:18 -0800, semeon.risom wrote:
> > >
> > >> Simple question. I hope. .....
> >
> > To follow up, below is a solution to the problem you stated.
> >
> > #!/usr/bin/python
> >
> > import Image, ImageDraw, math
> >
> > def makeimg(length, orientation):
> >     """
> >     Make an image file of a black 4 pixel wide line of defined length
> >     crossing and centered on a white background of 800 px square, save
> >     as a png file identifying line length and orientation in the file
> >     name.
> >     param length - pixels, length of the line
> >     param orientation - degrees, orientation ccw of the line from +ve x
> >     axis
> >     Files are saved in imgs subdir, this must already exist.
> >     File name is image_lll_ooo.jpg
> >     lll = length, ooo = orientation, both 0 padded to 3 digits
> >     """
> >
> >     # check length is +ve and not greater than 800
> >     if length < 0:
> >         length = length * -1
> >     if length > 800:
> >         length = 800
> >
> >     # check orientation is positive in range 0 .. 179
> >     while orientation < 0:
> >         orientation = orientation + 360
> >     if orientation > 179:
> >         orientation = orientation % 180
> >
> >     # calculate radius in pixels and orientation in radians
> >     radius = length / 2
> >     orient = math.radians(orientation)
> >
> >     # calculate xy coords in image space of line end points
> >     x1 = int(400 + (radius * math.cos(orient)))
> >     y1 = int(400 - (radius * math.sin(orient)))
> >     x2 = int(400 + (-radius * math.cos(orient)))
> >     y2 = int(400 - (-radius * math.sin(orient)))
> >
> >     # create an image
> >     img = Image.new('RGB', (800,800), 'rgb(255, 255, 255)')
> >     # create a draw interface
> >     draw = ImageDraw.Draw(img)
> >
> >     # draw the line on the image
> >     draw.line([(x1, y1), (x2, y2)], fill='rgb(0, 0, 0)', width=4)
> >
> >     # determine file name, save image file
> >     fn = 'imgs/image_{:03d}_{:03d}.jpg'.format(length,orientation)
> >     img.save(fn)
> >
> > # stepping through ranges of values
> > for length in range(100, 601, 100):
> >     for orientation in range(0, 171, 10):
> >         makeimg(length, orientation)
> >
> > # using lists of values
> > for length in [50, 150, 250, 350, 450, 550, 650]:
> >     for orientation in [0, 15, 40, 45, 60, 75, 90, 105, 120, 135, 150,
> > 165]:
> >         makeimg(length, orientation)
> >
> >
> >
> >
> > --
> > Denis McMahon, denismfmcmahon@gmail.com
>
> Thank you for the help btw. I think I'm close to a solution, but I'm
> having issue feeding the coordinates from my csv file into the formula.
>
> This is the error I get:
> Traceback (most recent call last):
>   File "C:\Users\Owner\Desktop\Stimuli Generation\Coordinates\Generate_w
> corr.py", line 68, in <module>
>     makeimg(length, orientation)
>   File "C:\Users\Owner\Desktop\Stimuli Generation\Coordinates\Generate_w
> corr.py", line 40, in makeimg
>     orientation = orientation % 180
> TypeError: unsupported operand type(s) for %: 'list' and 'int'
> >>>
>
> and here's the code:
>
> from PIL import Image, ImageDraw
> from numpy import math
>
> # import csv
> import csv
> f = open('C:\Users\Owner\DesktopStimuli Generation\Coordinates\file.csv',
> 'rb')
> rdr = csv.reader(f)
> f.seek(0)
> i = 0
> a = []
> b = []
> for row in rdr:
>         a.append(row[0])
>         b.append(row[1])
>
> def makeimg(length, orientation):
>     """
>     Make an image file of a black 4 pixel wide line of defined length
>     crossing and centered on a white background of 800 px square, save
>     as a png file identifying line length and orientation in the file
>     name.
>     param length - pixels, length of the line
>     param orientation - degrees, orientation ccw of the line from +ve x
>     axis
>     Files are saved in imgs subdir, this must already exist.
>     File name is image_lll_ooo.jpg
>     lll = length, ooo = orientation, both 0 padded to 3 digits
>     """
>
>     # check length is +ve and not greater than 800
>     if length < 0:
>         length = length * -1
>     if length > 800:
>         length = 800
>
>     # check orientation is positive in range 0 .. 179
>     while orientation < 0:
>         orientation = orientation + 360
>     if orientation > 179:
>         orientation = orientation % 180
>
>     # calculate radius in pixels and orientation in radians
>     radius = length / 2
>     orient = math.radians(orientation)
>
>     # calculate xy coords in image space of line end points
>     x1 = int(400 + (radius * math.cos(orient)))
>     y1 = int(400 - (radius * math.sin(orient)))
>     x2 = int(400 + (-radius * math.cos(orient)))
>     y2 = int(400 - (-radius * math.sin(orient)))
>
>     # create an image
>     img = Image.new('RGB', (800,800), 'rgb(255, 255, 255)')
>     # create a draw interface
>     draw = ImageDraw.Draw(img)
>
>     # draw the line on the image
>     draw.line([(x1, y1), (x2, y2)], fill='rgb(0, 0, 0)', width=4)
>
>     # determine file name, save image file
>     fn = 'imgs/image_{:03d}_{:03d}.jpg'.format(length,orientation)
>     img.save(fn)
>
>
> # using lists of values
> for length in [a]:
>     for orientation in [b]:
>         makeimg(length, orientation)
>

above should be:
   for length in a:
      for orientation in b:


--
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Generate jpg files using line length (pixels) and orientation (degrees) semeon.risom@gmail.com - 2015-01-08 09:09 -0800
  Re: Generate jpg files using line length (pixels) and orientation (degrees) Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-08 22:07 +0000
    Re: Generate jpg files using line length (pixels) and orientation (degrees) Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-09 02:54 +0000
      Re: Generate jpg files using line length (pixels) and orientation (degrees) semeon.risom@gmail.com - 2015-01-09 09:49 -0800
        Re: Generate jpg files using line length (pixels) and orientation (degrees) Joel Goldstick <joel.goldstick@gmail.com> - 2015-01-09 13:18 -0500
          Re: Generate jpg files using line length (pixels) and orientation (degrees) semeon.risom@gmail.com - 2015-01-09 13:51 -0800
            Re: Generate jpg files using line length (pixels) and orientation (degrees) Dan Sommers <dan@tombstonezero.net> - 2015-01-09 22:21 +0000
            Re: Generate jpg files using line length (pixels) and orientation (degrees) Dave Angel <davea@davea.name> - 2015-01-09 17:23 -0500
            Re: Generate jpg files using line length (pixels) and orientation (degrees) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-09 22:41 +0000
        Re: Generate jpg files using line length (pixels) and orientation (degrees) Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-11 00:32 +0000
          Re: Generate jpg files using line length (pixels) and orientation (degrees) semeon.risom@gmail.com - 2015-01-11 11:41 -0800
            Re: Generate jpg files using line length (pixels) and orientation (degrees) Denis McMahon <denismfmcmahon@gmail.com> - 2015-01-11 19:56 +0000
            Re: Generate jpg files using line length (pixels) and orientation (degrees) Dave Angel <davea@davea.name> - 2015-01-11 15:16 -0500

csiph-web