@@ -253,7 +253,11 @@ def get_size(self):
253
253
if self ._A is None :
254
254
raise RuntimeError ('You must first set the image array' )
255
255
256
- return self ._A .shape [:2 ]
256
+ if isinstance (self .norm , mcolors .BivariateNorm ):
257
+ imshape = self ._A .shape [1 :]
258
+ else :
259
+ imshape = self ._A .shape [:2 ]
260
+ return imshape
257
261
258
262
def set_alpha (self , alpha ):
259
263
"""
@@ -300,6 +304,12 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
300
304
`trans` is the affine transformation from the image to pixel
301
305
space.
302
306
"""
307
+ if isinstance (self .norm , mcolors .BivariateNorm ):
308
+ imwidth = A .shape [1 ]
309
+ imheight = A .shape [2 ]
310
+ else :
311
+ imwidth = A .shape [0 ]
312
+ imheight = A .shape [1 ]
303
313
if A is None :
304
314
raise RuntimeError ('You must first set the image '
305
315
'array or the image attribute' )
@@ -323,15 +333,15 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
323
333
# Flip the input image using a transform. This avoids the
324
334
# problem with flipping the array, which results in a copy
325
335
# when it is converted to contiguous in the C wrapper
326
- t0 = Affine2D ().translate (0 , - A . shape [ 0 ] ).scale (1 , - 1 )
336
+ t0 = Affine2D ().translate (0 , - imwidth ).scale (1 , - 1 )
327
337
else :
328
338
t0 = IdentityTransform ()
329
339
330
340
t0 += (
331
341
Affine2D ()
332
342
.scale (
333
- in_bbox .width / A . shape [ 1 ] ,
334
- in_bbox .height / A . shape [ 0 ] )
343
+ in_bbox .width / imheight ,
344
+ in_bbox .height / imwidth )
335
345
.translate (in_bbox .x0 , in_bbox .y0 )
336
346
+ self .get_transform ())
337
347
@@ -362,17 +372,17 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
362
372
if A .ndim not in (2 , 3 ):
363
373
raise ValueError ("Invalid dimensions, got {}" .format (A .shape ))
364
374
365
- if A .ndim == 2 :
366
- if not isinstance (self .norm , mcolors .BivariateNorm ):
367
- A = self .norm (A )
375
+ if A .ndim == 2 or ( A . ndim == 3 and
376
+ isinstance (self .norm , mcolors .BivariateNorm ) ):
377
+ A = self .norm (A )
368
378
if A .dtype .kind == 'f' :
369
379
# If the image is greyscale, convert to RGBA and
370
380
# use the extra channels for resizing the over,
371
381
# under, and bad pixels. This is needed because
372
382
# Agg's resampler is very aggressive about
373
383
# clipping to [0, 1] and we use out-of-bounds
374
384
# values to carry the over/under/bad information
375
- rgba = np .empty ((A . shape [ 0 ], A . shape [ 1 ] , 4 ), dtype = A .dtype )
385
+ rgba = np .empty ((imwidth , imheight , 4 ), dtype = A .dtype )
376
386
rgba [..., 0 ] = A # normalized data
377
387
# this is to work around spurious warnings coming
378
388
# out of masked arrays.
@@ -411,9 +421,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
411
421
412
422
if not created_rgba_mask :
413
423
# Always convert to RGBA, even if only RGB input
424
+ isBivari = (A .ndim == 2 and A .shape [0 ] == 2 )
414
425
if A .shape [2 ] == 3 :
415
426
A = _rgb_to_rgba (A )
416
- elif A .shape [2 ] != 4 :
427
+ elif A .shape [2 ] != 4 and not isBivari :
417
428
raise ValueError ("Invalid dimensions, got %s" % (A .shape ,))
418
429
419
430
output = np .zeros ((out_height , out_width , 4 ), dtype = A .dtype )
@@ -596,8 +607,9 @@ def set_data(self, A):
596
607
not np .can_cast (self ._A .dtype , float , "same_kind" )):
597
608
raise TypeError ("Image data cannot be converted to float" )
598
609
599
- if not (self ._A .ndim == 2
600
- or self ._A .ndim == 3 and self ._A .shape [- 1 ] in [3 , 4 ]):
610
+ isRGB = (self ._A .ndim == 3 and self ._A .shape [- 1 ] in [3 , 4 ])
611
+ isBivari = (self ._A .ndim == 3 and self ._A .shape [0 ] == 2 )
612
+ if not (self ._A .ndim == 2 or isRGB or isBivari ):
601
613
raise TypeError ("Invalid dimensions for image data" )
602
614
603
615
self ._imcache = None
0 commit comments