读Shape-Guided代码①预处理

有时候debug就会爆编码错还是加个前缀保险吧,但其实还是要稍等一会刷个新更好

# -*- coding: UTF-8 -*-

preprocessing预处理

首先遍历所有tiff路径读取点云数据、rgb图像,以及可能有的gt掩码图像
例如首先读到的是babel测试集combined
第一组中,点云pc是800,800,3的ndarray,rgb同样大小,gt就是800,800的灰度图
在Win10查看tiff属性的话,它是400*400,dpi300,分辨率单位2。所以可能就是利用那个分辨率单位做了什么“分辨率缩放”

去除平面 remove_plane

mvt_util.organized_pc_to_unorganized_pc方法将结构的点云数据转换为非j结构形式的点云数据。这是因为后续进行平面拟合和点到平面距离计算时,更适合操作非j结构形式的点云数据。

其实就是变成了640000,3
pc和rgb都这样
各自拷贝一份前缀planeless

结构pc送去提取边缘点(看起来就是各种拼接、reshape)得到25236,3
这个临时的非结构pc通过open3d包做成Vector3dVector这种点云数据结构
然后使用同样是open3d里的segment_plane方法进行平面拟合。这个方法基于RANSAC(随机抽样一致性)算法,能够从点云数据中鲁棒地估计出最佳拟合平面的参数。

segment_plane方法的主要参数包括:
distance_threshold:点到拟合平面的最大距离阈值,超过此阈值的点将被视为离群点。
ransac_n:每次迭代中,用于拟合平面的随机点数。
num_iterations:RANSAC算法的迭代次数。
返回平面模型:最终,segment_plane方法返回拟合的平面模型和内点索引。平面模型是一个包含四个元素的元组(a, b, c, d),对应于平面方程ax + by + cz + d = 0的参数。这个函数仅返回平面模型,即平面的参数。

所以plane_model就是一个4元素的ndarray
造一个640000,1的全1ndarray,让planeless的pc和它拼接并转置成4,640000
再让plane_model与它相乘后取绝对值得到640000元素的ndarray distances
筛选得到小于0.005阈值的索引indices 307652长,把这些planeless_pc和planeless_rgb的这些位置都赋值0
然后再把planeless_pc这个非结构的,reshape成结构的planeless_pc 800,800,3;把planeless_rgb这个非结构的,reshape成结构的planeless_rgb 800,800,3

pad_cropped_pc

对上面输出的这两个结构化的planeless,rgb和pc分别处理

上下左右四个方向常数0填充,使其高度和宽度都扩展到向上取整最接近的100的倍数,并保证结果是一个正方形

如果有gt那么就对一开始那个结构化gt也同样处理(但其实当前例子正好就是正方形,所以还是800,800,3)

connected_components_cleaning

这个函数用于对点云进行聚类并清除离群的点云组件。

首先还是对pc和rgb结构化变无结构640000,3
找出pc中所有非零点(即有效的点云数据点),由此转成o3d点云数据结构。

使用点云数据结构的cluster_dbscan方法对非零点云进行DBSCAN聚类,这是一种基于密度的聚类算法,可以将紧密连接的点云组成一个簇,而将噪声点或离群点分开。(这一部分运行还挺慢的)
cluster_dbscan产生的标签labels用于识别每个点属于哪个簇,或者是否被视为噪声(标签为-1)。
然后,它找出最大的簇(即包含最多点的簇)max_label,并将不属于这个簇的所有点(离群点)outlier_indices_nonzero_array,在原始的无组织点云和RGB数据中设置为0(清除)。
最后,函数将清理后的无组织点云和RGB数据重新塑形为有组织的形式,并返回这两个有组织的数组。这个过程可以用于去除点云数据中的噪声或非关联的对象,只保留最主要的组件。(还是800,800,3)

