分层存储的图片叠层成为3d,并显示。
文件夹D:\mask内的分层存储的图像文件:
1、显示为3d点云:
import open3d as o3d
import numpy as np
from PIL import Image
def convert_images_to_point_cloud(image_paths):
points = []
for i, image_path in enumerate(image_paths):
img = Image.open(image_path)
img_array = np.array(img)
height, width = img_array.shape
for y in range(height):
for x in range(width):
if img_array[y][x] > 0: # 假设非黑色点为感兴趣的点
points.append([x, y, i]) # 将 2D 像素点转换为 3D 点,高度使用索引值
return points
# 替换为你实际存储图像的路径
image_paths = ['D:\\mask\\mask_1.PNG', 'D:\\mask\\mask_2.PNG', 'D:\\mask\\mask_3.PNG', 'D:\\mask\\mask_4.PNG', 'D:\\mask\\mask_5.PNG', 'D:\\mask\\mask_6.PNG', 'D:\\mask\\mask_7.PNG', 'D:\\mask\\mask_8.PNG', 'D:\\mask\\mask_9.PNG', 'D:\\mask\\mask_10.PNG', 'D:\\mask\\mask_11.PNG', 'D:\\mask\\mask_12.PNG']
points = convert_images_to_point_cloud(image_paths)
point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(points)
o3d.visualization.draw_geometries([point_cloud])
2、将点云渲染为体素网格
import open3d as o3d
import numpy as np
from PIL import Image
def convert_images_to_point_cloud(image_paths):
points = []
for i, image_path in enumerate(image_paths):
img = Image.open(image_path)
img_array = np.array(img)
height, width = img_array.shape
for y in range(height):
for x in range(width):
if img_array[y][x] > 0: # 假设非黑色点为感兴趣的点
points.append([x, y, i]) # 将 2D 像素点转换为 3D 点,高度使用索引值
return points
# 替换为你实际存储图像的路径
image_paths = ['D:\\mask\\mask_1.PNG', 'D:\\mask\\mask_2.PNG', 'D:\\mask\\mask_3.PNG', 'D:\\mask\\mask_4.PNG',
'D:\\mask\\mask_5.PNG', 'D:\\mask\\mask_6.PNG', 'D:\\mask\\mask_7.PNG', 'D:\\mask\\mask_8.PNG',
'D:\\mask\\mask_9.PNG', 'D:\\mask\\mask_10.PNG', 'D:\\mask\\mask_11.PNG', 'D:\\mask\\mask_12.PNG']
points = convert_images_to_point_cloud(image_paths)
point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(points)
# 创建点云体素网格
voxel_size = 1
voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(point_cloud, voxel_size=voxel_size)
# 显示体素网格,指定渲染模式为网格
o3d.visualization.draw_geometries([voxel_grid], mesh_show_wireframe=True)
持续更新