官术网_书友最值得收藏!

Loading and visualizing a 3D image

The 3D ShapeNets dataset contains Computer-aided design (CAD) models of different object categories, which are in the .mat file format. We will convert these .mat files to NumPy ndarrays. We will also visualize a 3D image to get a visual understanding of the dataset.

Execute the following code to load a 3D image from a .mat file:

  1. Use the loadmat() function from scipy to retrieve the voxels. The code is as follows:
import scipy.io as io
voxels = io.loadmat("path to .mat file")['instance']
  1. The shape of the loaded 3D image is 30x30x30. Our network requires images of shape 64x64x64. We will use NumPy's pad() method to increase the size of the 3D image to 32x32x32:
import numpy as np
voxels = np.pad(voxels, (1, 1), 'constant', constant_values=(0, 0))

The pad() method takes four parameters, which are the ndarray of the actual voxels, the number of values that need to be padded to the edges of each axes, the mode values (constant), and the constant_values that are to be padded. 

  1. Then, use the zoom() function from the scipy.ndimage module to convert the 3D image to a 3D image with dimensions of 64x64x64
import scipy.ndimage as nd
voxels = nd.zoom(voxels, (2, 2, 2), mode='constant', order=0)

Our network requires images to be shaped 64x64x64, which is why we converted our 3D images to this shape.

主站蜘蛛池模板: 尉氏县| 台北市| 万州区| 延长县| 泾源县| 砚山县| 盐城市| 华安县| 隆林| 五常市| 资溪县| 潢川县| 平定县| 石门县| 枞阳县| 南昌市| 孟津县| 明溪县| 家居| 康乐县| 安西县| 临桂县| 乐平市| 灵武市| 莲花县| 广元市| 龙胜| 凤翔县| 六盘水市| 修武县| 龙山县| 宾阳县| 剑阁县| 思南县| 白银市| 乌兰浩特市| 井研县| 漳州市| 喀喇| 陕西省| 凤庆县|