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