fishdist.stack_prediction

predict_3D_stack_from_2D_model(deepTA, stack, apply_normalization_to_entire_stack_before=True, rotation_along_Z_axis_pattern=None, **predict_parameters)

Predict a 3D image stack slice-by-slice using a 2D model.

This function applies a 2D DeepTA model to each Z-slice of a 3D stack, optionally normalizing the stack globally, applying rotations along Z, and returning the combined predicted 3D stack.

Parameters:
  • deepTA (object) –

    Model-like object implementing the same API as predict_single_image().

  • stack (str or ndarray) –

    Path to an image stack or array with shape (Z, H, W) or (Z, H, W, C). If a path is provided, the stack is loaded using Img().

  • apply_normalization_to_entire_stack_before (bool, default=True, default: True ) –

    If True, normalize the entire stack globally before prediction.

  • rotation_along_Z_axis_pattern (optional, default: None ) –

    If provided, rotates the stack along Z before prediction and un-rotates afterwards.

  • **predict_parameters

    Additional parameters passed to predict_single_image(), including optional "input_normalization" for normalization configuration.

Returns:
  • np.ndarray: Predicted 3D stack, shape (Z, H, W, ...) depending on model output.

Example
predicted_stack = predict_3D_stack_from_2D_model(deepTA_model, 'stack.tif', apply_normalization_to_entire_stack_before=True)

predict_single_image(deepTA, input_file, **predict_parameters)

Run prediction on a single image using a DeepTA model.

This function prepares a temporary image file for compatibility with DeepTA's predict_generator API, generates predictions for the input image, and returns the results.

Parameters:
  • deepTA (object) –

    An object implementing the following methods: - get_inputs_shape() - get_outputs_shape() - get_predict_generator(...) - predict_single(...)

  • input_file (str or array - like) –

    Path to the input image or an object convertible to an image by Img(...).

  • **predict_parameters

    Additional keyword arguments passed to both get_predict_generator() and predict_single(). Special key: clip_by_frequency (optional): Passed only to get_predict_generator().

Returns:
  • any

    Model prediction result(s) as returned by deepTA.predict_single().

Example
results = predict_single_image(deepTA_model, 'image.tif', clip_by_frequency=0.01)
print(results)