5
5
from pathlib import Path
6
6
parentFolder = str (Path (__file__ ).parent .parent )
7
7
activate_path = parentFolder + '\\ env\\ Scripts\\ activate_this.py'
8
+
8
9
if os .path .exists (activate_path ):
9
10
exec (open (activate_path ).read (), {'__file__' : activate_path })
10
11
print (f'Aivia virtual environment activated\n Using python: { activate_path } ' )
51
52
PIL
52
53
wxPython
53
54
54
- For Aivia 10.x with embedded python, the guide to install non-standard packages (windows and macOS):
55
-
56
- * Open terminal
57
- * Change directory: cd "path/to/Aivia/Python/directory/" (For e.g. C:\Program Files\Leica Microsystems\Aivia 10.5.0\Python)
58
- * Run: python -m pip install <name_of_the_module>
59
-
60
55
Parameters
61
56
----------
62
57
Input Image : Aivia channel
@@ -85,19 +80,17 @@ def run(params):
85
80
print ('read' )
86
81
if not os .path .exists (image_location ):
87
82
print (f'Error: { image_location } does not exist' )
88
- return ;
83
+ return
89
84
90
85
if zCount > 1 or tCount > 1 :
91
86
print ('Currently this only supports 2D images with no time dimension.' )
92
87
return
93
88
94
-
95
- image_data = imread (image_location )
89
+ image_data = imread (image_location )
96
90
mask_data = paint_superpixels (image_location )
97
91
98
-
99
92
mask_data = resize (mask_data , image_data .shape , anti_aliasing = False )
100
- mask_data = img_as_ubyte (mask_data )
93
+ mask_data = img_as_ubyte (mask_data )
101
94
102
95
imsave (result_mask_location , mask_data )
103
96
imsave (result_object_location , mask_data )
@@ -121,13 +114,10 @@ def paint_superpixels(image_location):
121
114
(N, M) array
122
115
Binary mask based on the user's painting.
123
116
"""
124
-
125
-
126
117
app = wx .App ()
127
118
frame = MyFrame (image_location )
128
119
app .MainLoop ()
129
120
130
-
131
121
return frame .mask [:, :, 0 ]
132
122
133
123
@@ -157,67 +147,61 @@ class MyFrame(wx.Frame):
157
147
"""
158
148
159
149
def __init__ (self , image_location ):
160
- super ().__init__ (parent = None , title = 'Superpixel Painter' , size = wx .Size ( 800 ,800 ))
161
-
150
+ super ().__init__ (parent = None , title = 'Superpixel Painter' , size = wx .Size (800 , 800 ))
162
151
163
-
164
- image_np = imread (image_location )
152
+ image_np = imread (image_location )
165
153
frame_size = self .GetSize ()
166
- frame_h = (frame_size [0 ]) * 0.7
167
- frame_w = (frame_size [1 ]) * 0.7
168
- image_np_sc = resize (image_np , (frame_h ,frame_w ), anti_aliasing = False )
154
+ frame_h = (frame_size [0 ]) * 0.7
155
+ frame_w = (frame_size [1 ]) * 0.7
156
+ image_np_sc = resize (image_np , (frame_h , frame_w ), anti_aliasing = False )
169
157
self .W = image_np_sc .shape [0 ]
170
158
self .H = image_np_sc .shape [1 ]
171
159
172
160
image = wx .Image (self .W , self .H )
173
- image .SetData (image_np .tobytes ())
161
+ image .SetData (image_np_sc .tobytes ())
174
162
wxBitmap = image .ConvertToBitmap ()
175
163
176
-
177
164
max_markers = int (0.01 * (self .W * self .H ))
178
165
self .marker_color = [1.00 , 0.73 , 0.03 ]
179
166
180
167
self .panel = wx .Panel (self )
181
168
self .panel .SetBackgroundColour ("gray" )
182
169
183
-
184
170
self .mainSizer = wx .BoxSizer (wx .VERTICAL )
185
171
186
172
user_instructions = 'Click left mouse button to paint superpixels. Click right mouse button to erase. ' \
187
173
'Middle click to fill a contour. Close the app when finished.'
188
174
self .instruction = wx .StaticText (self .panel , label = user_instructions )
189
- self .instruction .SetForegroundColour (wx .Colour (255 ,255 ,255 ))
190
- self .mainSizer .Add (self .instruction , 0 ,wx .ALL | wx .CENTER , 5 )
175
+ self .instruction .SetForegroundColour (wx .Colour (255 , 255 , 255 ))
176
+ self .mainSizer .Add (self .instruction , 0 , wx .ALL | wx .CENTER , 5 )
191
177
192
178
self .imageCtrl = wx .StaticBitmap (self .panel , wx .ID_ANY ,
193
179
wxBitmap )
194
180
195
181
self .mainSizer .Add (self .imageCtrl , 0 , wx .ALL , 5 )
196
- self .imageCtrl .SetBitmap (wxBitmap )
197
-
182
+ self .imageCtrl .SetBitmap (wxBitmap )
198
183
199
184
self .marker = wx .StaticText (self .panel , label = 'Marker' )
200
- self .marker .SetForegroundColour (wx .Colour (255 ,255 ,255 ))
201
- self .mainSizer .Add (self .marker , 0 , wx .ALL , 5 )
185
+ self .marker .SetForegroundColour (wx .Colour (255 , 255 , 255 ))
186
+ self .mainSizer .Add (self .marker , 0 , wx .ALL , 5 )
202
187
203
- self .marker_sld = wx .Slider (self .panel , value = 1 , minValue = 10 , maxValue = max_markers ,
204
- style = wx .SL_HORIZONTAL | wx .SL_LABELS )
205
- self .mainSizer .Add (self .marker_sld ,1 , flag = wx .EXPAND , border = 20 )
188
+ self .marker_sld = wx .Slider (self .panel , value = 1 , minValue = 10 , maxValue = max_markers ,
189
+ style = wx .SL_HORIZONTAL | wx .SL_LABELS )
190
+ self .mainSizer .Add (self .marker_sld , 1 , flag = wx .EXPAND , border = 20 )
206
191
207
192
self .compactness = wx .StaticText (self .panel , label = 'Compactness' )
208
- self .compactness .SetForegroundColour (wx .Colour (255 ,255 ,255 ))
209
- self .mainSizer .Add (self .compactness , 0 , wx .ALL , 5 )
210
- self .compactness_float = 0.001
193
+ self .compactness .SetForegroundColour (wx .Colour (255 , 255 , 255 ))
194
+ self .mainSizer .Add (self .compactness , 0 , wx .ALL , 5 )
195
+ self .compactness_float = 0.001
211
196
212
-
213
- self .compactness_sld = wx .Slider (self .panel , value = 1 , minValue = 1 , maxValue = 10 ,
214
- style = wx .SL_HORIZONTAL | wx .SL_LABELS )
215
- self .mainSizer .Add (self .compactness_sld ,1 ,flag = wx .EXPAND , border = 20 )
197
+ self .compactness_sld = wx .Slider (self .panel , value = 1 , minValue = 1 , maxValue = 10 ,
198
+ style = wx .SL_HORIZONTAL | wx .SL_LABELS )
199
+ self .mainSizer .Add (self .compactness_sld , 1 , flag = wx .EXPAND , border = 20 )
216
200
217
201
self .clear_button = wx .Button (self .panel , wx .ID_ANY , 'Clear' , (10 , 10 ))
218
- self .mainSizer .Add (self .clear_button , 0 , wx .ALL , 5 )
202
+ self .mainSizer .Add (self .clear_button , 0 , wx .ALL , 5 )
219
203
220
- self .input_image_np = image_np_sc
204
+ self .input_image_np = image_np_sc
221
205
self .superpixels = watershed (sobel (self .input_image_np ), markers = self .marker_sld .GetValue (),
222
206
compactness = self .compactness_sld .GetValue ()* self .compactness_float )
223
207
self .boundaries = img_as_ubyte (mark_boundaries (self .input_image_np , self .superpixels , color = self .marker_color ))
@@ -240,10 +224,8 @@ def __init__(self, image_location):
240
224
def wximage_to_numpy (self , image ):
241
225
242
226
arr = np .asarray (image .GetDataBuffer ())
243
- image_np = np .copy (np .reshape (arr , (image .GetWidth (), image .GetHeight (),3 )))
227
+ image_np = np .copy (np .reshape (arr , (image .GetWidth (), image .GetHeight (), 3 )))
244
228
return image_np
245
-
246
-
247
229
248
230
def clear_mask (self , event ):
249
231
"""
@@ -258,9 +240,8 @@ def update_image(self):
258
240
Updates the app's displayed image.
259
241
"""
260
242
261
- wxBitmap = wx .Image (self .W ,self .H , self .display_image )
243
+ wxBitmap = wx .Image (self .W , self .H , self .display_image )
262
244
self .imageCtrl .SetBitmap (wx .Bitmap (wxBitmap ))
263
-
264
245
265
246
def update_superpixels (self , event ):
266
247
"""
@@ -304,20 +285,19 @@ def flood_fill(self, event):
304
285
305
286
for i in range (3 ):
306
287
self .mask [:, :, i ] = flood_fill (self .mask [:, :, i ], seed_point = (event .y , event .x ), new_value = 255 ,
307
- tolerance = 1 )
288
+ tolerance = 1 )
308
289
self .display_image [:, :, i ] = np .where (self .mask [:, :, i ] == 255 , 255 , self .display_image [:, :, i ])
309
290
self .update_image ()
310
-
311
291
312
292
313
-
314
-
315
-
316
293
if __name__ == '__main__' :
317
294
params = {}
318
- params ['inputImagePath' ] = '2D_PigSkin .tif'
319
- params ['resultMaskPath' ] = '2D_PigSkinMask .tif'
320
- params ['resultObjectPath' ] = '2D_PigSkinResult .tif'
321
- params ['TCount' ]= 1
322
- params ['ZCount' ]= 1
295
+ params ['inputImagePath' ] = 'test_8b .tif'
296
+ params ['resultMaskPath' ] = 'test_8b_res .tif'
297
+ params ['resultObjectPath' ] = 'test_8b_objres .tif'
298
+ params ['TCount' ] = 1
299
+ params ['ZCount' ] = 1
323
300
run (params )
301
+
302
+ # CHANGELOG:
303
+ # v1.01: - Bug fixed with wxPython.Image.SetData (ValueError: Invalid data buffer size.) >> was not using rescaled img.
0 commit comments