Changeset 2516


Ignore:
Timestamp:
29/05/07 08:37:11 (12 years ago)
Author:
domlowe
Message:

ImageFile? reading sped up by use of image2array method

Location:
TI02-CSML/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml/csmllibs/csmldataiface.py

    r2509 r2516  
    543543      self.extractType   = 'rawExtract' 
    544544      self.extractPrefix = '_rawextract_' 
    545  
    546  
     545  
     546  
    547547   def openFile(self, filename): 
    548548      self.file = open(filename, "rb") 
     
    579579      # Read and unpack data into a Numeric array. 
    580580      self.data = Numeric.array(struct.unpack(format_str, self.file.read())) 
    581        
    582       # The order of dimensions in Numeric arrays do not correspond with 
    583       # the order of dimensions in traditional image files, so we need to 
    584       # reverse the dimensions before shaping the array. 
    585       dimensions = map(int, kwargs['dimensions']) 
    586       dimensions.reverse() 
    587       self.data.shape = tuple(dimensions) 
     581      self.data.shape = tuple(map(int, kwargs['dimensions'])) 
    588582       
    589583      # If numericTransform or fillValue were provided, store them as  
     
    677671      self.extractType   = 'imageExtract' 
    678672      self.extractPrefix = '_imageextract_' 
     673    
     674   def image2array(self,im): 
     675       #Adapted from code by Fredrik Lundh, http://www.pythonware.com  
     676       #http://effbot.org/zone/pil-numpy.htm 
     677        if im.mode not in ("L", "F"): 
     678            raise ValueError, "can only convert single-layer images" 
     679        if im.mode == "L": 
     680            a = Numeric.fromstring(im.tostring(), Numeric.UnsignedInt8) 
     681        else: 
     682            a = Numeric.fromstring(im.tostring(), Numeric.Float32) 
     683        a.shape = im.size[1], im.size[0] 
     684        return a 
    679685 
    680686   def openFile(self, filename): 
     
    686692   def readFile(self, **kwargs): 
    687693      # Convert the image to a Numeric array 
    688       self.data = Numeric.array(self.file.getdata()) 
     694       
     695      self.data=self.image2array(self.file) 
     696      #slower method: 
     697      #self.data = Numeric.array(self.file.getdata()) 
    689698 
    690699      # The order of dimensions in Numeric arrays do not correspond with 
  • TI02-CSML/trunk/setup.py

    r2255 r2516  
    66""" 
    77 
    8 import ez_setup; ez_setup.use_setuptools() 
     8import ez_setup;ez_setup.use_setuptools() 
    99from setuptools import setup, find_packages 
    1010 
    1111setup( 
    1212    name = 'csml', 
    13     version = '2.0', 
     13    version = '2.0b', 
    1414    author = 'Dominic Lowe', 
    1515    author_email = 'd.lowe@rl.ac.uk', 
Note: See TracChangeset for help on using the changeset viewer.