-
-
Save mcdlee/b154258dd8a8ec780920d4569dbf84a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
import nibabel as nib | |
import matplotlib.pyplot as plt | |
from matplotlib.colors import LinearSegmentedColormap | |
%matplotlib inline | |
path1 = os.path.join('folder', 'a.img') #path of file 1 | |
img1 = nib.load(path1) | |
dataarray1=img1.get_data() | |
path2 = os.path.join('folder', 'b.img') #path of file 2 | |
img2 = nib.load(path2) | |
dataarray2=img2.get_data() | |
diffarray= dataarray1-dataarray2 #計算兩個的差值 | |
## 以下為視覺化 | |
cdict1 = {'red': ((0.0, 0.0, 1.0), | |
#(0.33, 1.0, 1.0), | |
(0.50, 0.0, 0.0), | |
#(0.67, 1.0, 1.0), | |
(1.0, 0.0, 1.0)), | |
'green': ((0.0, 0.0, 1.0), | |
#(0.33, 1.0, 1.0), | |
(0.50, 0.0, 0.0), | |
#(0.67, 1.0, 1.0), | |
(1.0, 0.0, 0.0)), | |
'blue': ((0.0, 0.0, 0.0), | |
#(0.33, 1.0, 1.0), | |
(0.50, 0.0, 0.0), | |
#(0.67, 1.0, 1.0), | |
(1.0, 1.0, 0.0)) | |
} | |
blue_red1 = LinearSegmentedColormap('BlueRed1', cdict1) | |
plt.register_cmap(name='BlueRed1', data=cdict1) | |
def sagi(array, x): | |
fig, ax = plt.subplots(1) | |
cmap = plt.get_cmap('BlueRed1') | |
im = ax.imshow(array[x,:,:].T, cmap=cmap) | |
cbar= plt.colorbar(im) | |
im.set_clim(-4,4) | |
plt.title(x) | |
plt.gca().invert_xaxis() | |
plt.gca().invert_yaxis() | |
#return fig | |
def coro(array, y): | |
fig, ax = plt.subplots(1) | |
cmap = plt.get_cmap('BlueRed1') | |
im = ax.imshow(array[:,y,:].T, cmap=cmap) | |
cbar= plt.colorbar(im) | |
im.set_clim(-4,4) | |
plt.title(y) | |
plt.gca().invert_xaxis() | |
plt.gca().invert_yaxis() | |
#return fig | |
def axial(array, z): | |
fig, ax = plt.subplots(1) | |
cmap = plt.get_cmap('BlueRed1') | |
im = ax.imshow(array[:,:,z].T, cmap=cmap) | |
cbar= plt.colorbar(im) | |
im.set_clim(-4,4) | |
plt.title(z) | |
plt.gca().invert_xaxis() | |
plt.gca().invert_yaxis() | |
axial(diffarray[:,:,:,0], 35) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment