diff --git a/.github/workflows/build-and-publish-docs.yml b/.github/workflows/build-and-publish-docs.yml index a8c1163b..1773007a 100644 --- a/.github/workflows/build-and-publish-docs.yml +++ b/.github/workflows/build-and-publish-docs.yml @@ -3,7 +3,7 @@ on: push: branches: - master - - qy/add-plantseg-v1-installation + - qy/mask-pred permissions: contents: write diff --git a/docs/chapters/plantseg_interactive_napari/preprocessing.md b/docs/chapters/plantseg_interactive_napari/preprocessing.md index 40c74944..4e0626b8 100644 --- a/docs/chapters/plantseg_interactive_napari/preprocessing.md +++ b/docs/chapters/plantseg_interactive_napari/preprocessing.md @@ -11,3 +11,9 @@ This section describes the data processing functionalities available in PlantSeg ## Widget: Image Rescaling --8<-- "napari/dataprocessing/rescale.md" + +## Widget: Image Pair Operations + +```python exec="1" html="1" +--8<-- "napari/dataprocessing/image_pair_operations.py" +``` diff --git a/docs/chapters/python_api/functionals/data_processing.md b/docs/chapters/python_api/functionals/data_processing.md index f96862e5..ee8bbeae 100644 --- a/docs/chapters/python_api/functionals/data_processing.md +++ b/docs/chapters/python_api/functionals/data_processing.md @@ -10,6 +10,7 @@ Basic data processing functions are provided in the `dataprocessing` module. The ::: plantseg.functionals.dataprocessing.dataprocessing.image_median ::: plantseg.functionals.dataprocessing.dataprocessing.image_gaussian_smoothing ::: plantseg.functionals.dataprocessing.dataprocessing.image_crop +::: plantseg.functionals.dataprocessing.dataprocessing.process_images ## Segmentation Functions diff --git a/docs/chapters/python_api/tasks/dataprocessing_tasks.md b/docs/chapters/python_api/tasks/dataprocessing_tasks.md index 6d6cec2a..60e11669 100644 --- a/docs/chapters/python_api/tasks/dataprocessing_tasks.md +++ b/docs/chapters/python_api/tasks/dataprocessing_tasks.md @@ -1,41 +1,45 @@ -# Import and export tasks +# Data Processing Tasks -## Gaussian smoothing task +## Image Preprocessing Tasks + +### Gaussian smoothing task ::: plantseg.tasks.dataprocessing_tasks.gaussian_smoothing_task -## Image cropping task +### Image cropping task ::: plantseg.tasks.dataprocessing_tasks.image_cropping_task - -## Image rescale to shape task +### Image rescale to shape task ::: plantseg.tasks.dataprocessing_tasks.image_rescale_to_shape_task - -## Image rescale to voxel size task +### Image rescale to voxel size task ::: plantseg.tasks.dataprocessing_tasks.image_rescale_to_voxel_size_task -## Set image voxel size task +### Set image voxel size task ::: plantseg.tasks.dataprocessing_tasks.set_voxel_size_task -## Label Postprocessing +## Image pair operation task + +::: plantseg.tasks.dataprocessing_tasks.image_pair_operation_task + +## Label Postprocessing Tasks -## Remove false positives task +### Remove false positives task ::: plantseg.tasks.dataprocessing_tasks.remove_false_positives_by_foreground_probability_task -## Fix Over/Under segmentation task +### Fix Over/Under segmentation task ::: plantseg.tasks.dataprocessing_tasks.fix_over_under_segmentation_from_nuclei_task -## Set biggest object as background task +### Set biggest object as background task ::: plantseg.tasks.dataprocessing_tasks.set_biggest_instance_to_zero_task -## Relabel task +### Relabel task ::: plantseg.tasks.dataprocessing_tasks.relabel_segmentation_task diff --git a/docs/snippets/napari/dataprocessing/image_pair_operations.py b/docs/snippets/napari/dataprocessing/image_pair_operations.py new file mode 100644 index 00000000..8c587d51 --- /dev/null +++ b/docs/snippets/napari/dataprocessing/image_pair_operations.py @@ -0,0 +1,10 @@ +import sys + +sys.path.append("docs/snippets") + +from napari_widgets_render import render_widget + +from plantseg.viewer_napari.widgets import widget_image_pair_operations + +html = render_widget(widget_image_pair_operations) +print(html) diff --git a/plantseg/tasks/dataprocessing_tasks.py b/plantseg/tasks/dataprocessing_tasks.py index d65c7130..98fe2023 100644 --- a/plantseg/tasks/dataprocessing_tasks.py +++ b/plantseg/tasks/dataprocessing_tasks.py @@ -326,6 +326,9 @@ def image_pair_operation_task( image1 (PlantSegImage): First image to process. Image2 (PlantSegImage): Second image to process. operation (str): Operation to perform on the images. + normalize_input (bool): Normalize input images before processing. + clip_output (bool): Clip output values to the range [0, 1]. + normalize_output (bool): Normalize output values to the range [0, 1]. Returns: PlantSegImage: New image resulting from the operation. diff --git a/tests/functionals/dataprocessing/test_image_math.py b/tests/functionals/dataprocessing/test_image_math.py index 57ca21f6..e2dd07fe 100644 --- a/tests/functionals/dataprocessing/test_image_math.py +++ b/tests/functionals/dataprocessing/test_image_math.py @@ -11,7 +11,6 @@ ) -# Mock normalize_01 function (replace with your actual implementation) def normalize_01(image: np.ndarray) -> np.ndarray: min_val, max_val = image.min(), image.max() if max_val - min_val == 0: @@ -19,7 +18,6 @@ def normalize_01(image: np.ndarray) -> np.ndarray: return (image - min_val) / (max_val - min_val) -# Test cases for process_images @pytest.mark.parametrize( "operation, expected_result", [ @@ -103,12 +101,16 @@ def test_max_images(): assert np.allclose(result, expected), "Max operation failed" -# Error handling def test_process_images_invalid_operation(): image1 = np.array([[1, 2], [3, 4]]) image2 = np.array([[1, 2], [3, 4]]) with pytest.raises(ValueError, match="Unsupported operation: invalid"): process_images( - image1, image2, operation="invalid", normalize_input=False, clip_output=False, normalize_output=False + image1, + image2, + operation="invalid", + normalize_input=False, + clip_output=False, + normalize_output=False, )