# File IO¶

This tutorial shows how basic data structures are read and written by Open3D.

## Point cloud¶

The code below reads and writes a point cloud.

[2]:

print("Testing IO for point cloud ...")
sample_pcd_data = o3d.data.PCDPointCloud()
print(pcd)
o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)

Testing IO for point cloud ...
PointCloud with 113662 points.

[2]:

True


By default, Open3D tries to infer the file type by the filename extension. The following point cloud file types are supported:

Format

Description

xyz

Each line contains [x, y, z], where x, y, z are the 3D coordinates

xyzn

Each line contains [x, y, z, nx, ny, nz], where nx, ny, nz are the normals

xyzrgb

Each line contains [x, y, z, r, g, b], where r, g, b are in floats of range [0, 1]

pts

The first line is an integer representing the number of points. The subsequent lines follow one of these formats: [x, y, z, i, r, g, b], [x, y, z, r, g, b], [x, y, z, i] or [x, y, z], where x, y, z, i are of type double and r, g, b are of type uint8

ply

See Polygon File Format, the ply file can contain both point cloud and mesh data

pcd

It’s also possible to specify the file type explicitly. In this case, the file extension will be ignored.

## Mesh¶

The code below reads and writes a mesh.

[3]:

print("Testing IO for meshes ...")
knot_data = o3d.data.KnotMesh()
print(mesh)
o3d.io.write_triangle_mesh("copy_of_knot.ply", mesh)

Testing IO for meshes ...
TriangleMesh with 1440 points and 2880 triangles.

[3]:

True


Compared to the point cloud data structure, a mesh has triangles that define the 3D surface.

By default, Open3D tries to infer the file type by the filename extension. The following mesh file types are supported:

Format

Description

ply

See Polygon File Format, the ply file can contain both point cloud and mesh data

stl

obj

See Object Files

off

gltf/glb

## Image¶

The code below reads and writes an image.

[4]:

print("Testing IO for images ...")
image_data = o3d.data.JuneauImage()
print(img)
o3d.io.write_image("copy_of_Juneau.jpg", img)

Testing IO for images ...

[4]:

True

The size of the image is readily displayed using print(img).
Both jpg and png image files are supported.