点云文件image_path中识别出的聚类数量,即max_label + 1(因为标签从0开始计数)。
每个聚类的唯一标识符(unique_cluster_ids)和对应的聚类大小(cluster_size),即每个聚类中包含的点数。
如果max_label大于0,即至少存在一个有效的聚类(不考虑噪声),则会打印如下格式的信息:

##########################################################################
Point cloud file [image_path] has [X] clusters
Cluster ids: [unique_cluster_ids]. Cluster size [cluster_size]
##########################################################################

这里,[image_path]将被实际的点云文件路径替换,[X]是聚类的数量,[unique_cluster_ids]是聚类的ID数组,[cluster_size]是每个聚类中点的数量数组。这些信息有助于了解点云数据的聚类结构,例如,哪些聚类较大,可能表示点云中较为显著的区域。

最后,使用tifffile.imsave和Image.fromarray将处理后的3D点云数据和RGB图像覆盖保存(就很狗,所以最好有个备份😂)

在这里插入图片描述

这是原本的tiff,dpi是300,分辨率单位2,所以还是很方便转成png展示在这里的

在这里插入图片描述

这是去背景之后的tiff,明明ndarray是800,800,3,但是tiff.imsave保存后的结果在属性里显示400*400分辨率像素,1dpi,分辨率单位1,这我就不明白这个尺寸了。而且除了默认看图软件外都很难把它展示成400*400的图片

/home/pengpeng/.conda/envs/myenv/bin/python3.6 /media/pengpeng/新加卷/Shape-Guided/pre.py 
Found 4147 tiff files in /media/pengpeng/新加卷/mvtec3d/new
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/combined/xyz/003.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 206020     32]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/combined/xyz/007.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [206526     39]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/combined/xyz/014.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    13  13122 213424]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/contamination/xyz/000.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [205139   2341]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/contamination/xyz/004.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     3 211682     50]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/contamination/xyz/012.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 225481     38]
##########################################################################


Processed 50 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/crack/xyz/021.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     2 199416     40]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/good/xyz/010.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 203508     34]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/good/xyz/013.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [213799     69]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/hole/xyz/010.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 206167    552]
##########################################################################


Processed 100 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/hole/xyz/011.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    12 222570     45]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/hole/xyz/012.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     4 219567     63]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/hole/xyz/013.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    18 227852    443]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/test/hole/xyz/014.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    22 224220    785]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/013.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [     1 221867     72     41]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/015.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [217954     32]
##########################################################################


Processed 150 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/156.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 227465    298]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/073.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [     2 219204     34     51]
##########################################################################


Processed 200 tiff files...



Processed 250 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/055.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 207675     78]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/218.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [203718    151]
##########################################################################


Processed 300 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/175.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     6 206389     61]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/185.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [212987     55]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/226.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     4 201810     40]
##########################################################################


Processed 350 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/240.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 200673    434]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/242.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 201334     41]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/bagel/train/good/xyz/243.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 204116     29]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/test/bent/xyz/003.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    4 23547    86]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/test/bent/xyz/007.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    3 23493    73]
##########################################################################


Processed 400 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/test/good/xyz/013.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    3 23760    55]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/test/hole/xyz/009.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [22575   188]
##########################################################################


Processed 450 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/test/hole/xyz/012.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    2 23431    42]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/train/good/xyz/003.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    7 22939   176]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/train/good/xyz/006.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [23157   269]
##########################################################################


Processed 500 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/train/good/xyz/020.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    1 22506   187]
##########################################################################


Processed 550 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/train/good/xyz/077.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    1 23748    30]
##########################################################################


Processed 600 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/train/good/xyz/053.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    3 24171    30]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/train/good/xyz/061.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    1 23753    49]
##########################################################################


Processed 650 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/cable_gland/train/good/xyz/214.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    1 22201   219]
##########################################################################


