def compute(self, roi: DataRoi) -> FeatureData: features: List[FeatureData] = [] channel_offset: int = 0 for fx in self.extractors: result = fx.compute(roi).translated(Point5D.zero(c=channel_offset)) features.append(result) channel_offset += result.shape.c out = Array5D.combine(features) return FeatureData( arr=out.raw(out.axiskeys), axiskeys=out.axiskeys, location=out.location )
def compute(self, roi: DataRoi) -> FeatureData: roi_step: Shape5D = roi.shape.updated( c=1, t=1) # compute features independently for each c and each t if self.axis_2d: roi_step = roi_step.updated(**{self.axis_2d: 1}) # also compute in 2D slices per_channel_results: List[FeatureData] = [] for roi_slice in roi.split(roi_step): haloed_roi = roi_slice.enlarged(self.halo) channel_offset = roi_slice.start.c - roi.start.c if self.presmooth_sigma > 0: gaussian_filter = GaussianSmoothing( preprocessor=self.preprocessor, sigma=self.presmooth_sigma, axis_2d=self.axis_2d, window_size=3.5) source_data = gaussian_filter.compute(haloed_roi) else: source_data = self.preprocessor.compute(haloed_roi) source_axes = "zyx" if self.axis_2d: source_axes = source_axes.replace(self.axis_2d, "") raw_data: numpy.ndarray = source_data.raw(source_axes).astype( numpy.float32) raw_feature_data: numpy.ndarray = self.filter_fn(raw_data) if len(raw_feature_data.shape) > len(source_axes): output_axes = source_axes + "c" channel_multiplier = raw_feature_data.shape[-1] else: output_axes = source_axes channel_multiplier = 1 feature_data = FeatureData( raw_feature_data, axiskeys=output_axes, location=haloed_roi.start.updated(c=channel_offset * channel_multiplier)) per_channel_results.append(feature_data.cut(roi_slice, c=All())) combined_result = Array5D.combine(per_channel_results) out = FeatureData(combined_result.raw(combined_result.axiskeys), axiskeys=combined_result.axiskeys, location=combined_result.location) out.setflags(write=False) return out