def test_rgb_lch_roundtrip(self): rgb = img_as_float(self.img_rgb) lab = rgb2lab(rgb) lch = lab2lch(lab) lab2 = lch2lab(lch) rgb2 = lab2rgb(lab2) assert_array_almost_equal(rgb, rgb2)
def test_apply_parallel_lazy(): import dask.array as da # data a = np.arange(144).reshape(12, 12).astype(float) d = da.from_array(a, chunks=(6, 6)) # apply the filter expected1 = threshold_local(a, 3) result1 = apply_parallel(threshold_local, a, chunks=(6, 6), depth=5, extra_arguments=(3,), extra_keywords={'mode': 'reflect'}, compute=False) # apply the filter on a Dask Array result2 = apply_parallel(threshold_local, d, depth=5, extra_arguments=(3,), extra_keywords={'mode': 'reflect'}, compute=False) assert isinstance(result1, da.Array) assert_array_almost_equal(result1.compute(), expected1) assert isinstance(result2, da.Array) assert_array_almost_equal(result2.compute(), expected1)
def test_absolute_threshold(self): image = np.zeros((5, 5), dtype=np.uint8) image[1, 1] = 10 image[3, 3] = 20 peaks = peak.peak_local_max(image, min_distance=1, threshold_abs=10) assert len(peaks) == 1 assert_array_almost_equal(peaks, [(3, 3)])
def test_cross_correlate_masked_over_axes(): """Masked normalized cross-correlation over axes should be equivalent to a loop over non-transform axes.""" # See random number generator for reproducible results np.random.seed(23) arr1 = np.random.random((8, 8, 5)) arr2 = np.random.random((8, 8, 5)) m1 = np.random.choice([True, False], arr1.shape) m2 = np.random.choice([True, False], arr2.shape) # Loop over last axis with_loop = np.empty_like(arr1, dtype=np.complex) for index in range(arr1.shape[-1]): with_loop[:, :, index] = cross_correlate_masked(arr1[:, :, index], arr2[:, :, index], m1[:, :, index], m2[:, :, index], axes=(0, 1), mode='same') over_axes = cross_correlate_masked( arr1, arr2, m1, m2, axes=(0, 1), mode='same') testing.assert_array_almost_equal(with_loop, over_axes)
def test_yuv_roundtrip(self): img_rgb = img_as_float(self.img_rgb)[::16, ::16] assert_array_almost_equal(yuv2rgb(rgb2yuv(img_rgb)), img_rgb) assert_array_almost_equal(yiq2rgb(rgb2yiq(img_rgb)), img_rgb) assert_array_almost_equal(ypbpr2rgb(rgb2ypbpr(img_rgb)), img_rgb) assert_array_almost_equal(ycbcr2rgb(rgb2ycbcr(img_rgb)), img_rgb) assert_array_almost_equal(ydbdr2rgb(rgb2ydbdr(img_rgb)), img_rgb)
def test_roberts_diagonal2(): """Roberts' filter on a diagonal edge should be a diagonal line.""" image = np.rot90(np.tri(10, 10, 0), 3) expected = ~np.rot90(np.tri(10, 10, -1).astype(bool) | np.tri(10, 10, -2).astype(bool).transpose()) expected = _mask_filter_result(expected, None) result = filters.roberts(image).astype(bool) assert_array_almost_equal(result, expected)
def roundtrip(self, x, scaling=1): f = NamedTemporaryFile(suffix='.png') fname = f.name f.close() imsave(fname, x) y = imread(fname) assert_array_almost_equal((x * scaling).astype(np.int32), y)
def test_apply_parallel_wrap(): def wrapped(arr): return gaussian(arr, 1, mode='wrap') a = np.arange(144).reshape(12, 12).astype(float) expected = gaussian(a, 1, mode='wrap') result = apply_parallel(wrapped, a, chunks=(6, 6), depth=5, mode='wrap') assert_array_almost_equal(result, expected)
def test_offset_not_none(): """Test reconstruction with valid offset parameter""" seed = np.array([0, 3, 6, 2, 1, 1, 1, 4, 2, 0]) mask = np.array([0, 8, 6, 8, 8, 8, 8, 4, 4, 0]) expected = np.array([0, 3, 6, 6, 6, 6, 6, 4, 4, 0]) assert_array_almost_equal( reconstruction(seed, mask, method='dilation', selem=np.ones(3), offset=np.array([0])), expected)
def test_weighted_moments_normalized(): wnu = regionprops(SAMPLE, intensity_image=INTENSITY_SAMPLE )[0].weighted_moments_normalized.T # test used x/y coord ref = np.array( [[ np.nan, np.nan, 0.0873590903, -0.0161217406], [ np.nan, -0.0160405109, -0.0031421072, -0.0031376984], [ 0.230146783, 0.0457932622, 0.0165315478, 0.0043903193], [-0.0162529732, -0.0104598869, -0.0028544152, -0.0011057191]] ) assert_array_almost_equal(wnu, ref)
def test_no_chunks(): a = np.ones(1 * 4 * 8 * 9).reshape(1, 4, 8, 9) def add_42(arr): return arr + 42 expected = add_42(a) result = apply_parallel(add_42, a) assert_array_almost_equal(result, expected)
def test_weighted_moments_hu(): whu = regionprops(SAMPLE, intensity_image=INTENSITY_SAMPLE )[0].weighted_moments_hu ref = np.array([ 3.1750587329e-01, 2.1417517159e-02, 2.3609322038e-02, 1.2565683360e-03, 8.3014209421e-07, -3.5073773473e-05, -6.7936409056e-06 ]) assert_array_almost_equal(whu, ref)
def test_moments_hu(): hu = regionprops(SAMPLE)[0].moments_hu ref = np.array([ 3.27117627e-01, 2.63869194e-02, 2.35390060e-02, 1.23151193e-03, 1.38882330e-06, -2.72586158e-05, -6.48350653e-06 ]) # bug in OpenCV caused in Central Moments calculation? assert_array_almost_equal(hu, ref)
def test_weighted_moments(): wm = regionprops(SAMPLE, intensity_image=INTENSITY_SAMPLE )[0].weighted_moments.T # test used x/y coords ref = np.array( [[ 7.4000000000e+01, 4.1000000000e+02, 2.7500000000e+03, 1.9778000000e+04], [ 6.9900000000e+02, 3.7850000000e+03, 2.4855000000e+04, 1.7500100000e+05], [ 7.8630000000e+03, 4.4063000000e+04, 2.9347700000e+05, 2.0810510000e+06], [ 9.7317000000e+04, 5.7256700000e+05, 3.9007170000e+06, 2.8078871000e+07]] ) assert_array_almost_equal(wm, ref)
def test_weighted_moments_central(): wmu = regionprops(SAMPLE, intensity_image=INTENSITY_SAMPLE )[0].weighted_moments_central.T # test used x/y coords ref = np.array( [[ 7.4000000000e+01, -2.1316282073e-13, 4.7837837838e+02, -7.5943608473e+02], [ 3.7303493627e-14, -8.7837837838e+01, -1.4801314828e+02, -1.2714707125e+03], [ 1.2602837838e+03, 2.1571526662e+03, 6.6989799420e+03, 1.5304076361e+04], [ -7.6561796932e+02, -4.2385971907e+03, -9.9501164076e+03, -3.3156729271e+04]] ) np.set_printoptions(precision=10) assert_array_almost_equal(wmu, ref)
def test_apply_parallel_rgb(depth, chunks, dtype): cat = data.chelsea().astype(dtype) / 255. func = color.rgb2ycbcr cat_ycbcr_expected = func(cat) cat_ycbcr = apply_parallel(func, cat, chunks=chunks, depth=depth, dtype=dtype, multichannel=True) assert_equal(cat_ycbcr.dtype, cat.dtype) assert_array_almost_equal(cat_ycbcr_expected, cat_ycbcr)
def test_gaussian_mssim_and_gradient_vs_Matlab(): # comparison to Matlab implementation of N. Avanaki: # https://ece.uwaterloo.ca/~nnikvand/Coderep/SHINE%20TOOLBOX/SHINEtoolbox/ # Note: final line of ssim_sens.m was modified to discard image borders ref = np.load(os.path.join(data_dir, 'mssim_matlab_output.npz')) grad_matlab = ref['grad_matlab'] mssim_matlab = float(ref['mssim_matlab']) mssim, grad = ssim(cam, cam_noisy, gaussian_weights=True, gradient=True, use_sample_covariance=False) assert_almost_equal(mssim, mssim_matlab, decimal=3) # check almost equal aside from object borders assert_array_almost_equal(grad_matlab[5:-5], grad[5:-5])
def test_apply_parallel_nearest(): def wrapped(arr): return gaussian(arr, 1, mode='nearest') a = np.arange(144).reshape(12, 12).astype(float) expected = gaussian(a, 1, mode='nearest') result = apply_parallel(wrapped, a, chunks=(6, 6), depth={ 0: 5, 1: 5 }, mode='nearest') assert_array_almost_equal(result, expected)
def test_rgb2luv_brucelindbloom(self): """ Test the RGB->Lab conversion by comparing to the calculator on the authoritative Bruce Lindbloom [website](http://brucelindbloom.com/index.html?ColorCalculator.html). """ # Obtained with D65 white point, sRGB model and gamma gt_for_colbars = np.array([[100, 0, 0], [97.1393, 7.7056, 106.7866], [91.1132, -70.4773, -15.2042], [87.7347, -83.0776, 107.3985], [60.3242, 84.0714, -108.6834], [53.2408, 175.0151, 37.7564], [32.2970, -9.4054, -130.3423], [0, 0, 0]]).T gt_array = np.swapaxes(gt_for_colbars.reshape(3, 4, 2), 0, 2) assert_array_almost_equal(rgb2luv(self.colbars_array), gt_array, decimal=2)
def test_rgb2lab_brucelindbloom(self): """ Test the RGB->Lab conversion by comparing to the calculator on the authoritative Bruce Lindbloom [website](http://brucelindbloom.com/index.html?ColorCalculator.html). """ # Obtained with D65 white point, sRGB model and gamma gt_for_colbars = np.array([[100, 0, 0], [97.1393, -21.5537, 94.4780], [91.1132, -48.0875, -14.1312], [87.7347, -86.1827, 83.1793], [60.3242, 98.2343, -60.8249], [53.2408, 80.0925, 67.2032], [32.2970, 79.1875, -107.8602], [0, 0, 0]]).T gt_array = np.swapaxes(gt_for_colbars.reshape(3, 4, 2), 0, 2) assert_array_almost_equal(rgb2lab(self.colbars_array), gt_array, decimal=2)
def check(): expected = self.refs_3d[filter] if outdt is not None: out = np.zeros_like(expected, dtype=outdt) else: out = None result = getattr(rank, filter)(self.volume, self.footprint_3d, out=out) if outdt is not None: # Avoid rounding issues comparing to expected result if filter == 'sum': # sum test data seems to be 8-bit disguised as 16-bit datadt = np.uint8 else: datadt = expected.dtype result = result.astype(datadt) assert_array_almost_equal(expected, result)
def test_rgb2lab_brucelindbloom(self): """ Test the RGB->Lab conversion by comparing to the calculator on the authoritative Bruce Lindbloom [website](http://brucelindbloom.com/index.html?ColorCalculator.html). """ # Obtained with D65 white point, sRGB model and gamma gt_for_colbars = np.array([ [100,0,0], [97.1393, -21.5537, 94.4780], [91.1132, -48.0875, -14.1312], [87.7347, -86.1827, 83.1793], [60.3242, 98.2343, -60.8249], [53.2408, 80.0925, 67.2032], [32.2970, 79.1875, -107.8602], [0,0,0]]).T gt_array = np.swapaxes(gt_for_colbars.reshape(3, 4, 2), 0, 2) assert_array_almost_equal(rgb2lab(self.colbars_array), gt_array, decimal=2)
def test_rgb2luv_brucelindbloom(self): """ Test the RGB->Lab conversion by comparing to the calculator on the authoritative Bruce Lindbloom [website](http://brucelindbloom.com/index.html?ColorCalculator.html). """ # Obtained with D65 white point, sRGB model and gamma gt_for_colbars = np.array([ [100, 0, 0], [97.1393, 7.7056, 106.7866], [91.1132, -70.4773, -15.2042], [87.7347, -83.0776, 107.3985], [60.3242, 84.0714, -108.6834], [53.2408, 175.0151, 37.7564], [32.2970, -9.4054, -130.3423], [0, 0, 0]]).T gt_array = np.swapaxes(gt_for_colbars.reshape(3, 4, 2), 0, 2) assert_array_almost_equal(rgb2luv(self.colbars_array), gt_array, decimal=2)
def test_apply_parallel(): # data a = np.arange(144).reshape(12, 12).astype(float) # apply the filter expected1 = threshold_local(a, 3) result1 = apply_parallel(threshold_local, a, chunks=(6, 6), depth=5, extra_arguments=(3,), extra_keywords={'mode': 'reflect'}) assert_array_almost_equal(result1, expected1) def wrapped_gauss(arr): return gaussian(arr, 1, mode='reflect') expected2 = gaussian(a, 1, mode='reflect') result2 = apply_parallel(wrapped_gauss, a, chunks=(6, 6), depth=5) assert_array_almost_equal(result2, expected2)
def test_overlay_custom_saturation(): rgb_img = np.random.uniform(size=(10, 10, 3)) labels = np.ones((10, 10), dtype=np.int64) labels[5:, 5:] = 2 labels[:3, :3] = 0 alpha = 0.3 saturation = 0.3 rgb = label2rgb(labels, image=rgb_img, alpha=alpha, bg_label=0, saturation=saturation) hsv = rgb2hsv(rgb_img) hsv[..., 1] *= saturation saturaded_img = hsv2rgb(hsv) # check that rgb part of input image is saturated, where labels=0 assert_array_almost_equal(saturaded_img[:3, :3] * (1 - alpha), rgb[:3, :3])
def check(): expected = self.refs_3d[filter] if outdt is not None: out = np.zeros_like(expected, dtype=outdt) else: out = None result = getattr(rank, filter)(self.volume, self.footprint_3d, out=out) if outdt is not None: # Avoid rounding issues comparing to expected result if filter == 'sum': # sum test data seems to be 8-bit disguised as 16-bit datadt = np.uint8 else: datadt = expected.dtype # Take modulus first to avoid undefined behavior for # float->uint8 conversions. result = np.mod(result, 256.0).astype(datadt) assert_array_almost_equal(expected, result)
def test_lab2xyz(self): assert_array_almost_equal(lab2xyz(self.lab_array), self.xyz_array, decimal=3) # Test the conversion with the rest of the illuminants. for I in ["d50", "d55", "d65", "d75"]: for obs in ["2", "10"]: fname = "lab_array_{0}_{1}.npy".format(I, obs) lab_array_I_obs = np.load( os.path.join(os.path.dirname(__file__), 'data', fname)) assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, obs), self.xyz_array, decimal=3) for I in ["a", "e"]: fname = "lab_array_{0}_2.npy".format(I, obs) lab_array_I_obs = np.load( os.path.join(os.path.dirname(__file__), 'data', fname)) assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, "2"), self.xyz_array, decimal=3) # And we include a call to test the exception handling in the code. try: xs = lab2xyz(lab_array_I_obs, "NaI", "2") # Not an illuminant except ValueError: pass try: xs = lab2xyz(lab_array_I_obs, "d50", "42") # Not a degree except ValueError: pass
def test_apply_parallel(): import dask.array as da # data a = np.arange(144).reshape(12, 12).astype(float) # apply the filter expected1 = threshold_local(a, 3) result1 = apply_parallel(threshold_local, a, chunks=(6, 6), depth=5, extra_arguments=(3,), extra_keywords={'mode': 'reflect'}) assert_array_almost_equal(result1, expected1) def wrapped_gauss(arr): return gaussian(arr, 1, mode='reflect') expected2 = gaussian(a, 1, mode='reflect') result2 = apply_parallel(wrapped_gauss, a, chunks=(6, 6), depth=5) assert_array_almost_equal(result2, expected2) expected3 = gaussian(a, 1, mode='reflect') result3 = apply_parallel( wrapped_gauss, da.from_array(a, chunks=(6, 6)), depth=5, compute=True ) assert isinstance(result3, np.ndarray) assert_array_almost_equal(result3, expected3)
def test_lab2xyz(self): assert_array_almost_equal(lab2xyz(self.lab_array), self.xyz_array, decimal=3) # Test the conversion with the rest of the illuminants. for I in ["A", "B", "C", "d50", "d55", "d65"]: I = I.lower() for obs in ["2", "10", "R"]: obs = obs.lower() fname = "color/tests/data/lab_array_{0}_{1}.npy".format(I, obs) lab_array_I_obs = np.load(fetch(fname)) assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, obs), self.xyz_array, decimal=3) for I in ["d75", "e"]: fname = "color/tests/data/lab_array_{0}_2.npy".format(I) lab_array_I_obs = np.load(fetch(fname)) assert_array_almost_equal(lab2xyz(lab_array_I_obs, I, "2"), self.xyz_array, decimal=3) # And we include a call to test the exception handling in the code. try: xs = lab2xyz(lab_array_I_obs, "NaI", "2") # Not an illuminant except ValueError: pass try: xs = lab2xyz(lab_array_I_obs, "d50", "42") # Not a degree except ValueError: pass
def test_apply_parallel(): import dask.array as da # data a = np.arange(144).reshape(12, 12).astype(float) # apply the filter expected1 = threshold_local(a, 3) result1 = apply_parallel(threshold_local, a, chunks=(6, 6), depth=5, extra_arguments=(3, ), extra_keywords={'mode': 'reflect'}) assert_array_almost_equal(result1, expected1) def wrapped_gauss(arr): return gaussian(arr, 1, mode='reflect') expected2 = gaussian(a, 1, mode='reflect') result2 = apply_parallel(wrapped_gauss, a, chunks=(6, 6), depth=5) assert_array_almost_equal(result2, expected2) expected3 = gaussian(a, 1, mode='reflect') result3 = apply_parallel(wrapped_gauss, da.from_array(a, chunks=(6, 6)), depth=5, compute=True) assert isinstance(result3, np.ndarray) assert_array_almost_equal(result3, expected3)
def test_alpha(): image = np.random.uniform(size=(3, 3)) label = np.random.randint(0, 9, size=(3, 3)) # If we set `alpha = 0`, then rgb should match image exactly. rgb = label2rgb(label, image=image, alpha=0, image_alpha=1, bg_label=-1) assert_array_almost_equal(rgb[..., 0], image) assert_array_almost_equal(rgb[..., 1], image) assert_array_almost_equal(rgb[..., 2], image)
def test_two_image_peaks(): """Test reconstruction with two peak pixels isolated by the mask""" image = np.array([[1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 3, 1], [1, 1, 1, 1, 1, 1, 1, 1]]) mask = np.array([[4, 4, 4, 1, 1, 1, 1, 1], [4, 4, 4, 1, 1, 1, 1, 1], [4, 4, 4, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 4, 4, 4], [1, 1, 1, 1, 1, 4, 4, 4], [1, 1, 1, 1, 1, 4, 4, 4]]) expected = np.array([[2, 2, 2, 1, 1, 1, 1, 1], [2, 2, 2, 1, 1, 1, 1, 1], [2, 2, 2, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 3, 3, 3], [1, 1, 1, 1, 1, 3, 3, 3], [1, 1, 1, 1, 1, 3, 3, 3]]) assert_array_almost_equal(reconstruction(image, mask), expected)
def check(): expected = self.refs[filter] if outdt is not None: out = np.zeros_like(expected, dtype=outdt) else: out = None result = getattr(rank, filter)(self.image, self.footprint, out=out) if filter == "entropy": # There may be some arch dependent rounding errors # See the discussions in # https://github.com/scikit-image/scikit-image/issues/3091 # https://github.com/scikit-image/scikit-image/issues/2528 if outdt is not None: # Adjust expected precision expected = expected.astype(outdt) assert_allclose(expected, result, atol=0, rtol=1E-15) elif filter == "otsu": # OTSU May also have some optimization dependent failures # See the discussions in # https://github.com/scikit-image/scikit-image/issues/3091 # Pixel 3, 5 was found to be problematic. It can take either # a value of 41 or 81 depending on the specific optimizations # used. assert result[3, 5] in [41, 81] result[3, 5] = 81 # Pixel [19, 18] is also found to be problematic for the same # reason. assert result[19, 18] in [141, 172] result[19, 18] = 172 assert_array_almost_equal(expected, result) else: if outdt is not None: # Avoid rounding issues comparing to expected result. # Take modulus first to avoid undefined behavior for # float->uint8 conversions. result = np.mod(result, 256.0).astype(expected.dtype) assert_array_almost_equal(expected, result)
def test_bbox(): bbox = regionprops(SAMPLE)[0].bbox assert_array_almost_equal(bbox, (0, 0, SAMPLE.shape[0], SAMPLE.shape[1])) SAMPLE_mod = SAMPLE.copy() SAMPLE_mod[:, -1] = 0 bbox = regionprops(SAMPLE_mod)[0].bbox assert_array_almost_equal(bbox, (0, 0, SAMPLE.shape[0], SAMPLE.shape[1]-1)) bbox = regionprops(SAMPLE_3D)[0].bbox assert_array_almost_equal(bbox, (1, 1, 1, 4, 3, 3))
def test_luv2xyz(self): assert_array_almost_equal(luv2xyz(self.luv_array), self.xyz_array, decimal=3) # Test the conversion with the rest of the illuminants. for I in ["d50", "d55", "d65", "d75"]: for obs in ["2", "10"]: fname = "color/tests/data/luv_array_{0}_{1}.npy".format(I, obs) luv_array_I_obs = np.load(fetch(fname)) assert_array_almost_equal(luv2xyz(luv_array_I_obs, I, obs), self.xyz_array, decimal=3) for I in ["a", "e"]: fname = "color/tests/data/luv_array_{0}_2.npy".format(I, obs) luv_array_I_obs = np.load(fetch(fname)) assert_array_almost_equal(luv2xyz(luv_array_I_obs, I, "2"), self.xyz_array, decimal=3)
def test_luv2xyz(self): assert_array_almost_equal(luv2xyz(self.luv_array), self.xyz_array, decimal=3) # Test the conversion with the rest of the illuminants. for I in ["d50", "d55", "d65", "d75"]: for obs in ["2", "10"]: fname = "luv_array_{0}_{1}.npy".format(I, obs) luv_array_I_obs = np.load( os.path.join(os.path.dirname(__file__), 'data', fname)) assert_array_almost_equal(luv2xyz(luv_array_I_obs, I, obs), self.xyz_array, decimal=3) for I in ["a", "e"]: fname = "luv_array_{0}_2.npy".format(I, obs) luv_array_I_obs = np.load( os.path.join(os.path.dirname(__file__), 'data', fname)) assert_array_almost_equal(luv2xyz(luv_array_I_obs, I, "2"), self.xyz_array, decimal=3)
def test_xyz2luv(self): assert_array_almost_equal(xyz2luv(self.xyz_array), self.luv_array, decimal=3) # Test the conversion with the rest of the illuminants. for I in ["A", "B", "C", "d50", "d55", "d65"]: I = I.lower() for obs in ["2", "10", "R"]: obs = obs.lower() fname = "color/tests/data/luv_array_{0}_{1}.npy".format(I, obs) luv_array_I_obs = np.load(fetch(fname)) assert_array_almost_equal(luv_array_I_obs, xyz2luv(self.xyz_array, I, obs), decimal=2) for I in ["d75", "e"]: fname = "color/tests/data/luv_array_{0}_2.npy".format(I) luv_array_I_obs = np.load(fetch(fname)) assert_array_almost_equal(luv_array_I_obs, xyz2luv(self.xyz_array, I, "2"), decimal=2)
def test_rescale_out_range(): image = np.array([-10, 0, 10], dtype=np.int8) out = exposure.rescale_intensity(image, out_range=(0, 127)) assert out.dtype == np.int8 assert_array_almost_equal(out, [0, 63, 127])
def test_rescale_uint14_limits(): image = np.array([0, uint16_max], dtype=np.uint16) out = exposure.rescale_intensity(image, out_range='uint14') assert_array_almost_equal(out, [0, uint14_max])
def test_rescale_same_values(): image = np.ones((2, 2)) out = exposure.rescale_intensity(image) assert ~np.isnan(out).all() assert_array_almost_equal(out, image)
def test_rescale_all_zeros(): image = np.zeros((2, 2), dtype=np.uint8) out = exposure.rescale_intensity(image) assert ~np.isnan(out).all() assert_array_almost_equal(out, image)
def test_rescale_named_out_range(): image = np.array([0, uint16_max], dtype=np.uint16) out = exposure.rescale_intensity(image, out_range='uint10') assert_array_almost_equal(out, [0, uint10_max])
def test_rescale_in_range(): image = np.array([51., 102., 153.]) out = exposure.rescale_intensity(image, in_range=(0, 255)) assert_array_almost_equal(out, [0.2, 0.4, 0.6])
def test_rescale_stretch(): image = np.array([51, 102, 153], dtype=np.uint8) out = exposure.rescale_intensity(image) assert out.dtype == np.uint8 assert_array_almost_equal(out, [0, 127, 255])
def test_rescale_shrink(): image = np.array([51., 102., 153.]) out = exposure.rescale_intensity(image) assert_array_almost_equal(out, [0, 0.5, 1])
def test_rescale_in_range_clip(): image = np.array([51., 102., 153.]) out = exposure.rescale_intensity(image, in_range=(0, 102)) assert_array_almost_equal(out, [0.5, 1, 1])
def test_rescale_constant(): image = np.array([130, 130], dtype=np.uint16) out = exposure.rescale_intensity(image, out_range=(0, 127)) assert_array_almost_equal(out, [127, 127])
def test_match_array_values(array, template, expected_array): # when matched = histogram_matching._match_cumulative_cdf(array, template) # then assert_array_almost_equal(matched, expected_array)