-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alasdair Wilson
committed
Jun 27, 2024
1 parent
1996cc0
commit 3f8b2d1
Showing
6 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
===================================== | ||
Adding Chan-Vese Contours to an Image | ||
===================================== | ||
This example shows how to add a contour based on an A-star traversal of the image in an area between two existing contours. | ||
This is useful as a method to produce an average path between two contours, for example the 'upper' and 'lower' boundaries of a ripple. | ||
Since it is common for waves to have a shape that is multivalued then a normal averaging method will not effectivey capture the average shape of the two contours. | ||
""" | ||
|
||
################################################################################ | ||
# We can load an image into a RippleImage object using the RippleImage class and then run `add_boundary_contours` to add our limits for the A* contour to the image. | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from ripplemapper.analyse import add_boundary_contours, add_a_star_contours | ||
from ripplemapper.classes import RippleImage | ||
from ripplemapper.data.example import example_data | ||
|
||
ripple_img = RippleImage(example_data[1]) | ||
add_boundary_contours(ripple_img) | ||
|
||
################################################################################ | ||
# From here we can run `add_a_star_contours` to add the A* contour that uses these two boundaries as its limits. | ||
|
||
add_a_star_contours(ripple_img) | ||
|
||
################################################################################ | ||
# Plotting the image and its contours | ||
|
||
ripple_img.plot(include_contours=True) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
===================================== | ||
Adding Chan-Vese Contours to an Image | ||
===================================== | ||
This example shows how to add a contour based on the chan-vese segmentation of the image. | ||
The Chan-vese algorithm is a level set method for image segmentation. | ||
It is based on the Mumford-Shah functional and is designed to segment images without edges. | ||
In this example, we will the `ripplemapper.analyse` module to segment the image and add the resulting contour to the image. | ||
""" | ||
|
||
################################################################################ | ||
# We can load an image into a RippleImage object using the RippleImage class and then run `add_chan_vese_contours` to add Chan-Vese contours to the image. | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from ripplemapper.analyse import add_chan_vese_contours | ||
from ripplemapper.classes import RippleImage | ||
from ripplemapper.data.example import example_data | ||
|
||
ripple_img = RippleImage(example_data[1]) | ||
add_chan_vese_contours(ripple_img) | ||
|
||
################################################################################ | ||
# Plotting the image and its contours | ||
|
||
ripple_img.plot(include_contours=True) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
=========================================== | ||
Removing "bumps" from a computed boundary | ||
=========================================== | ||
Since many of the methods for computing boundaries rely on contouring data, it is possible that the contours may have small "bumps" in them. | ||
This happens when the contouring "jumps" from one parallel line to the next and back again, it looks like a small discontinuity when plotted. | ||
These can sometimes be removed using ripplemapper. | ||
""" | ||
|
||
################################################################################ | ||
# We load our image into a RippleImage and then run `add_boundary_contours` to add boundary contours to the image. | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from ripplemapper.analyse import add_boundary_contours, remove_small_bumps | ||
from ripplemapper.classes import RippleImage | ||
from ripplemapper.data.example import example_data | ||
|
||
ripple_img = RippleImage(example_data[-1]) | ||
add_boundary_contours(ripple_img, sigma=2) | ||
|
||
################################################################################ | ||
# Plotting the contour | ||
|
||
ripple_img.contours[0].plot() | ||
plt.show() | ||
|
||
################################################################################ | ||
# We can remove the small bumps by running `remove_small_bumps`. | ||
|
||
remove_small_bumps(ripple_img.contours[0]) | ||
|
||
################################################################################ | ||
# Plotting the now smoothed contour, this is not perfectly smooth but does have some of the abrupt discontoniuties removed. | ||
|
||
ripple_img.contours[0].plot() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters