Source code for ddd_pylib.image_manip._find_extrema_operator

from ddd_pylib._base import MeasurementsOperator
from skimage.morphology import h_maxima, h_minima
import numpy as np
import pandas as pd


[docs] class FindExtremaOperator(MeasurementsOperator): """ Searches for the local extrema (minima or maxima) on an image. These extrema are filtered by prominence, which is a measure of how much an extremum stands out from its surroundings. **Note:** The prominence is always positive. If you are looking for local maxima, set blackBackground to True. If you are looking for local minima, set blackBackground to False. Settable parameters: blackBackground (setBlackBackground): If True, the operator will look for local maxima. prominence (setProminence): The minimum prominence of a local extremum. Produces: result (getResult): The extrema as a list of coordinates bundled in a :code:`pd.DataFrame`. Each line is a point and each column is an axis. """ def __init__(self): super().__init__() self._blackBackground = self.defaultBlackBackground() self._prominence = self.defaultProminence()
[docs] @staticmethod def defaultBlackBackground() -> bool: return True
[docs] @staticmethod def defaultProminence() -> float: return 1.0
[docs] def getPrefix(self) -> str: return "Extrema-"
[docs] def setBlackBackground(self, value: bool): """ Set the blackBackground attribute, which defines if we are looking for minima or maxima """ self._blackBackground = value
[docs] def setProminence(self, value: float|int): """ Set the minimum prominence of a local extremum. """ self._prominence = value
def _findExtrema(self, image): extrema_fx = h_maxima if self._blackBackground else h_minima extrema = extrema_fx(image.values, h=self._prominence) where = np.where(extrema > 0) df = pd.DataFrame({str(ax): w for ax, w in zip(image.dims, where)}) return df def _applyToFrame(self, frameData, t, nT): image = frameData[0] return self._findExtrema(image)