如何计算方向轴?

2023-11-25

之前,我根据解剖结构(例如爪子的脚趾)计算了方向轴。

enter image description here

但我发现,当我无法很好地区分脚趾或者“脚跟”(蓝色方块)偏离得很远时,这不起作用。所以我决定寻找更好的替代方案并决定尝试计算惯性轴.

此页面很好地解释了如何计算它,但我很难理解从质心(或我的例子中的压力)到某个角度的步骤。

enter image description here

The explanation boils it down to: enter image description here which uses the Center of Pressure and a value p, of which I don't know what it is.

我可以访问计算人脚轴的 Matlab 代码,并尽力将其翻译为 Python:

x = 0.508 # sensor size in the x-direction
y = 0.762 # sensor size in the y-direction
Ptot = 0 # total pressure 
Px   = 0 # first order moment(x)
Py   = 0 # first order moment(y)
Pxx  = 0 # second order moment (y)
Pyy  = 0 # second order moment (x)
Pxy  = 0 # second order moment (xy)

for row in range(rows): # y-direction
    for col in range(cols): # x-direction
        if data[row,col] > 0.0: # If not zero
            temp = 1
        else:
            temp = 0
        Ptot = Ptot + temp # Add 1 for every sensor that is nonzero
        Px = Px   + (x * col + x / 2) * temp
        Py = Py   + (y * row + y / 2) * temp
        Pxx = Pxx + (x * y * y * y / 12 + x * y * (row * y + y / 2) * (row * y + y / 2) ) * temp
        Pyy = Pyy + (y * x * x * x / 12 + x * y * (col * x + x / 2) * (col * x + x / 2) ) * temp        
        Pxy = Pxy + (x * y * (row * y + y / 2) * (row * x + x / 2)) * temp

CoPY = Py / Ptot
CoPX = Px / Ptot
CoP = [CoPX, CoPY]

Ixx = Pxx - Ptot * self.x * self.y * CoPY * CoPY
Iyy = Pyy - Ptot * self.x * self.y * CoPX * CoPX
Ixy = Pxy - Ptot * self.x * self.y * CoPY * CoPX
angle = (math.atan(2 * Ixy / (Iyy - Ixx))) / 2

Ixp = Ixx * math.cos(angle) * math.cos(angle) + Iyy * math.sin(angle) * math.sin(angle) - 2 * Ixy * math.sin(angle) * math.cos(angle)
Iyp = Iyy * math.cos(angle) * math.cos(angle) + Ixx * math.sin(angle) * math.sin(angle) + 2 * Ixy * math.sin(angle) * math.cos(angle)
RotationMatrix = [[math.cos(angle), math.sin(angle)], [-math.sin(angle), math.cos(angle)]]

据我了解,RotationMatrix 中的 sin(angle) 和 cos(angle) 用于确定轴。但我真的不明白如何使用这些值来绘制穿过爪子的轴围绕它旋转.

知道我做错了什么和/或我应该做什么来解决它吗?

If someone feels the need to experiment, here's a file with all the sliced arrays that contain the pressure data of each paw. To clarfiy: walk_sliced_data is a dictionary that contains ['ser_3', 'ser_2', 'sel_1', 'sel_2', 'ser_1', 'sel_3'], which are the names of the measurements. Each measurement contains another dictionary, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (example from 'sel_1') which represent the impacts that were extracted.


好吧,这是一个与上面的代码执行相同操作的实现(并将图像旋转相关角度)。

然而,就你的爪子而言,我不确定它是否能像人脚一样有效。

首先,对于狗的爪子,以这种方式定义的“长”轴是沿着爪子的宽度而不是爪子的长度。只要保持一致,这并不重要,因为我们可以简单地旋转计算出的角度,而不是 90 度(计算出的角度)。

然而,狗的爪子接近圆形这一事实给我们带来了更多问题。

基本上,这对狗来说可能不会像对人类那么有用。由图像的第二中心矩形成的图像的协方差矩阵推导出的“长”轴的旋转(这就是(我认为)上面的代码所做的)不太可能准确测量爪子。

换句话说,狗的爪子接近圆形,并且它们的大部分重量似乎都集中在脚趾上,因此在此计算中“后”脚趾的权重小于字体的权重。因此,我们得到的轴不会始终与“后”脚趾与前脚趾的位置有关系。 (希望这是有道理的......我是一个糟糕的作家......这就是为什么我回答这个问题而不是写我应该写的论文......)

