Skip to content

Commit

Permalink
docs(math): docs for image pair operations
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-yu committed Dec 3, 2024
1 parent 4d141c8 commit a782a70
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- master
- qy/add-plantseg-v1-installation
- qy/mask-pred

permissions:
contents: write
Expand Down
6 changes: 6 additions & 0 deletions docs/chapters/plantseg_interactive_napari/preprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
1 change: 1 addition & 0 deletions docs/chapters/python_api/functionals/data_processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 17 additions & 13 deletions docs/chapters/python_api/tasks/dataprocessing_tasks.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions docs/snippets/napari/dataprocessing/image_pair_operations.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions plantseg/tasks/dataprocessing_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions tests/functionals/dataprocessing/test_image_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
)


# 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:
return np.zeros_like(image)

Check warning on line 17 in tests/functionals/dataprocessing/test_image_math.py

View check run for this annotation

Codecov / codecov/patch

tests/functionals/dataprocessing/test_image_math.py#L17

Added line #L17 was not covered by tests
return (image - min_val) / (max_val - min_val)


# Test cases for process_images
@pytest.mark.parametrize(
"operation, expected_result",
[
Expand Down Expand Up @@ -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,
)

0 comments on commit a782a70

Please sign in to comment.