|
9 | 9 | importurllib.request
|
10 | 10 |
|
11 | 11 | importnumpyasnp
|
12 |
| -fromnumpy.testingimportassert_array_equal |
| 12 | +fromnumpy.testingimportassert_allclose,assert_array_equal |
13 | 13 | fromPILimportImage
|
14 | 14 |
|
15 | 15 | importmatplotlibasmpl
|
|
18 | 18 | frommatplotlib.imageimport (AxesImage,BboxImage,FigureImage,
|
19 | 19 | NonUniformImage,PcolorImage)
|
20 | 20 | frommatplotlib.testing.decoratorsimportcheck_figures_equal,image_comparison
|
21 |
| -frommatplotlib.transformsimportBbox,Affine2D,TransformedBbox |
| 21 | +frommatplotlib.transformsimportBbox,Affine2D,Transform,TransformedBbox |
22 | 22 | importmatplotlib.tickerasmticker
|
23 | 23 |
|
24 | 24 | importpytest
|
@@ -1641,6 +1641,41 @@ def test__resample_valid_output():
|
1641 | 1641 | resample(np.zeros((9,9)),out)
|
1642 | 1642 |
|
1643 | 1643 |
|
| 1644 | +@pytest.mark.parametrize("data, interpolation, expected", |
| 1645 | + [(np.array([[0.1,0.3,0.2]]),mpl._image.NEAREST, |
| 1646 | +np.array([[0.1,0.1,0.1,0.3,0.3,0.3,0.3,0.2,0.2,0.2]])), |
| 1647 | + (np.array([[0.1,0.3,0.2]]),mpl._image.BILINEAR, |
| 1648 | +np.array([[0.1,0.1,0.15078125,0.21096191,0.27033691, |
| 1649 | +0.28476562,0.2546875,0.22460938,0.20002441,0.20002441]])), |
| 1650 | + ] |
| 1651 | +) |
| 1652 | +deftest__resample_nonaffine(data,interpolation,expected): |
| 1653 | +# Test that equivalent affine and nonaffine transforms resample the same |
| 1654 | + |
| 1655 | +# Create a simple affine transform for scaling the input array |
| 1656 | +affine_transform=Affine2D().scale(sx=expected.shape[1]/data.shape[1],sy=1) |
| 1657 | + |
| 1658 | +affine_result=np.empty_like(expected) |
| 1659 | +mpl._image.resample(data,affine_result,affine_transform, |
| 1660 | +interpolation=interpolation) |
| 1661 | +assert_allclose(affine_result,expected) |
| 1662 | + |
| 1663 | +# Create a nonaffine version of the same transform |
| 1664 | +# by compositing with a nonaffine identity transform |
| 1665 | +classNonAffineIdentityTransform(Transform): |
| 1666 | +input_dims=2 |
| 1667 | +output_dims=2 |
| 1668 | + |
| 1669 | +definverted(self): |
| 1670 | +returnself |
| 1671 | +nonaffine_transform=NonAffineIdentityTransform()+affine_transform |
| 1672 | + |
| 1673 | +nonaffine_result=np.empty_like(expected) |
| 1674 | +mpl._image.resample(data,nonaffine_result,nonaffine_transform, |
| 1675 | +interpolation=interpolation) |
| 1676 | +assert_allclose(nonaffine_result,expected) |
| 1677 | + |
| 1678 | + |
1644 | 1679 | deftest_axesimage_get_shape():
|
1645 | 1680 | # generate dummy image to test get_shape method
|
1646 | 1681 | ax=plt.gca()
|
|