无论如何,废话已经够多了……这是一个例子:

import cPickle
import numpy as np
import matplotlib.pyplot as plt

from scipy import ndimage

def main():
    measurements = cPickle.load(open('walk_sliced_data', 'r'))
    plot(measurements['ser_1'].values())
    plt.show()

def raw_moment(data, iord, jord):
    nrows, ncols = data.shape
    y, x = np.mgrid[:nrows, :ncols]
    data = data * x**iord * y**jord
    return data.sum()

def intertial_axis(data):
    data_sum = data.sum()
    m10 = raw_moment(data, 1, 0)
    m01 = raw_moment(data, 0, 1)
    x_bar = m10 / data_sum
    y_bar = m01 / data_sum
    u11 = (raw_moment(data, 1, 1) - x_bar * m01) / data_sum
    u20 = (raw_moment(data, 2, 0) - x_bar * m10) / data_sum
    u02 = (raw_moment(data, 0, 2) - y_bar * m01) / data_sum
    angle = 0.5 * np.arctan(2 * u11 / (u20 - u02))
    return x_bar, y_bar, angle


def plot(impacts):
    def plot_subplot(pawprint, ax):
        x_bar, y_bar, angle = intertial_axis(pawprint)
        ax.imshow(pawprint)
        plot_bars(x_bar, y_bar, angle, ax)
        return angle

    fig1 = plt.figure()
    fig2 = plt.figure()
    for i, impact in enumerate(impacts[:9]):
        ax1 = fig1.add_subplot(3,3,i+1)
        ax2 = fig2.add_subplot(3,3,i+1)

        pawprint = impact.sum(axis=2)
        angle = plot_subplot(pawprint, ax1)

        pawprint = ndimage.rotate(pawprint, np.degrees(angle))
        plot_subplot(pawprint, ax2)

    fig1.suptitle('Original')
    fig2.suptitle('Rotated')

def plot_bars(x_bar, y_bar, angle, ax):
    def plot_bar(r, x_bar, y_bar, angle, ax, pattern):
        dx = r * np.cos(angle)
        dy = r * np.sin(angle)
        ax.plot([x_bar - dx, x_bar, x_bar + dx], 
                [y_bar - dy, y_bar, y_bar + dy], pattern)
    plot_bar(1, x_bar, y_bar, angle + np.radians(90), ax, 'wo-')
    plot_bar(3, x_bar, y_bar, angle, ax, 'ro-')
    ax.axis('image')


if __name__ == '__main__':
    main()

在这些图中,中心点是图像的质心,红线定义“长”轴,而白线定义“短”轴。

Original (Unrotated) Paws: enter image description here

Rotated Paws: enter image description here

这里需要注意的一件事......我只是围绕其中心旋转图像。 (还,scipy.ndimage.rotate对于 N 维数组和 2D 数组都适用。您可以轻松旋转原始 3D“随时间变化的爪印”阵列。)

如果您确实想围绕一个点(例如质心)旋转它,并将该点移动到新图像上的新位置,您可以在 scipy 中相当轻松地完成ndimage通过一些技巧来模块。如果你愿意的话我可以举个例子。不过这个例子有点长......

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何计算方向轴? 的相关文章

随机推荐

  • 无效操作:类型接口{}不支持索引

    我是 golang 新手 在读取嵌套 JSON 响应时遇到问题 var d interface json NewDecoder response Body Decode d test d data map string interface
  • R 中的循环效率低下

    早上好 我已经在 R 中进行了几个月的开发 我必须确保我的代码的执行时间不会太长 因为我分析大数据集 因此 我一直在尝试尽可能多地使用向量化函数 然而 我仍然想知道一些事情 R中代价高昂的不是循环本身吗 我的意思是 当您开始修改循环内的变量
  • 检查 9.30 到 4 ruby​​ 之间的时间

    我有一个错误地生成它的代码 我认为必须有更好的方法来检查时间 gt 9 30 am 和时间 def checkTime goodtime false if Time now hour gt 9 and Time now min gt 30
  • maven-surefire-report-plugin不生成surefire-report.html

    我无法获取maven surefire 报告插件生成Surefire report html当我跑步时 mvn clean deploy site mvn clean site mvn site mvn clean install site
  • 在 MySQL 的文本列中搜索字符串

    我有 mysql 表 其中有一列将 xml 存储为字符串 我需要找到 xml 列包含给定 6 个字符的字符串的所有元组 其他都不重要 我只需要知道这 6 个字符的字符串是否存在 因此 文本格式为 xml 可能并不重要 问题 如何在mysql
  • 在 Excel 单元格中创建超链接?

    是否可以在 Excel 单元格中创建仅使用单元格文本的一部分作为可点击链接的超链接 IE 下表模型是否代表可以在 Excel 2010 中轻松构建的内容 模拟http dl dropbox com u 14119404 misc Micro
  • SQL Server 将整数转换为二进制字符串

    我想知道 SQL 中是否有一种简单的方法可以将整数转换为其二进制表示形式 然后将其存储为 varchar 例如 5 将转换为 101 并存储为 varchar 实际上 使用普通的旧 SQL 非常简单 只需使用按位与即可 我有点惊讶的是 网上
  • 如何管理子模块的版本?

    如果 Go 存储库有go mod文件位于其根目录中 也位于子文件夹中 子模块的版本是如何发布的 举例来说 我的团队一直在使用 Vault 来开发我们的内部 cli 工具 我们最终使用了 github com hashicorp vault
  • Apache 2.4.1 未定义对“SSLv2_client_method”的引用

    我之前运行的是 apache 2 2 20 和 openssl 1 0 0e 我安装了 openssl 1 0 1 然后下载了 apache 2 4 1 的 tarball 并安装了 apr 1 4 6 和 apr util 1 4 1 p
  • Play 2.0 中如何将多个参数传递到模板中?

    我想同时向我的模板渲染两件事 如下所示 String one one String two two return ok template render one two 但 Playframework 说这是错误的 那么如何才能同时渲染 2
  • 使 Cocoa 应用程序可编写脚本 Swift

    Goal 我正在尝试使我的 Cocoa 应用程序能够从 Applescript 中用 Swift 编写脚本 我做了什么 我创建了一个 SDEF 文件 配置了 info plist 并创建了一个我认为合适的类 定义 sdef
  • Grails Eclipse 插件

    我在 SO 上看到过各种批评 Eclipse Grails 插件的帖子 我想知道是否有人找到了一种在 Eclipse 中高效使用 Grails 的方法 我看了一下Grails 插件页面 并且那里的信息看起来不太有希望 特别是有关 禁用 Gr
  • Facebook 分享按钮和自定义文本[关闭]

    Closed 这个问题需要多问focused 目前不接受答案 有没有办法让 Facebook 分享按钮在墙上或新闻提要上发布自定义文本 我们使用这样的东西 在一行中使用 a title send to Facebook href http
  • 简单的 Java HTTPS 服务器

    我需要为 Java 应用程序设置一个真正轻量级的 HTTPS 服务器 它是我们的开发实验室中使用的一个模拟器 用于模拟一台设备在野外接受的 HTTPS 连接 因为它纯粹是一个轻量级开发工具 根本不以任何方式用于生产 所以我很高兴能够绕过认证
  • 强制编译器选择以 const T& 作为参数的复制构造函数

    我正在编写一个类 其中有模板化构造函数和复制构造函数 每次我想使用非常量对象调用复制构造函数时 都会选择模板化构造函数 如何强制编译器选择复制构造函数 这是 mcve include
  • gcc/g++:“没有这样的文件或目录”

    g 给我以下形式的错误 foo cc
  • 使用 select 清除 angularJS 中的过滤器

    我在下面给出的 HTML 中使用 ngOptions 指令
  • 如何在 Spring boot 嵌入式 tomcat 中设置 HTTPS SSL Cipher Suite Preference

    我正在尝试根据服务器首选项设置 HTTPS SSL 密码套件首选项 而不是根据客户端和服务器支持的具有最高强度的通用密码套件自动选择 我想让服务器选择具有 TLS ECDHE 的服务器和客户端之间的共同点 以支持前向保密 我已经在 www
  • 删除所有以某个单词开头的 NSUserDefaults

    有没有办法让我 遍历 所有的列表NSUserDefault在我的 iPhone 应用程序中 只删除某些内容 例如 我想获取以某个单词开头的所有键名称 像这样的东西 NSUserDefaults standardUserDefaults re
  • 如何计算方向轴?

    之前 我根据解剖结构 例如爪子的脚趾 计算了方向轴 但我发现 当我无法很好地区分脚趾或者 脚跟 蓝色方块 偏离得很远时 这不起作用 所以我决定寻找更好的替代方案并决定尝试计算惯性轴 此页面很好地解释了如何计算它 但我很难理解从质心 或我的例