In [1]:
from numpy import fft
import scipy.io as io
from matplotlib import pyplot
import copy
import ipywidgets as ipw
In [2]:
# function for drawing two images next to each other:
def kSpaceFFT(kSpace):
"Transform a matlab s-space matrix into an image"
return fft.fftshift(fft.ifft2(fft.ifftshift(kSpace)))
def show2(img1, img2):
"draw two images next to each other"
pyplot.close()
pyplot.figure(figsize=(50,50))
pyplot.set_cmap(pyplot.gray())
# draw k-space
ax = pyplot.subplot(1,2,1)
ax.imshow(abs(img1))
ax = pyplot.subplot(1,2,2)
ax.imshow(abs(img2))
pyplot.show()
def trimSpace(first_row,step_size):
kSpaceOrig = kSpace[first_row::step_size,:]
print(kSpaceOrig.shape)
img = kSpaceFFT(kSpaceOrig)
show2(kSpaceOrig, img)
In [3]:
# load data:
data = io.loadmat('k_space_3T_body_res.mat')
kSpace = data['k_space_3T_body_res']
img = kSpaceFFT(kSpace)
ipw.interact(trimSpace, first_row=(1,3,1), step_size=(1,4,1));
In [4]:
def draw_kspace_lineV(x):
kSpaceTmp = kSpace.copy()
kSpaceTmp[x,:] = kSpace.max()
kSpaceTmp[img.shape[1]-x,:] = kSpace.max()/2 # just for the symmetry
imgTmp = kSpaceFFT(kSpaceTmp)
show2(kSpaceTmp, imgTmp)
ipw.interact(draw_kspace_lineV, x=(0,int(img.shape[1]/2),10));
In [5]:
def blockSpace(x,y,size):
kSpaceTmp = kSpace.copy()
kSpaceTmp[x:x+size,y:y+size] = kSpace.max()
# ignoring the symmetry
imgTmp = kSpaceFFT(kSpaceTmp)
show2(kSpaceTmp, imgTmp)
ipw.interact(blockSpace, x=(0,int(img.shape[1]),10), y=(0,int(img.shape[0]*2),10), size=(1,50,1));
In [6]:
kSpaceTmp = kSpace.copy()
kSpaceTmp[500:524,1000:1048] = kSpace.max()
# ignoring the symmetry
imgTmp = kSpaceFFT(kSpaceTmp)
show2(kSpaceTmp, imgTmp)