NiPyとmatplotlibで、脳機能画像のアニメーション
NiPyとmatplotlibで、脳機能画像のアニメーションを作っていきます。
Axial画像
import nipy import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation def input_files(data_path): img = nipy.load_image(data_path) data = img.get_data() return img, data #(x,y,z,t)の4D-NIfTIファイル img, data = input_files(data_path) fig = plt.figure() ims = [] for i in range(data.shape[2]): im = plt.imshow(data[:, :, i, 1].T, cmap='gray', animated=True) plt.gca().invert_yaxis() ims.append([im]) ani = animation.ArtistAnimation(fig, ims, interval=100) ani.save('Axial.gif' ,writer = 'imagemagick')
Saggital画像
import nipy import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation def input_files(data_path): img = nipy.load_image(data_path) data = img.get_data() return img, data #(x,y,z,t)の4D-NIfTIファイル img, data = input_files(data_path) fig = plt.figure() ims = [] for i in range(data.shape[0]): im = plt.imshow(data[i, :, : , 1].T, cmap='gray', animated=True) plt.gca().invert_yaxis() ims.append([im]) ani = animation.ArtistAnimation(fig, ims, interval=100) ani.save('Saggital.gif' ,writer = 'imagemagick')
Coronal画像
import nipy import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation def input_files(data_path): img = nipy.load_image(data_path) data = img.get_data() return img, data #(x,y,z,t)の4D-NIfTIファイル img, data = input_files(data_path) fig = plt.figure() ims = [] for i in range(data.shape[1]): im = plt.imshow(data[:, i, : , 1].T, cmap='gray', animated=True) plt.gca().invert_yaxis() ims.append([im]) ani = animation.ArtistAnimation(fig, ims, interval=100) ani.save('Coronal.gif' ,writer = 'imagemagick')