@@ -294,6 +294,8 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
294294 output [...] = - 100.0
295295 else :
296296 output = np .zeros ((out_height , out_width ), dtype = A .dtype )
297+
298+ alpha = 1.0
297299 elif len (A .shape ) == 3 :
298300 # Always convert to RGBA, even if only RGB input
299301 if A .shape [2 ] == 3 :
@@ -302,19 +304,27 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
302304 raise ValueError ("Invalid dimensions, got %s" % (A .shape ,))
303305
304306 output = np .zeros ((out_height , out_width , 4 ), dtype = A .dtype )
307+
308+ alpha = self .get_alpha ()
309+ if alpha is None :
310+ alpha = 1.0
305311 else :
306312 raise ValueError ("Invalid dimensions, got %s" % (A .shape ,))
307313
308- alpha = self .get_alpha ()
309- if alpha is None :
310- alpha = 1.0
311-
312314 _image .resample (
313315 A , output , t , _interpd_ [self .get_interpolation ()],
314316 self .get_resample (), alpha ,
315317 self .get_filternorm () or 0.0 , self .get_filterrad () or 0.0 )
316318
317319 output = self .to_rgba (output , bytes = True , norm = False )
320+
321+ # Apply alpha *after* if the input was greyscale
322+ if len (A .shape ) == 2 :
323+ alpha = self .get_alpha ()
324+ if alpha is not None and alpha != 1.0 :
325+ alpha_channel = output [:, :, 3 ]
326+ alpha_channel [:] = np .asarray (
327+ np .asarray (alpha_channel , np .float ) * alpha , np .uint8 )
318328 else :
319329 if self ._imcache is None :
320330 self ._imcache = self .to_rgba (A , bytes = True , norm = (A .ndim == 2 ))
0 commit comments