<s> from collections import namedtuple <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from mpl_toolkits . axes_grid1 import make_axes_locatable <EOL> from ... util import dtype as dtypes <EOL> from ... exposure import is_low_contrast <EOL> from ... util . colormap import viridis <EOL> from ... _shared . utils import warn <EOL> _default_colormap = '<STR_LIT>' <EOL> _nonstandard_colormap = viridis <EOL> _diverging_colormap = '<STR_LIT>' <EOL> ImageProperties = namedtuple ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def _get_image_properties ( image ) : <EOL> """<STR_LIT>""" <EOL> immin , immax = np . min ( image ) , np . max ( image ) <EOL> imtype = image . dtype . type <EOL> try : <EOL> lo , hi = dtypes . dtype_range [ imtype ] <EOL> except KeyError : <EOL> lo , hi = immin , immax <EOL> signed = immin < <NUM_LIT:0> <EOL> out_of_range_float = ( np . issubdtype ( image . dtype , np . float ) and <EOL> ( immin < lo or immax > hi ) ) <EOL> low_dynamic_range = ( immin != immax and <EOL> is_low_contrast ( image ) ) <EOL> unsupported_dtype = image . dtype not in dtypes . _supported_types <EOL> return ImageProperties ( signed , out_of_range_float , <EOL> low_dynamic_range , unsupported_dtype ) <EOL> def _raise_warnings ( image_properties ) : <EOL> """<STR_LIT>""" <EOL> ip = image_properties <EOL> if ip . unsupported_dtype : <EOL> warn ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if ip . low_dynamic_range : <EOL> warn ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if ip . out_of_range_float : <EOL> warn ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def _get_display_range ( image ) : <EOL> """<STR_LIT>""" <EOL> ip = _get_image_properties ( image ) <EOL> immin , immax = np . min ( image ) , np . max ( image ) <EOL> if ip . signed : <EOL> magnitude = max ( abs ( immin ) , abs ( immax ) ) <EOL> lo , hi = - magnitude , magnitude <EOL> cmap = _diverging_colormap <EOL> elif any ( ip ) : <EOL> _raise_warnings ( ip ) <EOL> lo , hi = immin , immax <EOL> cmap = _nonstandard_colormap <EOL> else : <EOL> lo = <NUM_LIT:0> <EOL> imtype = image . dtype . type <EOL> hi = dtypes . dtype_range [ imtype ] [ <NUM_LIT:1> ] <EOL> cmap = _default_colormap <EOL> return lo , hi , cmap <EOL> def imshow ( im , ax = None , show_cbar = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if kwargs . get ( '<STR_LIT>' , None ) == '<STR_LIT>' : <EOL> kwargs [ '<STR_LIT>' ] = viridis <EOL> lo , hi , cmap = _get_display_range ( im ) <EOL> kwargs . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> kwargs . setdefault ( '<STR_LIT>' , cmap ) <EOL> kwargs . setdefault ( '<STR_LIT>' , lo ) <EOL> kwargs . setdefault ( '<STR_LIT>' , hi ) <EOL> ax = ax or plt . gca ( ) <EOL> ax_im = ax . imshow ( im , ** kwargs ) <EOL> if ( cmap != _default_colormap and show_cbar is not False ) or show_cbar : <EOL> divider = make_axes_locatable ( ax ) <EOL> cax = divider . append_axes ( "<STR_LIT:right>" , size = "<STR_LIT>" , pad = <NUM_LIT> ) <EOL> plt . colorbar ( ax_im , cax = cax ) <EOL> ax . set_adjustable ( '<STR_LIT>' ) <EOL> ax . get_figure ( ) . tight_layout ( ) <EOL> return ax_im <EOL> def imshow_collection ( ic , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> fig , axes = plt . subplots ( <NUM_LIT:1> , len ( ic ) ) <EOL> for n , image in enumerate ( ic ) : <EOL> kwargs [ '<STR_LIT>' ] = axes [ n ] <EOL> imshow ( image , * args , ** kwargs ) <EOL> imread = plt . imread <EOL> show = plt . show <EOL> def _app_show ( ) : <EOL> show ( ) </s>
