View source: R/thr_twocorner.R
thr_twocorner | R Documentation |
Apply Rosin’s geometric corner detector for unimodal histograms \insertCiteRosin2001;textualrcaiman to both sides of a bimodal canopy histogram as in Macfarlane’s two-corner approach \insertCiteMacfarlane2011;textualrcaiman. Optional slope-reduction as in Macfarlane is supported. Peak detection can use a prominence-based method or Macfarlane’s original windowed maxima.
thr_twocorner(
x,
sigma = 2,
slope_reduction = TRUE,
method = "prominence",
diagnose = FALSE,
adjust_par = TRUE
)
x |
numeric vector or a single-column |
sigma |
numeric vector of length one. Standard deviation (DN) of the Gaussian kernel used to smooth the histogram prior to peak detection and Rosin’s construction. |
slope_reduction |
logical vector of length one. If |
method |
character vector of length one. Peak detection strategy. One of
|
diagnose |
logical vector of length one. If |
adjust_par |
logical vector of length one. If |
Runs the following pipeline:
Build an 8-bit histogram of x
after min–max normalization to
[0,255]
.
Smooth the histogram with a discrete Gaussian kernel of standard
deviation sigma
(in DN), using reflective padding to mitigate edge
bias.
Detect the two mode peaks according to method
:
method = "prominence"
: find local maxima via discrete
derivatives with plateau handling; find nearest left/right minima; compute
peak prominence as \min(y[p]-y[L],\,y[p]-y[R])
; filter by minimum
prominence and minimum peak separation; select the pair that maximizes
\min(\mathrm{prom}_\mathrm{left},\,\mathrm{prom}_\mathrm{right})
.
method = "macfarlane"
: search peaks within fixed DN windows as in
\insertCiteMacfarlane2011;textualrcaiman. Peak search is performed on the
unsmoothed histogram, as originally proposed.
Apply Rosin’s corner construction on each mode. The line end at the
“first empty bin after the last filled bin” is determined on the
unsmoothed histogram \insertCiteRosin2001;textualrcaiman. If
slope_reduction = TRUE
and the peak height exceeds the mean of the
smoothed histogram, the peak height is reduced to that mean before the
geometric construction (Macfarlane’s variant).
Derive thresholds:
T_l = DN_{lc} + (DN_{uc} - DN_{lc}) \times 0.25
T_m = DN_{lc} + (DN_{uc} - DN_{lc}) \times 0.50
T_h = DN_{lc} + (DN_{uc} - DN_{lc}) \times 0.75
where DN_{lc}
and DN_{uc}
are the lower and upper corners.
When diagnose = TRUE
, a geometric construction like the one shown below is
sent to the active graphics device.
When
diagnose = TRUE
and adjust_par = TRUE
, the function temporarily
adjusts margins to draw the geometric construction in a large square format
and restores the previous settings on exit. If adjust_par = FALSE
, no
parameters are changed and the plot respects the current device/layout.
A list with:
Lower peak DN.
Lower corner DN (Rosin on the left mode).
Low threshold derived from lc
and uc
.
Mid threshold derived from lc
and uc
.
High threshold derived from lc
and uc
.
Upper corner DN (Rosin on the right mode).
Upper peak DN.
caim <- conventional_lens_image()
# Prominence-based peak detection, Gaussian smoothing with sigma = 2 DN
thr <- thr_twocorner(caim$Blue[], sigma = 2, slope_reduction = FALSE,
method = "prominence")
# Original Macfarlane peak search (for comparison)
thr2 <- thr_twocorner(caim$Blue[], sigma = 2, slope_reduction = TRUE,
method = "macfarlane")
data.frame(unlist(thr), unlist(thr2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.