~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to Sane/demo_numarray.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
# Shows how to scan a 16 bit grayscale image into a numarray object
5
5
#
6
6
 
 
7
from __future__ import print_function
 
8
 
7
9
# Get the path set up to find PIL modules if not installed yet:
8
10
import sys ; sys.path.append('../PIL')
9
11
 
14
16
def toImage(arr):
15
17
    if arr.type().bytes == 1:
16
18
        # need to swap coordinates btw array and image (with [::-1])
17
 
        im = Image.fromstring('L', arr.shape[::-1], arr.tostring())
 
19
        im = Image.frombytes('L', arr.shape[::-1], arr.tostring())
18
20
    else:
19
21
        arr_c = arr - arr.min()
20
22
        arr_c *= (255./arr_c.max())
21
23
        arr = arr_c.astype(UInt8)
22
24
        # need to swap coordinates btw array and image (with [::-1])
23
 
        im = Image.fromstring('L', arr.shape[::-1], arr.tostring())
 
25
        im = Image.frombytes('L', arr.shape[::-1], arr.tostring())
24
26
    return im
25
27
 
26
 
print 'SANE version:', sane.init()
27
 
print 'Available devices=', sane.get_devices()
 
28
print('SANE version:', sane.init())
 
29
print('Available devices=', sane.get_devices())
28
30
 
29
31
s = sane.open(sane.get_devices()[0][0])
30
32
 
32
34
s.mode = 'gray'
33
35
s.br_x=320. ; s.br_y=240.
34
36
 
35
 
print 'Device parameters:', s.get_parameters()
 
37
print('Device parameters:', s.get_parameters())
36
38
 
37
39
s.depth=16
38
40
arr16 = s.arr_scan()