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 /r/forceFieldTransform.R | |
parent | 2b6cb9b655a53d43b32a8a211287c82f4f59999a (diff) | |
download | atoolbox-c9c896dea2ba43551c4e10bd49666105449e9bd7.tar.bz2 |
add all scripts/tools
Diffstat (limited to 'r/forceFieldTransform.R')
-rw-r--r-- | r/forceFieldTransform.R | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/r/forceFieldTransform.R b/r/forceFieldTransform.R new file mode 100644 index 0000000..92310c1 --- /dev/null +++ b/r/forceFieldTransform.R @@ -0,0 +1,46 @@ +# -*- coding: utf -*- +# +# Calculate the "force field transform" of the image, using the +# specified *cell* size. +# +# The image is padded with the mirrored boundary condition. +# +# NOTE:TODO: +# The transformation output strengths image is NOT normalized! +# +# +# Credit: +# [1] TODO: +# Hurley et al., 2002, 2005 +# +# +# Aaron LI +# 2015/08/28 +# + + +# The attractive force between two points on the image. +# NOTE: the coefficient is ignored +# +# Arguments: +# p0, p1 - (r, c, value), the row and column number of the point position, +# and the value of that point +# +# Return: +# the force vector (f_r, f_c): +# 'f_r': force along the row direction, positive goes downside +# 'f_c': force along the column direction, positive goes to the right +# Note that this is the force that 'p1' act on 'p0', and is directed +# to point 'p1'. +p2p.force <- function(p0, p1) { + r0 = p0[1] + c0 = p0[2] + r1 = p1[1] + c1 = p1[2] + f_r = p0[3]*p1[3] * (r1-r0) / ((r1-r0)^2 + (c1-c0)^2)^1.5 + f_c = p0[3]*p1[3] * (c1-c0) / ((r1-r0)^2 + (c1-c0)^2)^1.5 + return(c(f_r, f_c)) +} + + +# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=r: # |