@@ -1641,6 +1641,17 @@ def test__resample_valid_output():
1641
1641
resample (np .zeros ((9 ,9 )),out )
1642
1642
1643
1643
1644
+ @pytest .fixture
1645
+ def nonaffine_identity ():
1646
+ class NonAffineIdentityTransform (Transform ):
1647
+ input_dims = 2
1648
+ output_dims = 2
1649
+
1650
+ def inverted (self ):
1651
+ return self
1652
+ return NonAffineIdentityTransform ()
1653
+
1654
+
1644
1655
@pytest .mark .parametrize ("data, interpolation, expected" ,
1645
1656
[(np .array ([[0.1 ,0.3 ,0.2 ]]),mimage .NEAREST ,
1646
1657
np .array ([[0.1 ,0.1 ,0.1 ,0.3 ,0.3 ,0.3 ,0.3 ,0.2 ,0.2 ,0.2 ]])),
@@ -1649,7 +1660,7 @@ def test__resample_valid_output():
1649
1660
0.28476562 ,0.2546875 ,0.22460938 ,0.20002441 ,0.20002441 ]])),
1650
1661
]
1651
1662
)
1652
- def test_resample_nonaffine (data ,interpolation ,expected ):
1663
+ def test_resample_nonaffine (data ,interpolation ,expected , nonaffine_identity ):
1653
1664
# Test that equivalent affine and nonaffine transforms resample the same
1654
1665
1655
1666
# Create a simple affine transform for scaling the input array
@@ -1661,20 +1672,36 @@ def test_resample_nonaffine(data, interpolation, expected):
1661
1672
1662
1673
# Create a nonaffine version of the same transform
1663
1674
# by compositing with a nonaffine identity transform
1664
- class NonAffineIdentityTransform (Transform ):
1665
- input_dims = 2
1666
- output_dims = 2
1667
-
1668
- def inverted (self ):
1669
- return self
1670
- nonaffine_transform = NonAffineIdentityTransform ()+ affine_transform
1675
+ nonaffine_transform = nonaffine_identity + affine_transform
1671
1676
1672
1677
nonaffine_result = np .empty_like (expected )
1673
1678
mimage .resample (data ,nonaffine_result ,nonaffine_transform ,
1674
1679
interpolation = interpolation )
1675
1680
assert_allclose (nonaffine_result ,expected ,atol = 5e-3 )
1676
1681
1677
1682
1683
+ @check_figures_equal ()
1684
+ def test_nonaffine_scaling_to_axes_edges (fig_test ,fig_ref ,nonaffine_identity ):
1685
+ # Test that plotting an image with equivalent affine and nonaffine
1686
+ # transforms is scaled the same to the axes edges
1687
+ data = np .arange (16 ).reshape ((4 ,4 ))% 3
1688
+
1689
+ # Specifically choose an axes bbox that has a fractional pixel
1690
+
1691
+ fig_test .set_size_inches (5 ,5 )
1692
+ fig_test .set_dpi (100 )
1693
+ ax = fig_test .subplots ()
1694
+ ax .set_position ([0.2 ,0.2 ,300.5 / 500 ,300.5 / 500 ])
1695
+ ax .imshow (data ,interpolation = 'nearest' ,
1696
+ transform = nonaffine_identity + ax .transData )
1697
+
1698
+ fig_ref .set_size_inches (5 ,5 )
1699
+ fig_ref .set_dpi (100 )
1700
+ ax = fig_ref .subplots ()
1701
+ ax .set_position ([0.2 ,0.2 ,300.5 / 500 ,300.5 / 500 ])
1702
+ ax .imshow (data ,interpolation = 'nearest' )
1703
+
1704
+
1678
1705
def test_axesimage_get_shape ():
1679
1706
# generate dummy image to test get_shape method
1680
1707
ax = plt .gca ()