Skip to content

Commit

Permalink
Compute Circle mask (#2092)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc authored Mar 7, 2024
2 parents d6f16e8 + f2033e5 commit 1194d69
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions mantidimaging/core/operations/circular_mask/circular_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from __future__ import annotations

from functools import partial
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, List, Dict, Any

import numpy as np
import tomopy

from mantidimaging.core.parallel import shared as ps
from mantidimaging.core.operations.base_filter import BaseFilter
from mantidimaging.core.utility.progress_reporting import Progress
from mantidimaging.gui.utility.qt_helpers import Type

if TYPE_CHECKING:
Expand Down Expand Up @@ -42,15 +42,19 @@ def filter_func(data: ImageStack, circular_mask_ratio=0.95, circular_mask_value=
if not circular_mask_ratio or not circular_mask_ratio < 1:
raise ValueError(f'circular_mask_ratio must be > 0 and < 1. Value provided was {circular_mask_ratio}')

progress = Progress.ensure_instance(progress, num_steps=1, task_name='Circular Mask')

with progress:
progress.update(msg="Applying circular mask")
params = {'circular_mask_ratio': circular_mask_ratio, 'circular_mask_value': circular_mask_value}

tomopy.circ_mask(arr=data.data, axis=0, ratio=circular_mask_ratio, val=circular_mask_value)
ps.run_compute_func(CircularMaskFilter.compute_function, len(data.data), [data.shared_array], params, progress)

return data

@staticmethod
def compute_function(i: int, arrays: List[np.ndarray], params: Dict[str, Any]):
array = arrays[i]
if array.ndim == 2:
array = np.expand_dims(array, axis=0)
tomopy.circ_mask(array, axis=0, ratio=params['circular_mask_ratio'], val=params['circular_mask_value'])

@staticmethod
def register_gui(form, on_change, view):
from mantidimaging.gui.utility import add_property_to_form
Expand Down

0 comments on commit 1194d69

Please sign in to comment.