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

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.

主站蜘蛛池模板: 五家渠市| 交口县| 巍山| 东宁县| 静海县| 都匀市| 新津县| 临漳县| 巫溪县| 肃宁县| 自治县| 乐清市| 渝中区| 大理市| 平泉县| 宣汉县| 香河县| 舟山市| 大荔县| 平顺县| 临海市| 德昌县| 陆良县| 西丰县| 巨鹿县| 望奎县| 如皋市| 衢州市| 济南市| 桃江县| 榕江县| 岳普湖县| 金塔县| 平舆县| 社旗县| 扬中市| 汤原县| 军事| 鹤山市| 婺源县| 吴堡县|