@@ -431,12 +431,18 @@ def plot_tilted_slice(self, xyz, axis, volume='image', cmap=None, ax=None, **kwa
431
431
return ax
432
432
433
433
@staticmethod
434
- def _plot_slice (im , extent , ax = None , cmap = None , ** kwargs ):
434
+ def _plot_slice (im , extent , ax = None , cmap = None , volume = None , ** kwargs ):
435
435
if not ax :
436
436
ax = plt .gca ()
437
437
ax .axis ('equal' )
438
438
if not cmap :
439
439
cmap = plt .get_cmap ('bone' )
440
+
441
+ if volume == 'boundary' :
442
+ imb = np .zeros ((* im .shape [:2 ], 4 ), dtype = np .uint8 )
443
+ imb [im == 1 ] = np .array ([0 , 0 , 0 , 255 ])
444
+ im = imb
445
+
440
446
ax .imshow (im , extent = extent , cmap = cmap , ** kwargs )
441
447
return ax
442
448
@@ -534,9 +540,13 @@ def compute_boundaries(self, values):
534
540
:param values:
535
541
:return:
536
542
"""
537
- boundary = np .diff (values , axis = 0 , append = 0 )
538
- boundary = boundary + np .diff (values , axis = 1 , append = 0 )
543
+ boundary = np .abs (np .diff (values , axis = 0 , prepend = 0 ))
544
+ boundary = boundary + np .abs (np .diff (values , axis = 1 , prepend = 0 ))
545
+ boundary = boundary + np .abs (np .diff (values , axis = 1 , append = 0 ))
546
+ boundary = boundary + np .abs (np .diff (values , axis = 0 , append = 0 ))
547
+
539
548
boundary [boundary != 0 ] = 1
549
+
540
550
return boundary
541
551
542
552
def plot_slices (self , xyz , * args , ** kwargs ):
@@ -580,7 +590,7 @@ def plot_cslice(self, ap_coordinate, volume='image', mapping=None, region_values
580
590
"""
581
591
582
592
cslice = self .slice (ap_coordinate , axis = 1 , volume = volume , mapping = mapping , region_values = region_values )
583
- return self ._plot_slice (np .moveaxis (cslice , 0 , 1 ), extent = self .extent (axis = 1 ), ** kwargs )
593
+ return self ._plot_slice (np .moveaxis (cslice , 0 , 1 ), extent = self .extent (axis = 1 ), volume = volume , ** kwargs )
584
594
585
595
def plot_hslice (self , dv_coordinate , volume = 'image' , mapping = None , region_values = None , ** kwargs ):
586
596
"""
@@ -604,7 +614,7 @@ def plot_hslice(self, dv_coordinate, volume='image', mapping=None, region_values
604
614
"""
605
615
606
616
hslice = self .slice (dv_coordinate , axis = 2 , volume = volume , mapping = mapping , region_values = region_values )
607
- return self ._plot_slice (hslice , extent = self .extent (axis = 2 ), ** kwargs )
617
+ return self ._plot_slice (hslice , extent = self .extent (axis = 2 ), volume = volume , ** kwargs )
608
618
609
619
def plot_sslice (self , ml_coordinate , volume = 'image' , mapping = None , region_values = None , ** kwargs ):
610
620
"""
@@ -628,7 +638,7 @@ def plot_sslice(self, ml_coordinate, volume='image', mapping=None, region_values
628
638
"""
629
639
630
640
sslice = self .slice (ml_coordinate , axis = 0 , volume = volume , mapping = mapping , region_values = region_values )
631
- return self ._plot_slice (np .swapaxes (sslice , 0 , 1 ), extent = self .extent (axis = 0 ), ** kwargs )
641
+ return self ._plot_slice (np .swapaxes (sslice , 0 , 1 ), extent = self .extent (axis = 0 ), volume = volume , ** kwargs )
632
642
633
643
def plot_top (self , volume = 'annotation' , mapping = None , region_values = None , ax = None , ** kwargs ):
634
644
"""
@@ -668,7 +678,7 @@ def plot_top(self, volume='annotation', mapping=None, region_values=None, ax=Non
668
678
elif volume == 'boundary' :
669
679
im = self .compute_boundaries (regions )
670
680
671
- return self ._plot_slice (im , self .extent (axis = 2 ), ax = ax , ** kwargs )
681
+ return self ._plot_slice (im , self .extent (axis = 2 ), ax = ax , volume = volume , ** kwargs )
672
682
673
683
674
684
@dataclass
@@ -1164,7 +1174,7 @@ def plot_flatmap(self, depth=0, volume='annotation', mapping='Allen', region_val
1164
1174
if not ax :
1165
1175
ax = plt .gca ()
1166
1176
1167
- return self ._plot_slice (im , self .extent_flmap (), ax = ax , ** kwargs )
1177
+ return self ._plot_slice (im , self .extent_flmap (), ax = ax , volume = volume , ** kwargs )
1168
1178
1169
1179
def extent_flmap (self ):
1170
1180
extent = np .r_ [0 , self .flatmap .shape [1 ], 0 , self .flatmap .shape [0 ]]
0 commit comments