@@ -1711,3 +1711,49 @@ def test_resample_dtypes(dtype, ndim):
1711
1711
axes_image = ax .imshow (data )
1712
1712
# Before fix the following raises ValueError for some dtypes.
1713
1713
axes_image .make_image (None )[0 ]
1714
+
1715
+
1716
+ @pytest .mark .parametrize ('intp_stage' , ('data' , 'rgba' ))
1717
+ @check_figures_equal ()
1718
+ def test_interpolation_stage_rgba_respects_alpha_param (fig_test , fig_ref , intp_stage ):
1719
+ axs_tst = fig_test .subplots (2 , 3 )
1720
+ axs_ref = fig_ref .subplots (2 , 3 )
1721
+ ny , nx = 3 , 3
1722
+ scalar_alpha = 0.5
1723
+ array_alpha = np .random .rand (ny , nx )
1724
+
1725
+ # When the image does not have an alpha channel, alpha should be specified
1726
+ # by the user or default to 1.0
1727
+ im_rgb = np .random .rand (ny , nx , 3 )
1728
+ im_concat_default_a = np .ones ((ny , nx , 1 )) # alpha defaults to 1.0
1729
+ im_rgba = np .concatenate ( # combine rgb channels with array alpha
1730
+ (im_rgb , array_alpha .reshape ((ny , nx , 1 ))), axis = - 1
1731
+ )
1732
+ axs_tst [0 ][0 ].imshow (im_rgb )
1733
+ axs_ref [0 ][0 ].imshow (np .concatenate ((im_rgb , im_concat_default_a ), axis = - 1 ))
1734
+ axs_tst [0 ][1 ].imshow (im_rgb , interpolation_stage = intp_stage , alpha = scalar_alpha )
1735
+ axs_ref [0 ][1 ].imshow (
1736
+ np .concatenate ( # combine rgb channels with broadcasted scalar alpha
1737
+ (im_rgb , scalar_alpha * im_concat_default_a ), axis = - 1
1738
+ ), interpolation_stage = intp_stage
1739
+ )
1740
+ axs_tst [0 ][2 ].imshow (im_rgb , interpolation_stage = intp_stage , alpha = array_alpha )
1741
+ axs_ref [0 ][2 ].imshow (im_rgba , interpolation_stage = intp_stage )
1742
+
1743
+ # When the image already has an alpha channel, multiply it by the
1744
+ # scalar alpha param, or replace it by the array alpha param
1745
+ axs_tst [1 ][0 ].imshow (im_rgba )
1746
+ axs_ref [1 ][0 ].imshow (im_rgb , alpha = array_alpha )
1747
+ axs_tst [1 ][1 ].imshow (im_rgba , interpolation_stage = intp_stage , alpha = scalar_alpha )
1748
+ axs_ref [1 ][1 ].imshow (
1749
+ np .concatenate ( # combine rgb channels with scaled array alpha
1750
+ (im_rgb , scalar_alpha * array_alpha .reshape ((ny , nx , 1 ))), axis = - 1
1751
+ ), interpolation_stage = intp_stage
1752
+ )
1753
+ new_array_alpha = np .random .rand (ny , nx )
1754
+ axs_tst [1 ][2 ].imshow (im_rgba , interpolation_stage = intp_stage , alpha = new_array_alpha )
1755
+ axs_ref [1 ][2 ].imshow (
1756
+ np .concatenate ( # combine rgb channels with new array alpha
1757
+ (im_rgb , new_array_alpha .reshape ((ny , nx , 1 ))), axis = - 1
1758
+ ), interpolation_stage = intp_stage
1759
+ )
0 commit comments