<s> import warnings <EOL> import numpy as np <EOL> from numpy . testing import assert_array_almost_equal as assert_close <EOL> from numpy . testing import ( assert_array_equal , assert_raises , <EOL> assert_almost_equal ) <EOL> import skimage <EOL> from skimage import data <EOL> from skimage import exposure <EOL> from skimage . exposure . exposure import intensity_range <EOL> from skimage . color import rgb2gray <EOL> from skimage . util . dtype import dtype_range <EOL> from skimage . _shared . _warnings import expected_warnings <EOL> def test_negative_overflow ( ) : <EOL> im = np . array ( [ - <NUM_LIT:1> , <NUM_LIT> ] , dtype = np . int8 ) <EOL> frequencies , bin_centers = exposure . histogram ( im ) <EOL> assert_array_equal ( bin_centers , np . arange ( - <NUM_LIT:1> , <NUM_LIT> ) ) <EOL> assert frequencies [ <NUM_LIT:0> ] == <NUM_LIT:1> <EOL> assert frequencies [ - <NUM_LIT:1> ] == <NUM_LIT:1> <EOL> assert_array_equal ( frequencies [ <NUM_LIT:1> : - <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> def test_all_negative_image ( ) : <EOL> im = np . array ( [ - <NUM_LIT> , - <NUM_LIT:1> ] , dtype = np . int8 ) <EOL> frequencies , bin_centers = exposure . histogram ( im ) <EOL> assert_array_equal ( bin_centers , np . arange ( - <NUM_LIT> , <NUM_LIT:0> ) ) <EOL> assert frequencies [ <NUM_LIT:0> ] == <NUM_LIT:1> <EOL> assert frequencies [ - <NUM_LIT:1> ] == <NUM_LIT:1> <EOL> assert_array_equal ( frequencies [ <NUM_LIT:1> : - <NUM_LIT:1> ] , <NUM_LIT:0> ) <EOL> np . random . seed ( <NUM_LIT:0> ) <EOL> test_img_int = data . camera ( ) <EOL> test_img = skimage . img_as_float ( test_img_int ) <EOL> test_img = exposure . rescale_intensity ( test_img / <NUM_LIT> + <NUM_LIT:100> ) <EOL> def test_equalize_uint8_approx ( ) : <EOL> """<STR_LIT>""" <EOL> img_eq0 = exposure . equalize_hist ( test_img_int ) <EOL> img_eq1 = exposure . equalize_hist ( test_img_int , nbins = <NUM_LIT:3> ) <EOL> np . testing . assert_allclose ( img_eq0 , img_eq1 ) <EOL> def test_equalize_ubyte ( ) : <EOL> with expected_warnings ( [ '<STR_LIT>' ] ) : <EOL> img = skimage . img_as_ubyte ( test_img ) <EOL> img_eq = exposure . equalize_hist ( img ) <EOL> cdf , bin_edges = exposure . cumulative_distribution ( img_eq ) <EOL> check_cdf_slope ( cdf ) <EOL> def test_equalize_float ( ) : <EOL> img = skimage . img_as_float ( test_img ) <EOL> img_eq = exposure . equalize_hist ( img ) <EOL> cdf , bin_edges = exposure . cumulative_distribution ( img_eq ) <EOL> check_cdf_slope ( cdf ) <EOL> def test_equalize_masked ( ) : <EOL> img = skimage . img_as_float ( test_img ) <EOL> mask = np . zeros ( test_img . shape ) <EOL> mask [ <NUM_LIT:50> : <NUM_LIT> , <NUM_LIT:50> : <NUM_LIT> ] = <NUM_LIT:1> <EOL> img_mask_eq = exposure . equalize_hist ( img , mask = mask ) <EOL> img_eq = exposure . equalize_hist ( img ) <EOL> cdf , bin_edges = exposure . cumulative_distribution ( img_mask_eq ) <EOL> check_cdf_slope ( cdf ) <EOL> assert not ( img_eq == img_mask_eq ) . all ( ) <EOL> def check_cdf_slope ( cdf ) : <EOL> """<STR_LIT>""" <EOL> norm_intensity = np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , len ( cdf ) ) <EOL> slope , intercept = np . polyfit ( norm_intensity , cdf , <NUM_LIT:1> ) <EOL> assert <NUM_LIT> < slope < <NUM_LIT> <EOL> def test_intensity_range_uint8 ( ) : <EOL> image = np . array ( [ <NUM_LIT:0> , <NUM_LIT:1> ] , dtype = np . uint8 ) <EOL> input_and_expected = [ ( '<STR_LIT:image>' , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) , <EOL> ( '<STR_LIT>' , [ <NUM_LIT:0> , <NUM_LIT:255> ] ) , <EOL> ( ( <NUM_LIT:10> , <NUM_LIT:20> ) , [ <NUM_LIT:10> , <NUM_LIT:20> ] ) ] <EOL> for range_values , expected_values in input_and_expected : <EOL> out = intensity_range ( image , range_values = range_values ) <EOL> yield assert_array_equal , out , expected_values <EOL> def test_intensity_range_float ( ) : <EOL> image = np . array ( [ <NUM_LIT:0.1> , <NUM_LIT> ] , dtype = np . float64 ) <EOL> input_and_expected = [ ( '<STR_LIT:image>' , [ <NUM_LIT:0.1> , <NUM_LIT> ] ) , <EOL> ( '<STR_LIT>' , [ - <NUM_LIT:1> , <NUM_LIT:1> ] ) , <EOL> ( ( <NUM_LIT> , <NUM_LIT> ) , [ <NUM_LIT> , <NUM_LIT> ] ) ] <EOL> for range_values , expected_values in input_and_expected : <EOL> out = intensity_range ( image , range_values = range_values ) <EOL> yield assert_array_equal , out , expected_values <EOL> def test_intensity_range_clipped_float ( ) : <EOL> image = np . array ( [ <NUM_LIT:0.1> , <NUM_LIT> ] , dtype = np . float64 ) <EOL> out = intensity_range ( image , range_values = '<STR_LIT>' , clip_negative = True ) <EOL> assert_array_equal ( out , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> uint10_max = <NUM_LIT:2> ** <NUM_LIT:10> - <NUM_LIT:1> <EOL> uint12_max = <NUM_LIT:2> ** <NUM_LIT:12> - <NUM_LIT:1> <EOL> uint14_max = <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> <EOL> uint16_max = <NUM_LIT:2> ** <NUM_LIT:16> - <NUM_LIT:1> <EOL> def test_rescale_stretch ( ) : <EOL> image = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , dtype = np . uint8 ) <EOL> out = exposure . rescale_intensity ( image ) <EOL> assert out . dtype == np . uint8 <EOL> assert_close ( out , [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:255> ] ) <EOL> def test_rescale_shrink ( ) : <EOL> image = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> out = exposure . rescale_intensity ( image ) <EOL> assert_close ( out , [ <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:1> ] ) <EOL> def test_rescale_in_range ( ) : <EOL> image = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> out = exposure . rescale_intensity ( image , in_range = ( <NUM_LIT:0> , <NUM_LIT:255> ) ) <EOL> assert_close ( out , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_rescale_in_range_clip ( ) : <EOL> image = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> out = exposure . rescale_intensity ( image , in_range = ( <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> assert_close ( out , [ <NUM_LIT:0.5> , <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> def test_rescale_out_range ( ) : <EOL> image = np . array ( [ - <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:10> ] , dtype = np . int8 ) <EOL> out = exposure . rescale_intensity ( image , out_range = ( <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> assert out . dtype == np . int8 <EOL> assert_close ( out , [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_rescale_named_in_range ( ) : <EOL> image = np . array ( [ <NUM_LIT:0> , uint10_max , uint10_max + <NUM_LIT:100> ] , dtype = np . uint16 ) <EOL> out = exposure . rescale_intensity ( image , in_range = '<STR_LIT>' ) <EOL> assert_close ( out , [ <NUM_LIT:0> , uint16_max , uint16_max ] ) <EOL> def test_rescale_named_out_range ( ) : <EOL> image = np . array ( [ <NUM_LIT:0> , uint16_max ] , dtype = np . uint16 ) <EOL> out = exposure . rescale_intensity ( image , out_range = '<STR_LIT>' ) <EOL> assert_close ( out , [ <NUM_LIT:0> , uint10_max ] ) <EOL> def test_rescale_uint12_limits ( ) : <EOL> image = np . array ( [ <NUM_LIT:0> , uint16_max ] , dtype = np . uint16 ) <EOL> out = exposure . rescale_intensity ( image , out_range = '<STR_LIT>' ) <EOL> assert_close ( out , [ <NUM_LIT:0> , uint12_max ] ) <EOL> def test_rescale_uint14_limits ( ) : <EOL> image = np . array ( [ <NUM_LIT:0> , uint16_max ] , dtype = np . uint16 ) <EOL> out = exposure . rescale_intensity ( image , out_range = '<STR_LIT>' ) <EOL> assert_close ( out , [ <NUM_LIT:0> , uint14_max ] ) <EOL> def test_adapthist_scalar ( ) : <EOL> """<STR_LIT>""" <EOL> img = skimage . img_as_ubyte ( data . moon ( ) ) <EOL> adapted = exposure . equalize_adapthist ( img , kernel_size = <NUM_LIT:64> , clip_limit = <NUM_LIT> ) <EOL> assert adapted . min ( ) == <NUM_LIT:0.0> <EOL> assert adapted . max ( ) == <NUM_LIT:1.0> <EOL> assert img . shape == adapted . shape <EOL> full_scale = skimage . exposure . rescale_intensity ( skimage . img_as_float ( img ) ) <EOL> assert_almost_equal = np . testing . assert_almost_equal <EOL> assert_almost_equal ( peak_snr ( full_scale , adapted ) , <NUM_LIT> , <NUM_LIT:3> ) <EOL> assert_almost_equal ( norm_brightness_err ( full_scale , adapted ) , <EOL> <NUM_LIT> , <NUM_LIT:3> ) <EOL> return img , adapted <EOL> def test_adapthist_grayscale ( ) : <EOL> """<STR_LIT>""" <EOL> img = skimage . img_as_float ( data . astronaut ( ) ) <EOL> img = rgb2gray ( img ) <EOL> img = np . dstack ( ( img , img , img ) ) <EOL> with expected_warnings ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) : <EOL> adapted_old = exposure . equalize_adapthist ( img , <NUM_LIT:10> , <NUM_LIT:9> , clip_limit = <NUM_LIT> , <EOL> nbins = <NUM_LIT> ) <EOL> with expected_warnings ( [ '<STR_LIT>' ] ) : <EOL> adapted = exposure . equalize_adapthist ( img , kernel_size = ( <NUM_LIT> , <NUM_LIT> ) , <EOL> clip_limit = <NUM_LIT> , nbins = <NUM_LIT> ) <EOL> assert img . shape == adapted . shape <EOL> assert_almost_equal ( peak_snr ( img , adapted ) , <NUM_LIT> , <NUM_LIT:3> ) <EOL> assert_almost_equal ( norm_brightness_err ( img , adapted ) , <NUM_LIT> , <NUM_LIT:3> ) <EOL> return data , adapted <EOL> def test_adapthist_color ( ) : <EOL> """<STR_LIT>""" <EOL> img = skimage . img_as_uint ( data . astronaut ( ) ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> hist , bin_centers = exposure . histogram ( img ) <EOL> assert len ( w ) > <NUM_LIT:0> <EOL> with expected_warnings ( [ '<STR_LIT>' ] ) : <EOL> adapted = exposure . equalize_adapthist ( img , clip_limit = <NUM_LIT> ) <EOL> assert_almost_equal = np . testing . assert_almost_equal <EOL> assert adapted . min ( ) == <NUM_LIT:0> <EOL> assert adapted . max ( ) == <NUM_LIT:1.0> <EOL> assert img . shape == adapted . shape <EOL> full_scale = skimage . exposure . rescale_intensity ( img ) <EOL> assert_almost_equal ( peak_snr ( full_scale , adapted ) , <NUM_LIT> , <NUM_LIT:1> ) <EOL> assert_almost_equal ( norm_brightness_err ( full_scale , adapted ) , <NUM_LIT> , <NUM_LIT:2> ) <EOL> return data , adapted <EOL> def test_adapthist_alpha ( ) : <EOL> """<STR_LIT>""" <EOL> img = skimage . img_as_float ( data . astronaut ( ) ) <EOL> alpha = np . ones ( ( img . shape [ <NUM_LIT:0> ] , img . shape [ <NUM_LIT:1> ] ) , dtype = float ) <EOL> img = np . dstack ( ( img , alpha ) ) <EOL> with expected_warnings ( [ '<STR_LIT>' ] ) : <EOL> adapted = exposure . equalize_adapthist ( img ) <EOL> assert adapted . shape != img . shape <EOL> img = img [ : , : , : <NUM_LIT:3> ] <EOL> full_scale = skimage . exposure . rescale_intensity ( img ) <EOL> assert img . shape == adapted . shape <EOL> assert_almost_equal = np . testing . assert_almost_equal <EOL> assert_almost_equal ( peak_snr ( full_scale , adapted ) , <NUM_LIT> , <NUM_LIT:2> ) <EOL> assert_almost_equal ( norm_brightness_err ( full_scale , adapted ) , <NUM_LIT> , <NUM_LIT:3> ) <EOL> def peak_snr ( img1 , img2 ) : <EOL> """<STR_LIT>""" <EOL> if img1 . ndim == <NUM_LIT:3> : <EOL> img1 , img2 = rgb2gray ( img1 . copy ( ) ) , rgb2gray ( img2 . copy ( ) ) <EOL> img1 = skimage . img_as_float ( img1 ) <EOL> img2 = skimage . img_as_float ( img2 ) <EOL> mse = <NUM_LIT:1.> / img1 . size * np . square ( img1 - img2 ) . sum ( ) <EOL> _ , max_ = dtype_range [ img1 . dtype . type ] <EOL> return <NUM_LIT:20> * np . log ( max_ / mse ) <EOL> def norm_brightness_err ( img1 , img2 ) : <EOL> """<STR_LIT>""" <EOL> if img1 . ndim == <NUM_LIT:3> : <EOL> img1 , img2 = rgb2gray ( img1 ) , rgb2gray ( img2 ) <EOL> ambe = np . abs ( img1 . mean ( ) - img2 . mean ( ) ) <EOL> nbe = ambe / dtype_range [ img1 . dtype . type ] [ <NUM_LIT:1> ] <EOL> return nbe <EOL> def test_adjust_gamma_one ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . random . uniform ( <NUM_LIT:0> , <NUM_LIT:255> , ( <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> result = exposure . adjust_gamma ( image , <NUM_LIT:1> ) <EOL> assert_array_equal ( result , image ) <EOL> def test_adjust_gamma_zero ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . random . uniform ( <NUM_LIT:0> , <NUM_LIT:255> , ( <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> result = exposure . adjust_gamma ( image , <NUM_LIT:0> ) <EOL> dtype = image . dtype . type <EOL> assert_array_equal ( result , dtype_range [ dtype ] [ <NUM_LIT:1> ] ) <EOL> def test_adjust_gamma_less_one ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> expected = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , dtype = np . uint8 ) <EOL> result = exposure . adjust_gamma ( image , <NUM_LIT:0.5> ) <EOL> assert_array_equal ( result , expected ) <EOL> def test_adjust_gamma_greater_one ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> expected = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , <EOL> [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:12> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:64> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , dtype = np . uint8 ) <EOL> result = exposure . adjust_gamma ( image , <NUM_LIT:2> ) <EOL> assert_array_equal ( result , expected ) <EOL> def test_adjust_gamma_neggative ( ) : <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> assert_raises ( ValueError , exposure . adjust_gamma , image , - <NUM_LIT:1> ) <EOL> def test_adjust_log ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> expected = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:11> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , dtype = np . uint8 ) <EOL> result = exposure . adjust_log ( image , <NUM_LIT:1> ) <EOL> assert_array_equal ( result , expected ) <EOL> def test_adjust_inv_log ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> expected = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT:11> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , dtype = np . uint8 ) <EOL> result = exposure . adjust_log ( image , <NUM_LIT:1> , True ) <EOL> assert_array_equal ( result , expected ) <EOL> def test_adjust_sigmoid_cutoff_one ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> expected = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:16> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:32> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:64> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , dtype = np . uint8 ) <EOL> result = exposure . adjust_sigmoid ( image , <NUM_LIT:1> , <NUM_LIT:5> ) <EOL> assert_array_equal ( result , expected ) <EOL> def test_adjust_sigmoid_cutoff_zero ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> expected = np . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , dtype = np . uint8 ) <EOL> result = exposure . adjust_sigmoid ( image , <NUM_LIT:0> , <NUM_LIT:10> ) <EOL> assert_array_equal ( result , expected ) <EOL> def test_adjust_sigmoid_cutoff_half ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> expected = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:16> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:50> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:64> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] , dtype = np . uint8 ) <EOL> result = exposure . adjust_sigmoid ( image , <NUM_LIT:0.5> , <NUM_LIT:10> ) <EOL> assert_array_equal ( result , expected ) <EOL> def test_adjust_inv_sigmoid_cutoff_half ( ) : <EOL> """<STR_LIT>""" <EOL> image = np . arange ( <NUM_LIT:0> , <NUM_LIT:255> , <NUM_LIT:4> , np . uint8 ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> expected = np . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:10> , <NUM_LIT:8> , <NUM_LIT:7> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> ] ] , dtype = np . uint8 ) <EOL> result = exposure . adjust_sigmoid ( image , <NUM_LIT:0.5> , <NUM_LIT:10> , True ) <EOL> assert_array_equal ( result , expected ) <EOL> def test_negative ( ) : <EOL> image = np . arange ( - <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:4> ) . reshape ( <NUM_LIT:8> , <NUM_LIT:8> ) . astype ( np . double ) <EOL> assert_raises ( ValueError , exposure . adjust_gamma , image ) <EOL> def test_is_low_contrast ( ) : <EOL> image = np . linspace ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:100> ) <EOL> assert exposure . is_low_contrast ( image ) <EOL> image [ - <NUM_LIT:1> ] = <NUM_LIT:1> <EOL> assert exposure . is_low_contrast ( image ) <EOL> assert not exposure . is_low_contrast ( image , upper_percentile = <NUM_LIT:100> ) <EOL> image = ( image * <NUM_LIT:255> ) . astype ( np . uint8 ) <EOL> assert exposure . is_low_contrast ( image ) <EOL> assert not exposure . is_low_contrast ( image , upper_percentile = <NUM_LIT:100> ) <EOL> image = ( image . astype ( np . uint16 ) ) * <NUM_LIT:2> ** <NUM_LIT:8> <EOL> assert exposure . is_low_contrast ( image ) <EOL> assert not exposure . is_low_contrast ( image , upper_percentile = <NUM_LIT:100> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from numpy import testing <EOL> testing . run_module_suite ( ) </s>
