def test_order_0_warp_dtype(dtype): img = _convert(astronaut()[:10, :10, 0], dtype) assert resize(img, (12, 12), order=0).dtype == dtype assert rescale(img, 0.5, order=0).dtype == dtype assert rotate(img, 45, order=0).dtype == dtype assert warp_polar(img, order=0).dtype == dtype assert swirl(img, order=0).dtype == dtype
def test_linear_warp_polar(): radii = [5, 10, 15, 20] image = np.zeros([51, 51]) for rad in radii: rr, cc, val = circle_perimeter_aa(25, 25, rad) image[rr, cc] = val warped = warp_polar(image, radius=25) profile = warped.mean(axis=0) peaks = peak_local_max(profile) assert np.alltrue([peak in radii for peak in peaks])
def test_nonzero_order_warp_dtype(dtype, order): img = _convert(astronaut()[:10, :10, 0], dtype) float_dtype = _supported_float_type(dtype) assert resize(img, (12, 12), order=order).dtype == float_dtype assert rescale(img, 0.5, order=order).dtype == float_dtype assert rotate(img, 45, order=order).dtype == float_dtype assert warp_polar(img, order=order).dtype == float_dtype assert swirl(img, order=order).dtype == float_dtype
def test_linear_warp_polar(dtype): radii = [5, 10, 15, 20] image = np.zeros([51, 51]) for rad in radii: rr, cc, val = circle_perimeter_aa(25, 25, rad) image[rr, cc] = val image = image.astype(dtype, copy=False) warped = warp_polar(image, radius=25) assert warped.dtype == _supported_float_type(dtype) profile = warped.mean(axis=0) peaks = peak_local_max(profile) assert np.alltrue([peak in radii for peak in peaks])
def test_invalid_dimensions_polar(): with pytest.raises(ValueError): warp_polar(np.zeros((10, 10, 3)), (5, 5)) with pytest.raises(ValueError): warp_polar(np.zeros((10, 10)), (5, 5), channel_axis=-1) with pytest.raises(ValueError): warp_polar(np.zeros((10, 10, 10, 3)), (5, 5), channel_axis=-1)
def test_invalid_dimensions_polar(): with testing.raises(ValueError): warp_polar(np.zeros((10, 10, 3)), (5, 5)) with testing.raises(ValueError): warp_polar(np.zeros((10, 10)), (5, 5), multichannel=True) with testing.raises(ValueError): warp_polar(np.zeros((10, 10, 10, 3)), (5, 5), multichannel=True)
def test_log_warp_polar(): radii = [np.exp(2), np.exp(3), np.exp(4), np.exp(5), np.exp(5)-1, np.exp(5)+1] radii = [int(x) for x in radii] image = np.zeros([301, 301]) for rad in radii: rr, cc, val = circle_perimeter_aa(150, 150, rad) image[rr, cc] = val warped = warp_polar(image, radius=200, scaling='log') profile = warped.mean(axis=0) peaks_coord = peak_local_max(profile) peaks_coord.sort(axis=0) gaps = peaks_coord[1:] - peaks_coord[:-1] assert np.alltrue([x >= 38 and x <= 40 for x in gaps])
def test_invalid_scaling_polar(): with pytest.raises(ValueError): warp_polar(np.zeros((10, 10)), (5, 5), scaling='invalid') with pytest.raises(ValueError): warp_polar(np.zeros((10, 10)), (5, 5), scaling=None)