Skip to content

Commit

Permalink
analyse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alasdairwilson committed Jul 10, 2024
1 parent d565dae commit c99fa0b
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ local_scheme = "no-local-version"

[tool.pytest.ini_options]
norecursedirs = ['examples']
testpaths = ['tests', 'docs']
testpaths = ['ripplemapper/tests', 'docs']
text_file_format = "rst"
addopts = [
"--doctest-glob=*.rst"
Expand Down
2 changes: 2 additions & 0 deletions ripplemapper/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def remove_small_bumps(contour: RippleContour, **kwargs) -> RippleContour:

def remove_small_bumps_from_images(ripple_images: list[RippleImage] | RippleImage, **kwargs) -> list[RippleImage]:
"""Remove small bumps from a list of RippleImage objects."""
if isinstance(ripple_images, RippleImageSeries):
ripple_images = ripple_images.images
if isinstance(ripple_images, RippleImage):
ripple_images = [ripple_images]
for ripple_image in ripple_images:
Expand Down
Binary file modified ripplemapper/data/example/rimgs/1_00052_sample.rimg
Binary file not shown.
Binary file modified ripplemapper/data/example/rimgs/1_00205_sample.rimg
Binary file not shown.
Binary file modified ripplemapper/data/example/rimgs/1_00375_sample.rimg
Binary file not shown.
Binary file modified ripplemapper/data/example/rimgs/1_00443_sample.rimg
Binary file not shown.
Binary file modified ripplemapper/data/example/rimgs/image_series.rimgs
Binary file not shown.
5 changes: 4 additions & 1 deletion ripplemapper/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def preprocess_image(image: np.ndarray, roi_x: list[int]=False, roi_y: list[int]
Returns:
numpy.ndarray: Preprocessed image.
"""
gray_image = color.rgb2gray(image)
if len(image.shape) == 3 and image.shape[2] == 3:
gray_image = color.rgb2gray(image)
else:
gray_image = image
blurred_gray_image = filters.gaussian(gray_image, sigma=sigma)
# crop the image
if roi_x:
Expand Down
61 changes: 61 additions & 0 deletions ripplemapper/tests/test_analyse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pytest

from ripplemapper.analyse import (add_a_star_contours, add_boundary_contours,
add_chan_vese_contours, remove_small_bumps,
remove_small_bumps_from_images)


def test_add_boundary_contours(loaded_example_image):
add_boundary_contours(loaded_example_image)
assert len(loaded_example_image.contours) == 2
assert loaded_example_image.contours[0].method == 'Upper Boundary'
assert loaded_example_image.contours[1].method == 'Lower Boundary'

def test_add_a_star_contours(loaded_example_image):
add_boundary_contours(loaded_example_image)
add_a_star_contours(loaded_example_image)
assert len(loaded_example_image.contours) == 3
assert loaded_example_image.contours[2].method == 'A* traversal'

def test_add_chan_vese_contours(loaded_example_image):
add_chan_vese_contours(loaded_example_image)
assert len(loaded_example_image.contours) == 1
assert loaded_example_image.contours[0].method == 'Chan-Vese'

def test_remove_small_bumps(loaded_example_contour):
smoothed_contour = remove_small_bumps(loaded_example_contour)
assert smoothed_contour.values.shape[1] <= loaded_example_contour.values.shape[1]

def test_remove_small_bumps_from_images(loaded_example_image):
add_boundary_contours(loaded_example_image)
remove_small_bumps_from_images(loaded_example_image)
assert len(loaded_example_image.contours) == 2

def test_add_boundary_contours_image_series(loaded_example_image_series):
add_boundary_contours(loaded_example_image_series)
for image in loaded_example_image_series.images:
assert len(image.contours) == 2
assert image.contours[0].method == 'Upper Boundary'
assert image.contours[1].method == 'Lower Boundary'

def test_add_a_star_contours_image_series(loaded_example_image_series):
add_boundary_contours(loaded_example_image_series)
add_a_star_contours(loaded_example_image_series)
for image in loaded_example_image_series.images:
assert len(image.contours) == 3
assert image.contours[2].method == 'A* traversal'

def test_add_chan_vese_contours_image_series(loaded_example_image_series):
add_chan_vese_contours(loaded_example_image_series)
for image in loaded_example_image_series.images:
assert len(image.contours) == 1
assert image.contours[0].method == 'Chan-Vese'

def test_remove_small_bumps_from_image_series(loaded_example_image_series):
add_boundary_contours(loaded_example_image_series)
remove_small_bumps_from_images(loaded_example_image_series)
for image in loaded_example_image_series.images:
assert len(image.contours) == 2

if __name__ == '__main__':
pytest.main()

0 comments on commit c99fa0b

Please sign in to comment.