Skip to content

Commit

Permalink
Compute rescale operation (#2130)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc authored Mar 13, 2024
2 parents db14d23 + 0d4604f commit bb51655
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mantidimaging/core/operations/rescale/rescale.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any, Dict, TYPE_CHECKING

import numpy as np

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

Expand Down Expand Up @@ -42,9 +42,15 @@ def filter_func(images: ImageStack,
:return: The ImageStack object scaled to a new range.
"""

RescaleFilter.filter_array(images.data, min_input, max_input, max_output)
params = {'min_input': min_input, 'max_input': max_input, 'max_output': max_output}
ps.run_compute_func(RescaleFilter.compute_function, len(images.data), [images.shared_array], params)
return images

@staticmethod
def compute_function(index: int, array: np.ndarray, params: dict):
min_input, max_input, max_output = params['min_input'], params['max_input'], params['max_output']
array[index] = RescaleFilter.filter_array(array[index], min_input, max_input, max_output)

@staticmethod
def filter_array(image: np.ndarray, min_input: float, max_input: float, max_output: float) -> np.ndarray:
image[:] = np.interp(image, [min_input, max_input], [0, max_output])
Expand Down

0 comments on commit bb51655

Please sign in to comment.