<s> from __future__ import absolute_import , division , print_function <EOL> from glob import glob <EOL> import os <EOL> try : <EOL> from skimage . io import imread as sk_imread <EOL> except ImportError : <EOL> pass <EOL> from . core import Array <EOL> from . . base import tokenize <EOL> def add_leading_dimension ( x ) : <EOL> return x [ None , ... ] <EOL> def imread ( filename , imread = None , preprocess = None ) : <EOL> """<STR_LIT>""" <EOL> imread = imread or sk_imread <EOL> filenames = sorted ( glob ( filename ) ) <EOL> if not filenames : <EOL> raise ValueError ( "<STR_LIT>" % filename ) <EOL> name = '<STR_LIT>' % tokenize ( filenames , map ( os . path . getmtime , filenames ) ) <EOL> sample = imread ( filenames [ <NUM_LIT:0> ] ) <EOL> if preprocess : <EOL> sample = preprocess ( sample ) <EOL> keys = [ ( name , i ) + ( <NUM_LIT:0> , ) * len ( sample . shape ) for i in range ( len ( filenames ) ) ] <EOL> if preprocess : <EOL> values = [ ( add_leading_dimension , ( preprocess , ( imread , filename ) ) ) <EOL> for filename in filenames ] <EOL> else : <EOL> values = [ ( add_leading_dimension , ( imread , filename ) ) <EOL> for filename in filenames ] <EOL> dsk = dict ( zip ( keys , values ) ) <EOL> chunks = ( ( <NUM_LIT:1> , ) * len ( filenames ) , ) + tuple ( ( d , ) for d in sample . shape ) <EOL> return Array ( dsk , name , chunks , sample . dtype ) </s>
