<s> import os . path <EOL> import numpy as np <EOL> from numpy . testing . decorators import skipif <EOL> from numpy . testing import assert_raises <EOL> from tempfile import NamedTemporaryFile <EOL> from skimage import data_dir <EOL> from skimage . io import imread , imsave , use_plugin , reset_plugins <EOL> try : <EOL> import SimpleITK as sitk <EOL> use_plugin ( '<STR_LIT>' ) <EOL> except ImportError : <EOL> sitk_available = False <EOL> else : <EOL> sitk_available = True <EOL> np . random . seed ( <NUM_LIT:0> ) <EOL> def teardown ( ) : <EOL> reset_plugins ( ) <EOL> def setup_module ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> use_plugin ( '<STR_LIT>' ) <EOL> except ImportError : <EOL> pass <EOL> @ skipif ( not sitk_available ) <EOL> def test_imread_flatten ( ) : <EOL> img = imread ( os . path . join ( data_dir , '<STR_LIT>' ) , flatten = True ) <EOL> assert img . ndim == <NUM_LIT:2> <EOL> assert img . dtype == np . float64 <EOL> img = imread ( os . path . join ( data_dir , '<STR_LIT>' ) , flatten = True ) <EOL> assert np . sctype2char ( img . dtype ) in np . typecodes [ '<STR_LIT>' ] <EOL> @ skipif ( not sitk_available ) <EOL> def test_bilevel ( ) : <EOL> expected = np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> expected [ : : <NUM_LIT:2> ] = <NUM_LIT:255> <EOL> img = imread ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> np . testing . assert_array_equal ( img , expected ) <EOL> """<STR_LIT>""" <EOL> @ skipif ( not sitk_available ) <EOL> def test_imread_uint16 ( ) : <EOL> expected = np . load ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> img = imread ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> assert np . issubdtype ( img . dtype , np . uint16 ) <EOL> np . testing . assert_array_almost_equal ( img , expected ) <EOL> @ skipif ( not sitk_available ) <EOL> def test_imread_uint16_big_endian ( ) : <EOL> expected = np . load ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> img = imread ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> np . testing . assert_array_almost_equal ( img , expected ) <EOL> class TestSave : <EOL> def roundtrip ( self , dtype , x ) : <EOL> f = NamedTemporaryFile ( suffix = '<STR_LIT>' ) <EOL> fname = f . name <EOL> f . close ( ) <EOL> imsave ( fname , x ) <EOL> y = imread ( fname ) <EOL> np . testing . assert_array_almost_equal ( x , y ) <EOL> @ skipif ( not sitk_available ) <EOL> def test_imsave_roundtrip ( self ) : <EOL> for shape in [ ( <NUM_LIT:10> , <NUM_LIT:10> ) , ( <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:3> ) , ( <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:4> ) ] : <EOL> for dtype in ( np . uint8 , np . uint16 , np . float32 , np . float64 ) : <EOL> x = np . ones ( shape , dtype = dtype ) * np . random . rand ( * shape ) <EOL> if np . issubdtype ( dtype , float ) : <EOL> yield self . roundtrip , dtype , x <EOL> else : <EOL> x = ( x * <NUM_LIT:255> ) . astype ( dtype ) <EOL> yield self . roundtrip , dtype , x <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from numpy . testing import run_module_suite <EOL> run_module_suite ( ) </s>