Processed 700 tiff files...
Processed 750 tiff files...
Processed 800 tiff files...
Processed 850 tiff files...
Processed 900 tiff files...
Processed 950 tiff files...
Processed 1000 tiff files...
Processed 1050 tiff files...
Processed 1100 tiff files...
Processed 1150 tiff files...
Processed 1200 tiff files...
Processed 1250 tiff files...
Processed 1300 tiff files...
Processed 1350 tiff files...
Processed 1400 tiff files...
Processed 1450 tiff files...
Processed 1500 tiff files...
Processed 1550 tiff files...
Processed 1600 tiff files...
Processed 1650 tiff files...
Processed 1700 tiff files...
Processed 1750 tiff files...
Processed 1800 tiff files...
Processed 1850 tiff files...
Processed 1900 tiff files...
Processed 1950 tiff files...
Processed 2000 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/test/color/xyz/017.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 274817   5440]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/test/combined/xyz/008.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     5 253481   2727]
##########################################################################


Processed 2050 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/test/combined/xyz/011.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     8 257374   2282]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/test/combined/xyz/012.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     8 254942   3168]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/test/contamination/xyz/011.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     6 246402   1936]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/test/contamination/xyz/014.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     9 253090   2919]
##########################################################################


Processed 2100 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/008.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     2 244941   3382]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/023.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     7 252297   2487]
##########################################################################


Processed 2150 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/128.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     5 264907   2040]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/183.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     2 270944   2984]
##########################################################################


Processed 2200 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/194.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [256299   2441]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/199.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    11 261248   2744]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/064.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     6 251426   2825]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/067.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 254515   2215]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/071.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     2 254204   3155]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/080.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     6 260741   3082]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/088.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     2 263473   4258]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/215.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     5 261543   2622]
##########################################################################


Processed 2250 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/220.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     6 260723   2527]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/052.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    10 265414   2555]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/057.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    16 253671   2392]
##########################################################################


Processed 2300 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/147.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     1 256272   1999]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/train/good/xyz/170.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     4 260229   3187]
##########################################################################


Processed 2350 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/validation/good/xyz/002.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     4 266861   5839]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/validation/good/xyz/012.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     4 260262   2489]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/foam/validation/good/xyz/018.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [     3 249500   3072]
##########################################################################


Processed 2400 tiff files...
Processed 2450 tiff files...
Processed 2500 tiff files...
Processed 2550 tiff files...
Processed 2600 tiff files...
Processed 2650 tiff files...
Processed 2700 tiff files...
Processed 2750 tiff files...
Processed 2800 tiff files...
Processed 2850 tiff files...
Processed 2900 tiff files...
Processed 2950 tiff files...
Processed 3000 tiff files...
Processed 3050 tiff files...
Processed 3100 tiff files...
Processed 3150 tiff files...
Processed 3200 tiff files...
Processed 3250 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/potato/train/good/xyz/023.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [86053    32]
##########################################################################


Processed 3300 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/potato/train/good/xyz/219.tiff has 2 clusters
Cluster ids: [0 1]. Cluster size [33007    53]
##########################################################################


Processed 3350 tiff files...
Processed 3400 tiff files...
Processed 3450 tiff files...
Processed 3500 tiff files...
Processed 3550 tiff files...
Processed 3600 tiff files...
Processed 3650 tiff files...
Processed 3700 tiff files...
Processed 3750 tiff files...
Processed 3800 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/combined/xyz/004.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   10 91716   133]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/004.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   23 93012    96    56]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/005.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   44 92235    78]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/006.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   56 93648    53]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/009.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    4 92028   131]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/015.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   12 93095   142]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/022.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   11 93831    41   171]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/023.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   45 93585    56]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/024.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   20 93845    84]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/contamination/xyz/027.tiff has 5 clusters
Cluster ids: [-1  0  1  2  3  4]. Cluster size [   23   747 91238   247    82    31]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/cut/xyz/001.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   20 94650    44]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/cut/xyz/018.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   22 93483   173]
##########################################################################


Processed 3850 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/cut/xyz/023.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   36 92027   107    69]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/cut/xyz/026.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   29 92991    31]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/000.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   45 94127    45]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/003.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   39 93946    51]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/007.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   24 93576    37    64]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/008.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   17 92877    31]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/013.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   13 93758    89]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/014.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   30 93502    53]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/015.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   22 92844    38]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/016.tiff has 5 clusters
Cluster ids: [-1  0  1  2  3  4]. Cluster size [   30 92701    73   121   256   141]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/021.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    8 92976   108]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/good/xyz/022.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   20 92175    77]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/hole/xyz/000.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   24 92756    82]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/hole/xyz/009.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   10 91056   115]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/hole/xyz/010.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   23 91627    88]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/hole/xyz/014.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   19 94489    58]
##########################################################################


Processed 3900 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/test/hole/xyz/020.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    5 94777   209]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/003.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   25 92696    34]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/004.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   31 93221    47]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/008.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   13 92341    79]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/009.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   28 92398    78]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/011.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   34 93645   154]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/014.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   36 93631    63]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/018.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   31 93837    36]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/022.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   10 92084    86]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/030.tiff has 4 clusters
Cluster ids: [-1  0  1  2  3]. Cluster size [   73 91207    41    76   136]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/033.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   11 92421   105]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/113.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   38 91951    45]
##########################################################################


Processed 3950 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/125.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   10 92314    36    48]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/127.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   15 94648   135]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/132.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   17 93806    32]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/135.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   34 92996    46    49]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/164.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    4 94527    95]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/170.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   21 93353   236]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/176.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   21 93789   101]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/180.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   17 93029    36]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/065.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   26 92758    35]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/067.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   30 93927    60]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/068.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   29 92002   116]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/071.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   13 92533    47]
##########################################################################


Processed 4000 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/073.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   89 91352    36]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/074.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   34 91259    99   165]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/075.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   56 92806    74]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/076.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   33 93188    43]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/077.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   38 93820    37]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/078.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   14   225 92542]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/081.tiff has 4 clusters
Cluster ids: [-1  0  1  2  3]. Cluster size [   99 92119   112    51    33]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/084.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   29 92164    39]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/038.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   49 92793    65]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/045.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   27 89705    83    38]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/046.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   27 89503    52]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/047.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   33 90782    42]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/048.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   22 90757   107]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/049.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   16 91732   152]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/050.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   31 91597   186]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/052.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   18 92892    30]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/054.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [    8 92239   102]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/058.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   10 93975    52]
##########################################################################


Processed 4050 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/140.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   28 90025    63    93]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/145.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   20 91759   208]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/149.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   12 93986   220]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/154.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   16 93265    58]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/156.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   16 93867   259]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/158.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   27 90371    37]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/161.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   24 91361   225]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/090.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   57 91877    62]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/100.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   23 94049    54]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/103.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   28   141 91380]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/104.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   17 92852    34    35]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/105.tiff has 4 clusters
Cluster ids: [-1  0  1  2  3]. Cluster size [   61 91870    44    87    55]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/106.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   23 93023    67]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/111.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   53 91093    55]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/189.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   54 93809    67]
##########################################################################


Processed 4100 tiff files...
##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/201.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   16 93341    85]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/train/good/xyz/203.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   43 93012    39]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/validation/good/xyz/003.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   12 94106   171]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/validation/good/xyz/005.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   23 93886   127   111]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/validation/good/xyz/006.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   28 94202    49]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/validation/good/xyz/010.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   28 93595    46]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/validation/good/xyz/011.tiff has 3 clusters
Cluster ids: [-1  0  1  2]. Cluster size [   24 94756    38    31]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/validation/good/xyz/019.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   54 92975    51]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/validation/good/xyz/026.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   22 92722   163]
##########################################################################


##########################################################################
Point cloud file /media/pengpeng/新加卷/mvtec3d/new/tire/validation/good/xyz/028.tiff has 2 clusters
Cluster ids: [-1  0  1]. Cluster size [   23 92879    43]
##########################################################################



Process finished with exit code 0

cut_patches

输入参数

  • image_size: 设置图像的大小,默认为224。
  • point_num: 每个patch包含的点数,默认为500。
  • datasets_path: 上一步预处理后的MVTec 3D-AD数据集的路径。
  • save_grid_path: 保存patches的路径。
  • pretrain: 如果设置,将会为预训练数据切割patches。默认为False
  • group_mul: 用于计算patch数量的乘数,默认为10。patch的数量等于(group_mul * points)/ point_num。
  • sample_num: 预训练时随机采样噪声点的数量,默认为20。

然后每个类别分别处理train、test、validation

get_data_loader

对于预训练、train都是直接glob得到所有tiff路径然后sort
而对于test和validation却要先listdir把所有缺陷类型列出来,然后再遍历每种类型搞glob,那直接glob不也可以吗???还剩点循环复杂度吧。。。
读取结构化pc 800,800,3
permute成1,3,800,800的tensor后nearest插值到1,3,224,224-》3,224,224
再改成224,224,3的ndarray后,再搞成无结构的50176,3
检查非0点得到7140,3 points及其索引org_idx_table
然后对这个points均匀归一化,也就是xyz每个维度上减去最小值、除以极差

但是这里的极差都是用的第一个维度上的,明明减去的最小值都是各自维度的

pointcloud_s_t = pointcloud_s_t / np.array([
    np.max(pointcloud_s[:,0]) - np.min(pointcloud_s[:,0]), 
    np.max(pointcloud_s[:,0]) - np.min(pointcloud_s[:,0]), 
    np.max(pointcloud_s[:,0]) - np.min(pointcloud_s[:,0])
])
num_group = round(pointcloud_s.shape[0] * GROUP_MUL / GROUP_SIZE)   # num_group:number of knn groups.

其中GROUP_MUL是参数group_mul 10;GROUP_SIZE是参数points_num 500。从而得到143

再把7140,3 points搞成1,7140,3的tensor

sample_and_group

从输入的点云中采样出小的局部区域,并将这些区域的点聚合起来,捕捉局部结构信息
输入参数:

  • xyz: 输入点的位置数据,形状为 [B, N, 3],其中B是批次大小,N是每个批次中的点数,3代表点的x, y, z坐标。就是points 1,7140,3
  • npoint: 需要采样的点(也称为质心或关键点)的数量,这些点用于建立局部区域。 143
  • nsample: 每个局部区域中采样点的数量。 500
  • org_idx_table: 原始点云的索引表,用于从采样索引映射回原始点云的索引。
  • radius: 用于球查询的半径,在这个函数中未直接使用,可能在query_ball_point中用于确定局部邻域的范围。默认0.5
  • knn: 一个布尔值,指示是否使用k最近邻方法来确定每个质心的局部邻域。默认True
farthest_point_sample

远点采样(Farthest Point Sampling, FPS)算法,它是一种在点云中选择点以最大化它们之间的最小距离的方法。这种方法在点云处理中特别有用,因为它可以减少点的数量而保持点云的结构特征。FPS常用于减少点云数据的复杂性和后续处理的计算负担。

  1. 初始化:
  • 选择一个随机点作为第一个最远点。
  • 初始化一个距离向量,存储所有点到最近的已选点的距离。
  • 初始化一个质心向量,用于存储选定的最远点的索引。
  1. 迭代选择最远点:
  • 对于每次迭代,选择当前距离向量中距离最远的点作为新的最远点,并加入到质心向量中。
  • 更新距离向量:对于每个点,计算它到新质心的欧式距离,如果这个距离小于当前存储的距离,则更新该点的距离。
  1. 重复上述过程直到选取了npoint个最远点。1,143

