Created
May 2, 2018 13:03
-
-
Save RobBlackwell/c94a1ed348ac42fa123a8eec170ee9bd to your computer and use it in GitHub Desktop.
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
""" | |
hysthresh(im, T1, T2) | |
Hysteresis thresholding | |
A simple port of Peter Kovesi's MATLAB method to Julia. | |
See http://www.peterkovesi.com/matlabfns/Spatial/hysthresh.m | |
Usage: bw = hysthresh(im, T1, T2) | |
Arguments: | |
im - image to be thresholded (assumed to be non-negative) | |
T1 - upper threshold value | |
T2 - lower threshold value | |
(T1 and T2 can be entered in any order, the larger of the | |
two values is used as the upper threshold) | |
Returns: | |
bw - the thresholded image (containing values 0 or 1) | |
Function performs hysteresis thresholding of an image. | |
All pixels with values above threshold T1 are marked as edges | |
All pixels that are connected to points that have been marked as edges | |
and with values above threshold T2 are also marked as edges. | |
Copyright (c) 1996-2005 Peter Kovesi | |
School of Computer Science & Software Engineering | |
The University of Western Australia | |
http://www.csse.uwa.edu.au/ | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
The Software is provided "as is", without warranty of any kind. | |
""" | |
function hysthresh(im, T1, T2) | |
if T1 < T2 # T1 and T2 reversed - swap values | |
tmp = T1; | |
T1 = T2; | |
T2 = tmp; | |
end | |
# Edge points above lower threshold. | |
aboveT2 = im .> T2 | |
# Row and colum coords of points above upper threshold. | |
aboveT1r, aboveT1c = findn(im .> T1); | |
# Obtain all connected regions in aboveT2 that include a point that has a | |
# value above T1 | |
bw = bwselect(aboveT2, aboveT1c, aboveT1r); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment