简体   繁体   English

沿一个轴缩放/归一化 3D 个数据点?

[英]Scale/normalize 3D data points along one axis?

For a research project, I am asked to classify different types of spine curvatures using 3D landmarks of vertebrae.对于一个研究项目,我被要求使用 3D 椎骨界标对不同类型的脊柱弯曲进行分类。

3D Plots of 2 patients' spine landmarks 3D 2位患者的脊柱标志图

What I want the plots to look like more or less我希望这些情节或多或少看起来像什么

Since I am aiming to focus only on curvature, I need to scale/normalize the 3D lines along the Z-axis as patients differ in height and size.由于我的目标是只关注曲率,因此我需要缩放/归一化沿 Z 轴的 3D 线,因为患者的身高和体型不同。 I am not sure how to approach this problem of z-axis scaling while maintaining the relationship of the x and y axes with regard to z.我不确定如何在保持 x 轴和 y 轴相对于 z 的关系的同时解决这个 z 轴缩放问题。

print(spine_landmark_data_x.head(1).T)
print(spine_landmark_data_y.head(1).T)
print(spine_landmark_data_z.head(1).T)

Output of dataframes from above code (X,Y,Z coordinates in 3 separate dataframes)上面代码中的 Output 个数据帧(X、Y、Z 坐标在 3 个单独的数据帧中)

test_x = spine_landmark_data_x.copy()
test_y = spine_landmark_data_y.copy()
test_z = spine_landmark_data_z.copy()

# Scale each patient z-axis from 0 to 1
for row in range(spine_landmark_data.shape[0]):
    test_z.iloc[row] = spine_landmark_data_z.iloc[row] - spine_landmark_data_z.iloc[row].min()
    test_z.iloc[row] = test_z.iloc[row] / test_z.iloc[row].max()
    
    test_y.iloc[row] = spine_landmark_data_y.iloc[row] - spine_landmark_data_y.iloc[row].min()
    test_y.iloc[row] = test_y.iloc[row] / test_y.iloc[row].max()
    
    test_x.iloc[row] = spine_landmark_data_x.iloc[row] - spine_landmark_data_x.iloc[row].min()
    test_x.iloc[row] = test_x.iloc[row] / test_x.iloc[row].max()

Plots that the above code produces上面代码产生的图

Would the following work?以下会起作用吗?

test_x = spine_landmark_data_x.copy()
test_y = spine_landmark_data_y.copy()
test_z = spine_landmark_data_z.copy()

# Scale each patient z-axis from 0 to 1
for row in range(spine_landmark_data.shape[0]):
    # scaling factor = 1.0 / (patient's z data range)
    scaling_factor = 1.0 / (spine_landmark_data_z.iloc[row].max() - spine_landmark_data_z.iloc[row].min())
    test_z.iloc[row] = (spine_landmark_data_z.iloc[row] - spine_landmark_data_z.iloc[row].min()) * scaling_factor
    test_y.iloc[row] = (spine_landmark_data_y.iloc[row] - spine_landmark_data_y.iloc[row].min()) * scaling_factor
    test_x.iloc[row] = (spine_landmark_data_x.iloc[row] - spine_landmark_data_x.iloc[row].min()) * scaling_factor

It differs only slightly from your existing code in that it scales all axes by the same factor which was used to normalize the z range to [0, 1].它与您现有的代码略有不同,因为它按用于将 z 范围标准化为 [0, 1] 的相同因子缩放所有轴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM