How to scale the voxel-dimensions with Matplotlib?

Asked
Active3 hr before
Viewed126 times

7 Answers

scaledimensionsmatplotlibvoxel
90%

These chains of operations are easy to set up using Nilearn and Scipy Python libraries, Here we give clear guidelines about these steps, starting with pre-image operations to post-image operations

Example_snippet/controller/utility/_scale.js/ # cut in x-direction sagittal . . .
# cut in x - direction
sagittal = -25
# cut in y - direction
coronal = -37
# cut in z - direction
axial = -6

# coordinates displaying should be prepared as a list
cut_coords = [sagittal, coronal, axial]
load more v
88%

The following example is a complete program that illustrates some of the basic steps to create grids and write them to disk: , copyToArray has no tolerance argument, because there is no distinction between active and inactive values in the destination array,,Also available if the OpenVDB Python module is compiled with NumPy support (see above) are grid methods to convert polygonal meshes to level sets (see tools::meshToLevelSet for some restrictions) and to convert isosurfaces of scalar-valued grids to meshes

Example_snippet/controller/utility/_scale.js/ PY_OPENVDB_WRAP_ALL_GRID_TYPES. . .
PY_OPENVDB_WRAP_ALL_GRID_TYPES
Step 2 continued with PY_OPENVDB_WRAP_ALL_GRID_TYPES. . .
PY_OPENVDB_WRAP_ALL_GRID_TYPES
Step 3 continued with .vdb. . .
.vdb
load more v
72%

A 3D ndarray of color names, with each item the color for the corresponding voxel, The size must match the voxels

Example_snippet/controller/utility/_scale.js/ lowerBound < upperBound . . .
lowerBound < upperBound
load more v
65%

Scaling (zooming) in three dimensions can be represented by a diagonal 3 by 3 matrix, Here’s how to zoom the first dimension by \(p\), the second by \(q\) and the third by \(r\) units:,The voxel coordinate of the center voxel of the anatomical image is:,What is the voxel coordinate in the anatomical corresponding to the voxel center of the EPI image?,This brings the affine-transformed voxel coordinates to the red box on the figure, matching the position on the localizer

Example_snippet/controller/utility/_scale.js/ >>> import nibabel as nib >>> . . .
>>>
import nibabel as nib
   >>>
   epi_img = nib.load('downloads/someones_epi.nii.gz') >>>
   epi_img_data = epi_img.get_fdata() >>>
   epi_img_data.shape(53, 61, 33)
load more v
75%

Want to scale the voxel-dimensions with Matplotlib, How can I do this?, Stack Overflow Public questions & answers , Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,Instead the voxel on position (1,0,4)

Example_snippet/controller/utility/_scale.js/ import numpy as np import matp. . .
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d
import Axes3D

fig = plt.figure()
ax = fig.gca(projection = '3d')
# Make grid
test2 = np.zeros((6, 6, 6))
# Activate single Voxel
test2[1, 0, 4] = True

# Custom coordinates
for grid
x, y, z = np.indices((7, 7, 7)) / 2

# Pass the custom coordinates as extra arguments
ax.voxels(x, y, z, test2, edgecolor = "k")
ax.set_xlabel('0 - Dim')
ax.set_ylabel('1 - Dim')
ax.set_zlabel('2 - Dim')

plt.show()
load more v
40%

Demonstrates using the x, y, z parameters of Axes3D,voxels

Example_snippet/controller/utility/_dimensions.js/ import matplotlib.pyplot as pl. . .
import matplotlib.pyplot as plt
import matplotlib.colors
import numpy as np

def midpoints(x):
   sl = ()
for i in range(x.ndim):
   x = (x[sl + np.index_exp[: -1]] + x[sl + np.index_exp[1: ]]) / 2.0
sl += np.index_exp[: ]
return x

# prepare some coordinates, and attach rgb values to each
r, theta, z = np.mgrid[0: 1: 11 j, 0: np.pi * 2: 25 j, -0.5: 0.5: 11 j]
x = r * np.cos(theta)
y = r * np.sin(theta)

rc, thetac, zc = midpoints(r), midpoints(theta), midpoints(z)

# define a wobbly torus about[0.7, *, 0]
sphere = (rc - 0.7) ** 2 + (zc + 0.2 * np.cos(thetac * 2)) ** 2 < 0.2 ** 2

# combine the color components
hsv = np.zeros(sphere.shape + (3, ))
hsv[..., 0] = thetac / (np.pi * 2)
hsv[..., 1] = rc
hsv[..., 2] = zc + 0.5
colors = matplotlib.colors.hsv_to_rgb(hsv)

# and plot everything
ax = plt.figure().add_subplot(projection = '3d')
ax.voxels(x, y, z, sphere,
   facecolors = colors,
   edgecolors = np.clip(2 * colors - 0.5, 0, 1), # brighter linewidth = 0.5)

plt.show()
22%

To place the voxels at different positions, see How to scale the voxel-dimensions with Matplotlib?, ,The upcomming matplotlib version 2

Example_snippet/controller/utility/_dimensions.js/ from mpl_toolkits.mplot3d impo. . .
from mpl_toolkits.mplot3d
import Axes3D
import numpy as np
import matplotlib.pyplot as plt
N1 = 10
N2 = 10
N3 = 10
ma = np.random.choice([0, 1], size = (N1, N2, N3), p = [0.99, 0.01])

fig = plt.figure()
ax = fig.gca(projection = '3d')
ax.set_aspect('equal')

ax.voxels(ma, edgecolor = "k")

plt.show()
load more v