diff options
author | Aaron LI <aaronly.me@gmail.com> | 2016-03-31 10:57:34 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@gmail.com> | 2016-03-31 10:57:34 +0800 |
commit | c9c896dea2ba43551c4e10bd49666105449e9bd7 (patch) | |
tree | e94b73f17b2d776c2acd4c9549657f500c3dc7ce /julia/calc_k_percentile.jl | |
parent | 2b6cb9b655a53d43b32a8a211287c82f4f59999a (diff) | |
download | atoolbox-c9c896dea2ba43551c4e10bd49666105449e9bd7.tar.bz2 |
add all scripts/tools
Diffstat (limited to 'julia/calc_k_percentile.jl')
-rw-r--r-- | julia/calc_k_percentile.jl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/julia/calc_k_percentile.jl b/julia/calc_k_percentile.jl new file mode 100644 index 0000000..36b15e1 --- /dev/null +++ b/julia/calc_k_percentile.jl @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# +# Calculate the percentile of the gradient image, which +# used as the 'kappa' parameter of the anisotropic diffusion. +# +# Credits: +# [1] KAZE: nldiffusion_functions.cpp / compute_k_percentile() +# +# Aaron LI +# 2015/07/20 +# + +include("scharr.jl"); + +function calc_k_percentile(img, percent=0.7, nbins=300) + rows, cols = size(img) + # derivatives of the image + img_gx = scharr(img, 1, 0) + img_gy = scharr(img, 0, 1) + img_modg = sqrt(img_gx.^2 + img_gy.^2) + # histogram + hmax = maximum(img_modg) + hist_e, hist_counts = hist(reshape(img_modg, length(img_modg)), nbins) + hist_cum = cumsum(hist_counts) + # find the percent of the histogram percentile + npoints = sum(img_modg .> 0.0) + nthreshold = npoints * percent + k = sum(hist_cum .<= nthreshold) + kperc = (k == length(hist_cum)) ? 0.03 : (hmax * k / nbins) + return kperc +end + |