@@ -37,32 +37,26 @@ class StackViewNDArray(np.ndarray):
37
37
def __new__ (cls , input_array , library_name = None , help_url = None ):
38
38
if 'cupy.ndarray' in str (type (input_array )):
39
39
input_array = input_array .get ()
40
- obj = np .asarray (input_array ).view (cls )
40
+ input_array = np .asarray (input_array )
41
+ obj = super (StackViewNDArray , cls ).__new__ (cls , shape = input_array .shape , dtype = input_array .dtype )
41
42
obj .library_name = library_name
42
43
obj .help_url = help_url
44
+ obj [:] = input_array
43
45
return obj
44
46
45
47
def __array_finalize__ (self , obj ):
46
48
if obj is None : return
47
49
self .library_name = getattr (obj , 'library_name' , None )
48
50
self .help_url = getattr (obj , 'help_url' , None )
49
- self .obj = obj
50
-
51
- def __getattr__ (self , name ):
52
- if name == "__repr__" :
53
- return self .__repr__
54
- if name == "_repr_html_" :
55
- return self ._repr_html_
56
- return getattr (self .obj , name )
57
-
51
+ #self.obj = obj
58
52
59
53
def __repr__ (self ):
60
54
if _is_running_in_colab ():
61
55
from IPython .display import display , HTML
62
56
display (HTML (self ._repr_html_ ()))
63
57
return ""
64
58
else :
65
- return self . obj . __repr__ ( )
59
+ return str ( self )
66
60
67
61
68
62
def _repr_html_ (self ):
@@ -71,19 +65,19 @@ def _repr_html_(self):
71
65
-------
72
66
HTML text with the image and some properties.
73
67
"""
74
- if len (self .obj . shape ) < 2 :
75
- return str (self . obj )
68
+ if len (self .shape ) < 2 :
69
+ return str (self )
76
70
77
71
import numpy as np
78
- size_in_pixels = np .prod (self .obj . shape )
79
- size_in_bytes = size_in_pixels * self .obj . dtype .itemsize
72
+ size_in_pixels = np .prod (self .shape )
73
+ size_in_bytes = size_in_pixels * self .dtype .itemsize
80
74
81
75
from ._image_widget import _is_label_image
82
- labels = _is_label_image (self . obj )
76
+ labels = _is_label_image (self )
83
77
84
78
import matplotlib .pyplot as plt
85
79
from ._imshow import imshow
86
- imshow (self . obj ,
80
+ imshow (self ,
87
81
labels = labels ,
88
82
continue_drawing = True ,
89
83
colorbar = not labels )
@@ -110,7 +104,7 @@ def _repr_html_(self):
110
104
import numpy as np
111
105
112
106
num_bins = 32
113
- h , _ = np .histogram (self . obj , bins = num_bins )
107
+ h , _ = np .histogram (self , bins = num_bins )
114
108
115
109
plt .figure (figsize = (1.8 , 1.2 ))
116
110
plt .bar (range (0 , len (h )), h )
@@ -125,22 +119,24 @@ def _repr_html_(self):
125
119
126
120
histogram = _png_to_html (_plt_to_png ())
127
121
128
- min_intensity = self .obj . min ()
129
- max_intensity = self .obj . max ()
122
+ min_intensity = self .min ()
123
+ max_intensity = self .max ()
130
124
min_max = "<tr><td>min</td><td>" + str (min_intensity ) + "</td></tr>" + \
131
125
"<tr><td>max</td><td>" + str (max_intensity ) + "</td></tr>"
132
126
133
127
if labels :
134
- unique_labels = list (np .unique (self . obj ))
128
+ unique_labels = list (np .unique (self ))
135
129
if 0 in unique_labels :
136
130
unique_labels .remove (0 )
137
131
138
132
num_labels = len (unique_labels )
139
133
min_max += "<tr><td>n labels</td><td>" + str (num_labels ) + "</td></tr>"
140
- if max_intensity != num_labels :
141
- min_max += "<tr><td colspan=\" 2\" ><a href=\" https://haesleinhuepf.github.io/BioImageAnalysisNotebooks/20h_segmentation_post_processing/sequential_labeling.html\" style=\" color:darkred; font-weight:bold\" >Not sequentially labeled!</a></td></tr>"
142
134
if min_intensity < 0 :
143
135
min_max += "<tr><td colspan=\" 2\" style=\" color:darkred; font-weight:bold\" >Negative label values detected!</td></tr>"
136
+ else :
137
+ if max_intensity != num_labels :
138
+ min_max += "<tr><td colspan=\" 2\" ><a href=\" https://haesleinhuepf.github.io/BioImageAnalysisNotebooks/20h_segmentation_post_processing/sequential_labeling.html\" style=\" color:darkred; font-weight:bold\" >Not sequentially labeled!</a></td></tr>"
139
+
144
140
else :
145
141
min_max = ""
146
142
@@ -236,8 +232,8 @@ def _imshow(image, title: str = None, labels: bool = False, min_display_intensit
236
232
continue_drawing: float
237
233
True: the next shown image can be visualized on top of the current one, e.g. with alpha = 0.5
238
234
"""
235
+ return
239
236
import numpy as np
240
-
241
237
if len (image .shape ) == 3 and image .shape [2 ] == 3 : # RGB image
242
238
import matplotlib .pyplot as plt
243
239
plt .imshow (image , vmin = min_display_intensity , vmax = max_display_intensity ,
@@ -261,10 +257,10 @@ def _imshow(image, title: str = None, labels: bool = False, min_display_intensit
261
257
import matplotlib
262
258
import numpy as np
263
259
264
- if not hasattr (_imshow , "labels_cmap" ):
260
+ if not hasattr (imshow , "labels_cmap" ):
265
261
from ._image_widget import _labels_lut
266
- _imshow .labels_cmap = matplotlib .colors .ListedColormap (_labels_lut ())
267
- cmap = _imshow .labels_cmap
262
+ imshow .labels_cmap = matplotlib .colors .ListedColormap (_labels_lut ())
263
+ cmap = imshow .labels_cmap
268
264
269
265
if min_display_intensity is None :
270
266
min_display_intensity = 0
@@ -284,4 +280,4 @@ def _imshow(image, title: str = None, labels: bool = False, min_display_intensit
284
280
plot .imshow (image , cmap = cmap , vmin = min_display_intensity , vmax = max_display_intensity ,
285
281
interpolation = 'nearest' , alpha = alpha )
286
282
if colorbar :
287
- plot .colorbar ()
283
+ plot .colorbar ()
0 commit comments