本文整理汇总了Python中skimage._shared.testing.assert_almost_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_almost_equal函数的具体用法?Python assert_almost_equal怎么用?Python assert_almost_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_almost_equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fundamental_matrix_forward
def test_fundamental_matrix_forward():
essential_matrix_tform = EssentialMatrixTransform(
rotation=np.eye(3), translation=np.array([1, 0, 0]))
tform = FundamentalMatrixTransform()
tform.params = essential_matrix_tform.params
src = np.array([[0, 0], [0, 1], [1, 1]])
assert_almost_equal(tform(src), [[0, -1, 0], [0, -1, 1], [0, -1, 1]])
示例2: test_template
def test_template():
size = 100
# Float prefactors ensure that image range is between 0 and 1
image = np.full((400, 400), 0.5)
target = 0.1 * (np.tri(size) + np.tri(size)[::-1])
target_positions = [(50, 50), (200, 200)]
for x, y in target_positions:
image[x:x + size, y:y + size] = target
np.random.seed(1)
image += 0.1 * np.random.uniform(size=(400, 400))
result = match_template(image, target)
delta = 5
positions = peak_local_max(result, min_distance=delta)
if len(positions) > 2:
# Keep the two maximum peaks.
intensities = result[tuple(positions.T)]
i_maxsort = np.argsort(intensities)[::-1]
positions = positions[i_maxsort][:2]
# Sort so that order matches `target_positions`.
positions = positions[np.argsort(positions[:, 0])]
for xy_target, xy in zip(target_positions, positions):
assert_almost_equal(xy, xy_target)
示例3: test_save_buttons
def test_save_buttons():
viewer = get_image_viewer()
sv = SaveButtons()
viewer.plugins[0] += sv
import tempfile
fid, filename = tempfile.mkstemp(suffix='.png')
os.close(fid)
timer = QtCore.QTimer()
timer.singleShot(100, QtWidgets.QApplication.quit)
# exercise the button clicks
sv.save_stack.click()
sv.save_file.click()
# call the save functions directly
sv.save_to_stack()
with expected_warnings(['precision loss']):
sv.save_to_file(filename)
img = data.imread(filename)
with expected_warnings(['precision loss']):
assert_almost_equal(img, img_as_uint(viewer.image))
img = io.pop()
assert_almost_equal(img, viewer.image)
os.remove(filename)
示例4: test_ellipse_model_predict
def test_ellipse_model_predict():
model = EllipseModel()
model.params = (0, 0, 5, 10, 0)
t = np.arange(0, 2 * np.pi, np.pi / 2)
xy = np.array(((5, 0), (0, 10), (-5, 0), (0, -10)))
assert_almost_equal(xy, model.predict_xy(t))
示例5: test_NRMSE_no_int_overflow
def test_NRMSE_no_int_overflow():
camf = cam.astype(np.float32)
cam_noisyf = cam_noisy.astype(np.float32)
assert_almost_equal(compare_mse(cam, cam_noisy),
compare_mse(camf, cam_noisyf))
assert_almost_equal(compare_nrmse(cam, cam_noisy),
compare_nrmse(camf, cam_noisyf))
示例6: check_wrap_around
def check_wrap_around(ndim, axis):
# create a ramp, but with the last pixel along axis equalling the first
elements = 100
ramp = np.linspace(0, 12 * np.pi, elements)
ramp[-1] = ramp[0]
image = ramp.reshape(tuple([elements if n == axis else 1
for n in range(ndim)]))
image_wrapped = np.angle(np.exp(1j * image))
index_first = tuple([0] * ndim)
index_last = tuple([-1 if n == axis else 0 for n in range(ndim)])
# unwrap the image without wrap around
with warnings.catch_warnings():
# We do not want warnings about length 1 dimensions
warnings.simplefilter("ignore")
image_unwrap_no_wrap_around = unwrap_phase(image_wrapped, seed=0)
print('endpoints without wrap_around:',
image_unwrap_no_wrap_around[index_first],
image_unwrap_no_wrap_around[index_last])
# without wrap around, the endpoints of the image should differ
assert_(abs(image_unwrap_no_wrap_around[index_first] -
image_unwrap_no_wrap_around[index_last]) > np.pi)
# unwrap the image with wrap around
wrap_around = [n == axis for n in range(ndim)]
with warnings.catch_warnings():
# We do not want warnings about length 1 dimensions
warnings.simplefilter("ignore")
image_unwrap_wrap_around = unwrap_phase(image_wrapped, wrap_around,
seed=0)
print('endpoints with wrap_around:',
image_unwrap_wrap_around[index_first],
image_unwrap_wrap_around[index_last])
# with wrap around, the endpoints of the image should be equal
assert_almost_equal(image_unwrap_wrap_around[index_first],
image_unwrap_wrap_around[index_last])
示例7: test_peak_float_out_of_range_dtype
def test_peak_float_out_of_range_dtype():
im = np.array([10, 100], dtype=np.float16)
nbins = 10
frequencies, bin_centers = exposure.histogram(im, nbins=nbins, source_range='dtype')
assert_almost_equal(np.min(bin_centers), -0.9, 3)
assert_almost_equal(np.max(bin_centers), 0.9, 3)
assert_equal(len(bin_centers), 10)
示例8: test_daisy_normalization
def test_daisy_normalization():
img = img_as_float(data.astronaut()[:64, :64].mean(axis=2))
descs = daisy(img, normalization='l1')
for i in range(descs.shape[0]):
for j in range(descs.shape[1]):
assert_almost_equal(np.sum(descs[i, j, :]), 1)
descs_ = daisy(img)
assert_almost_equal(descs, descs_)
descs = daisy(img, normalization='l2')
for i in range(descs.shape[0]):
for j in range(descs.shape[1]):
assert_almost_equal(sqrt(np.sum(descs[i, j, :] ** 2)), 1)
orientations = 8
descs = daisy(img, orientations=orientations, normalization='daisy')
desc_dims = descs.shape[2]
for i in range(descs.shape[0]):
for j in range(descs.shape[1]):
for k in range(0, desc_dims, orientations):
assert_almost_equal(sqrt(np.sum(
descs[i, j, k:k + orientations] ** 2)), 1)
img = np.zeros((50, 50))
descs = daisy(img, normalization='off')
for i in range(descs.shape[0]):
for j in range(descs.shape[1]):
assert_almost_equal(np.sum(descs[i, j, :]), 0)
with testing.raises(ValueError):
daisy(img, normalization='does_not_exist')
示例9: test_ssim_multichannel
def test_ssim_multichannel():
N = 100
X = (np.random.rand(N, N) * 255).astype(np.uint8)
Y = (np.random.rand(N, N) * 255).astype(np.uint8)
S1 = ssim(X, Y, win_size=3)
# replicate across three channels. should get identical value
Xc = np.tile(X[..., np.newaxis], (1, 1, 3))
Yc = np.tile(Y[..., np.newaxis], (1, 1, 3))
S2 = ssim(Xc, Yc, multichannel=True, win_size=3)
assert_almost_equal(S1, S2)
# full case should return an image as well
m, S3 = ssim(Xc, Yc, multichannel=True, full=True)
assert_equal(S3.shape, Xc.shape)
# gradient case
m, grad = ssim(Xc, Yc, multichannel=True, gradient=True)
assert_equal(grad.shape, Xc.shape)
# full and gradient case
m, grad, S3 = ssim(Xc, Yc, multichannel=True, full=True, gradient=True)
assert_equal(grad.shape, Xc.shape)
assert_equal(S3.shape, Xc.shape)
# fail if win_size exceeds any non-channel dimension
with testing.raises(ValueError):
ssim(Xc, Yc, win_size=7, multichannel=False)
示例10: test_all_props_3d
def test_all_props_3d():
region = regionprops(SAMPLE_3D, INTENSITY_SAMPLE_3D)[0]
for prop in PROPS:
try:
assert_almost_equal(region[prop], getattr(region, PROPS[prop]))
except (NotImplementedError, TypeError):
pass
示例11: test_all_props
def test_all_props():
region = regionprops(SAMPLE, INTENSITY_SAMPLE)[0]
for prop in PROPS:
try:
assert_almost_equal(region[prop], getattr(region, PROPS[prop]))
except TypeError: # the `slice` property causes this
pass
示例12: test_stackcopy
def test_stackcopy():
layers = 4
x = np.empty((3, 3, layers))
y = np.eye(3, 3)
_stackcopy(x, y)
for i in range(layers):
assert_almost_equal(x[..., i], y)
示例13: test_line_model_nd_estimate
def test_line_model_nd_estimate():
# generate original data without noise
model0 = LineModelND()
model0.params = (np.array([0, 0, 0], dtype='float'),
np.array([1, 1, 1], dtype='float')/np.sqrt(3))
# we scale the unit vector with a factor 10 when generating points on the
# line in order to compensate for the scale of the random noise
data0 = (model0.params[0] +
10 * np.arange(-100, 100)[..., np.newaxis] * model0.params[1])
# add gaussian noise to data
random_state = np.random.RandomState(1234)
data = data0 + random_state.normal(size=data0.shape)
# estimate parameters of noisy data
model_est = LineModelND()
model_est.estimate(data)
# assert_almost_equal(model_est.residuals(data0), np.zeros(len(data)), 1)
# test whether estimated parameters are correct
# we use the following geometric property: two aligned vectors have
# a cross-product equal to zero
# test if direction vectors are aligned
assert_almost_equal(np.linalg.norm(np.cross(model0.params[1],
model_est.params[1])), 0, 1)
# test if origins are aligned with the direction
a = model_est.params[0] - model0.params[0]
if np.linalg.norm(a) > 0:
a /= np.linalg.norm(a)
assert_almost_equal(np.linalg.norm(np.cross(model0.params[1], a)), 0, 1)
示例14: test_gaussian_mssim_vs_IPOL
def test_gaussian_mssim_vs_IPOL():
# Tests vs. imdiff result from the following IPOL article and code:
# https://www.ipol.im/pub/art/2011/g_lmii/
mssim_IPOL = 0.327309966087341
mssim = ssim(cam, cam_noisy, gaussian_weights=True,
use_sample_covariance=False)
assert_almost_equal(mssim, mssim_IPOL, decimal=3)
示例15: test_rgb2yiq_conversion
def test_rgb2yiq_conversion(self):
rgb = img_as_float(self.img_rgb)[::16, ::16]
yiq = rgb2yiq(rgb).reshape(-1, 3)
gt = np.array([colorsys.rgb_to_yiq(pt[0], pt[1], pt[2])
for pt in rgb.reshape(-1, 3)]
)
assert_almost_equal(yiq, gt, decimal=2)