10
10
from mantidimaging import helper as h
11
11
from mantidimaging .core .data import Images
12
12
from mantidimaging .core .operations .base_filter import BaseFilter , FilterGroup
13
- from mantidimaging .core .parallel import two_shared_mem as ptsm
14
- from mantidimaging .core .parallel import utility as pu
13
+ from mantidimaging .core .parallel import utility as pu , shared as ps
15
14
from mantidimaging .core .utility .progress_reporting import Progress
16
15
from mantidimaging .gui .utility .qt_helpers import Type
17
16
from mantidimaging .gui .widgets .stack_selector import StackSelectorWidgetView
@@ -58,7 +57,7 @@ class FlatFieldFilter(BaseFilter):
58
57
filter_name = 'Flat-fielding'
59
58
60
59
@staticmethod
61
- def filter_func (data : Images ,
60
+ def filter_func (images : Images ,
62
61
flat_before : Images = None ,
63
62
flat_after : Images = None ,
64
63
dark_before : Images = None ,
@@ -80,7 +79,7 @@ def filter_func(data: Images,
80
79
:param chunksize: The number of chunks that each worker will receive.
81
80
:return: Filtered data (stack of images)
82
81
"""
83
- h .check_data_stack (data )
82
+ h .check_data_stack (images )
84
83
85
84
if selected_flat_fielding is not None :
86
85
if selected_flat_fielding == "Both, concatenated" and flat_after is not None and flat_before is not None \
@@ -101,19 +100,19 @@ def filter_func(data: Images,
101
100
if 2 != flat_avg .ndim or 2 != dark_avg .ndim :
102
101
raise ValueError (
103
102
f"Incorrect shape of the flat image ({ flat_avg .shape } ) or dark image ({ dark_avg .shape } ) \
104
- which should match the shape of the sample images ({ data .data .shape } )" )
103
+ which should match the shape of the sample images ({ images .data .shape } )" )
105
104
106
- if not data .data .shape [1 :] == flat_avg .shape == dark_avg .shape :
107
- raise ValueError (f"Not all images are the expected shape: { data .data .shape [1 :]} , instead "
105
+ if not images .data .shape [1 :] == flat_avg .shape == dark_avg .shape :
106
+ raise ValueError (f"Not all images are the expected shape: { images .data .shape [1 :]} , instead "
108
107
f"flat had shape: { flat_avg .shape } , and dark had shape: { dark_avg .shape } " )
109
108
110
109
progress = Progress .ensure_instance (progress ,
111
- num_steps = data .data .shape [0 ],
110
+ num_steps = images .data .shape [0 ],
112
111
task_name = 'Background Correction' )
113
- _execute (data .data , flat_avg , dark_avg , cores , chunksize , progress )
112
+ _execute (images .data , flat_avg , dark_avg , cores , chunksize , progress )
114
113
115
- h .check_data_stack (data )
116
- return data
114
+ h .check_data_stack (images )
115
+ return images
117
116
118
117
@staticmethod
119
118
def register_gui (form , on_change , view : FiltersWindowView ) -> Dict [str , Any ]:
@@ -260,7 +259,7 @@ def _subtract(data, dark=None):
260
259
np .subtract (data , dark , out = data )
261
260
262
261
263
- def _execute (data , flat = None , dark = None , cores = None , chunksize = None , progress = None ):
262
+ def _execute (data : np . ndarray , flat = None , dark = None , cores = None , chunksize = None , progress = None ):
264
263
"""A benchmark justifying the current implementation, performed on
265
264
500x2048x2048 images.
266
265
@@ -289,11 +288,13 @@ def _execute(data, flat=None, dark=None, cores=None, chunksize=None, progress=No
289
288
norm_divide [norm_divide == 0 ] = MINIMUM_PIXEL_VALUE
290
289
291
290
# subtract the dark from all images
292
- f = ptsm .create_partial (_subtract , fwd_function = ptsm .inplace_second_2d )
293
- data , dark = ptsm .execute (data , dark , f , cores , chunksize , progress = progress )
291
+ do_subtract = ps .create_partial (_subtract , fwd_function = ps .inplace_second_2d )
292
+ ps .shared_list = [data , dark ]
293
+ ps .execute (do_subtract , data .shape [0 ], progress , cores = cores )
294
294
295
295
# divide the data by (flat - dark)
296
- f = ptsm .create_partial (_divide , fwd_function = ptsm .inplace_second_2d )
297
- data , norm_divide = ptsm .execute (data , norm_divide , f , cores , chunksize , progress = progress )
296
+ do_divide = ps .create_partial (_divide , fwd_function = ps .inplace_second_2d )
297
+ ps .shared_list = [data , norm_divide ]
298
+ ps .execute (do_divide , data .shape [0 ], progress , cores = cores )
298
299
299
300
return data
0 commit comments