然后就根据上面这个最远点索引从1,7140,3中找出new_xyz 1,143,3作为质心坐标
knn为真,所以计算new_xyz中每个点与xyz中所有点之间的距离,然后对每个质心找到最近的nsample个点索引idx(也就是距离排序后的前nsample)。
将这个采样点的索引idx根据org_idx_table映射回原始点云的索引org_idx_all
再在原始点云中索引idx得到grouped_xyz,表示采样出的局部区域的点的坐标 1,143,500,3

再对grouped_xyz和org_idx_all压缩分别得到143,500,3和143,500-》71500,

np.savez(save_path, points_gt=grouped_xyz, points_idx=org_idx_all)

这样的键值对把两个东西保存到npz

$ python cut_patches.py --datasets_path /media/pengpeng/新加卷/mvtec3d --save_grid_path data/
1.10.1+cu102
Start to cut patches
Cutting patches of train-data for class bagel: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 244/244 [04:01<00:00,  1.01it/s]
Cutting patches of test-data for class bagel: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 110/110 [01:49<00:00,  1.00it/s]
Cutting patches of validation-data for class bagel: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [00:23<00:00,  1.08s/it]
Cutting patches of train-data for class cable_gland: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 223/223 [01:09<00:00,  3.23it/s]
Cutting patches of test-data for class cable_gland: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 108/108 [00:34<00:00,  3.09it/s]
Cutting patches of validation-data for class cable_gland: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 23/23 [00:07<00:00,  3.20it/s]
Cutting patches of train-data for class carrot: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 286/286 [00:42<00:00,  6.70it/s]
Cutting patches of test-data for class carrot: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 159/159 [00:21<00:00,  7.43it/s]
Cutting patches of validation-data for class carrot: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 29/29 [00:06<00:00,  4.43it/s]
Cutting patches of train-data for class cookie: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 210/210 [03:36<00:00,  1.03s/it]
Cutting patches of test-data for class cookie: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 131/131 [02:15<00:00,  1.04s/it]
Cutting patches of validation-data for class cookie: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [00:22<00:00,  1.03s/it]
Cutting patches of train-data for class dowel: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 288/288 [00:37<00:00,  7.76it/s]
Cutting patches of test-data for class dowel: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 130/130 [00:22<00:00,  5.88it/s]
Cutting patches of validation-data for class dowel: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 34/34 [00:04<00:00,  7.68it/s]
Cutting patches of train-data for class foam: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 236/236 [03:57<00:00,  1.00s/it]
Cutting patches of test-data for class foam: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [01:33<00:00,  1.07it/s]
Cutting patches of validation-data for class foam: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 27/27 [00:26<00:00,  1.03it/s]
Cutting patches of train-data for class peach: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 361/361 [02:48<00:00,  2.14it/s]
Cutting patches of test-data for class peach: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 132/132 [01:06<00:00,  1.99it/s]
Cutting patches of validation-data for class peach: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 42/42 [00:20<00:00,  2.02it/s]
Cutting patches of train-data for class potato: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 300/300 [01:04<00:00,  4.69it/s]
Cutting patches of test-data for class potato: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 114/114 [00:27<00:00,  4.21it/s]
Cutting patches of validation-data for class potato: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 33/33 [00:06<00:00,  5.47it/s]
Cutting patches of train-data for class rope: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 298/298 [00:50<00:00,  5.90it/s]
Cutting patches of test-data for class rope: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 101/101 [00:14<00:00,  7.20it/s]
Cutting patches of validation-data for class rope: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 33/33 [00:04<00:00,  6.98it/s]
Cutting patches of train-data for class tire: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 210/210 [01:15<00:00,  2.78it/s]
Cutting patches of test-data for class tire: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 112/112 [00:39<00:00,  2.86it/s]
Cutting patches of validation-data for class tire: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 29/29 [00:09<00:00,  2.95it/s]

All patches are saved to the grid_path: data/
  • 12
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值