read_image函数是open3d.io模块中用于读取图像文件的函数。它将支持的图像格式(如png、jpg、bmp、tga等)的文件读入为Open3D中的open3d.geometry.Image类型。
open3d.io.read_image(filename)
filename:要读取的图像文件的完整文件路径。open3d.geometry.Image类型的对象,包含从文件中读取的图像。
import open3d as o3d
# 读取图像文件为Open3D的Image对象
image = o3d.io.read_image("path/to/image.jpg")
# 查看Image对象的属性
print("Image width:", image.width)
print("Image height:", image.height)
print("Number of channels:", image.num_of_channels)
FileNotFoundError:指定的文件不存在或找不到。ValueError:指定的文件无法解析为支持的图像格式。read_image函数的返回值是Open3D中的open3d.geometry.Image类型的对象。要访问图像的属性,可以使用width、height和num_of_channels属性。可以通过get_data()方法以NumPy数组的形式访问图像的原始数据。
import open3d as o3d
import numpy as np
# 读取图像文件为Open3D的Image对象
image = o3d.io.read_image("path/to/image.jpg")
# 访问图像数据并打印出前5个像素值
data = np.asarray(image.get_data())
print("First 5 pixels:", data[:5])