Ejemplo n.º 1
0
MRIdir = '/home/sci/blakez/M15-01/Data/MRI/HARVEY_OSAMA_TOBLAKE/'
MRI_fname = MRIdir + 'T2_MRI.mha'
BFIdir = '/local/blakez/korenbergNAS/3D_database/Working/Blockface/self_registered/M15/'
outdir = '/local/blakez/korenbergNAS/3D_database/Working/Blockface/T2_registered/Thin_plate_spline/M15/'

# for block in [1, 2, 3, 4]:
#     fname = 'block{0}_reg_fillblanks_bw.mha'.format(block)
#     tmp = cc.LoadMHA(BFIdir + fname)
#     cc.WriteGrid(tmp.grid(), BFIdir + 'block{0}_grid.txt'.format(block))
# tmp = cc.LoadMHA(MRI_fname)
# cc.WriteGrid(tmp.grid(), MRIdir + 'T2_grid.txt'.format(block))
# sys.exit()

#BFIgrid = cc.LoadGrid(BFIdir + 'block{0}_grid.txt'.format(block))
#MRIgrid = cc.LoadGrid(MRIdir + 'T2_grid.txt'.format(block))
MRI = cc.LoadMHA(MRI_fname,ca.MEM_HOST)
MRIgrid = MRI.grid()
#MRIgrid = cc.MakeGrid(MRI.size(),MRI.spacing(),'center')
#MRI.setGrid(MRIgrid)
#BFI = cc.LoadMHA(BFIdir + 'M15_01_seg_crop_hd8.mha',ca.MEM_HOST)
BFI_full = cc.LoadMHA(BFIdir + 'M15_01_hd8_VE.mha',ca.MEM_HOST)
BFI = cc.SubVol(BFI_full, yrng=[146,626])
BFIgrid = cc.MakeGrid(ca.Vec3Di(480,480,2239),ca.Vec3Df(0.1185,0.1185,0.030),'center')
BFI.setGrid(BFIgrid)
#BFIgrid = BFI.grid()
print MRIgrid
print BFIgrid
# print 'b4 memory', 480*480*874*4/1024./1024 *7  # 7 blocks, mem size
# print 'mri memory', 256*256*256*4/1024./1024 *7  # 7 blocks, mem size
# print 'mri big memory', 512*512*512*4/1024./1024 *7  # 7 blocks, mem size
# print 'single mri ', 256*256*256*4/1024./1024
Ejemplo n.º 2
0
#else:
#    dir_mri = '/home/sci/crottman/korenberg/results/landmark/'
dir_save = '/home/sci/blakez/results/elast_reg/block1_480/'

SaveInMRICoords = True
MRI_sz = [256]  # list of sizes
SaveInBFICoords = False

SaveRGB = False
SaveVE = False
SaveBW = True
SaveVF = False
debug = False

# load BFI slice and MRI_as_BFI slices
BFI3D = cc.LoadMHA(dir_bf + 'block' + str(block) + 'as_MRI_bw_256.mha',
                   ca.MEM_HOST)  # B/W
MRI3D = cc.LoadMHA(dir_mri + 'T2Seg.mha', ca.MEM_HOST)

# Initialize Deformed 3D Volumes
if SaveRGB:
    BFI_color3D = cc.LoadMHA(dir_bf + 'block' + str(block) + '_reg_rgb.mha',
                             ca.MEM_HOST)
    BFIDef3D_RGB = ca.Field3D(BFI3D.grid(), BFI3D.memType())
    ca.SetMem(BFIDef3D_RGB, 0.0)
if SaveVE:
    BFIDef3D_VE = ca.Image3D(BFI3D.grid(), BFI3D.memType())
    ca.SetMem(BFIDef3D_VE, 0.0)
if SaveBW:
    BFIDef3D_BW = ca.Image3D(BFI3D.grid(), BFI3D.memType())
    ca.SetMem(BFIDef3D_BW, 0.0)
if SaveVF:
Ejemplo n.º 3
0
    mType = ca.MEM_HOST
else:
    mType = ca.MEM_DEVICE

if reg_type is not 'best':
    grid = cc.MakeGrid([sz, sz, sz], [256.0 / sz, 256.0 / sz, 256.0 / sz],
                       'center')
    blocks = ca.Field3D(grid, mType)
    ca.SetMem(blocks, 0.0)
    weights = blocks.copy()
    ca.SetMem(weights, 0.0)

    for i in xrange(1, 5):
        fname = imagedir + 'block' + str(i) + fname_end
        try:
            blk = cc.LoadMHA(fname, mType)
        except IOError:
            print 'Warning... block ' + str(i) + ' does not exist'
            continue
        blocks += blk
        weight3 = blk.copy()
        try:
            weight = cc.LoadMHA(imagedir +
                                'block{0}_as_MRI_weight_{1}.mha'.format(i, sz))
        except IOError:
            print 'Warning, weight block does not exist'
            weight = ca.Image3D(blk.grid(), blk.memType())
            ca.Copy(weight, blk, 0)  # take red
            cc.SetRegionGTE(weight, weight, .1, 1)
        for i in xrange(3):
            ca.Copy(weight3, weight, i)
Ejemplo n.º 4
0
import PyCA.Core as ca
import numpy as np
import sys
import PyCACalebExtras.Common as cc
import PyCACalebExtras.Display as cd
import matplotlib.pyplot as plt
plt.close('all')

block = 3  # 1, 2, 3, 4

dir_in = '/home/sci/crottman/korenberg/results/landmark/'
dir_out = '/home/sci/crottman/korenberg/results/ve_reg/'

Imri = cc.LoadMHA('/home/sci/crottman/korenberg/results/MRI/brain_seg.mha')
cc.SetRegionLT(Imri, Imri, 1.0, 20000)
VEmri = ca.Image3D(Imri.grid(), Imri.memType())
cc.VarianceEqualize(VEmri, Imri, sigma=2.0)

# # load landmark registered blocks
# Ibfi = cc.LoadMHA(dir_in + 'block' + str(block) + '_as_MRI_bw.mha')
# ca.Neg_I(Ibfi)
# VEbfi = ca.Image3D(Imri.grid(), Imri.memType())
# cc.VarianceEqualize(VEbfi, Ibfi, sigma=2.0)
# cd.DispImage(VEbfi, ca.MinMax(VEmri))

# load landmark registered pre-VEd block
VEbfi = cc.LoadMHA(dir_in + 'block' + str(block) + '_as_MRI_ve.mha')
ca.Neg_I(VEbfi)
# cc.WritePNG(VEbfi, 'VEbfi_block' + str(block) + 'new.png', rng = [-2.8, 2.8])
# cd.DispImage(Ibfi)
Ejemplo n.º 5
0
plt.close('all')
import PyCA.Common as common
from PyCAApps import ElastReg, SolveSpline, SplineToHField, DefPoint, IDiff

livedir = '/home/sci/blakez/M15-01/Data/MRI/liveMRI/'
# livedir = '/local/blakez/korenbergNAS/3D_database/Raw/MRI/in_vivo_MRI/M15/HARVEY_IN_VIVO/'
# T2dir = '/home/sci/blakez/M13_01/data/MRI/'
T2dir = '/home/sci/blakez/M15-01/Data/MRI/HARVEY_OSAMA_TOBLAKE/'
ex = 'Korenberg09_MonkeyBrain_Korenberg09_MonkeyBrain_081815_Live_Harv__E16_P1_2.16.756.5.5.100.1654368313.31476.1439925928.1/'
SaveDir = '/home/sci/blakez/M15-01/Results/MRI/invivo_MRI/081815_E16/'

memT = ca.MEM_DEVICE
write = False

# T2 = cc.LoadMHA(T2dir + 'T2Seg_roty-119_flipy.mha',memT)
T2 = cc.LoadMHA(T2dir + 'T2_MRI.mha', memT)
T2_mask = cc.LoadMHA(T2dir + '../M15_01_MRI_Full_Mask.mha', memT)
T2 *= T2_mask
# rotMat = np.load(T2dir + 'rotationMatrix.npy')
# live = cc.LoadMHA(livedir + 'M13_01_live_MRI.mha',memT)
live = cc.LoadMHA(livedir + 'M15_01_live_MRI_E16.mha', memT)
live_mask = cc.LoadNRRD(SaveDir + 'M15_01_live_MRI_mask.nrrd', memT)

live_mask.setOrigin(live.origin())
live -= ca.Min(live)
live /= ca.Max(live)
live *= live_mask

with open(SaveDir + 'M15_01_LiveE16-T2_Landmarks.json', 'r') as f:
    landmarks = json.load(f)
Ejemplo n.º 6
0
    '~/korenbergNAS/3D_database/Working/MRI/Post-Mortem_MRI/Subject_to_Subject/M13/'
)
M15dir = os.path.expanduser(
    '~/korenbergNAS/3D_database/Working/MRI/Post-Mortem_MRI/Subject_to_Subject/M15/'
)

with open(M13dir + 'Affine/M13_01_MRI_affineLandmarks_affineApplied_3.txt',
          'r') as m13:
    m13pts = [[float(v) for v in line.split()] for line in m13]

with open(M15dir + 'Affine/M15_01_MRI_affineLandmarks_3.txt', 'r') as m15:
    m15pts = [[float(v) for v in line.split()] for line in m15]

aff_M13 = np.load(M13dir + 'Affine/rotationMatrix.npy')

M13_aff = cc.LoadMHA(M13dir + 'Affine/T2Seg_roty-119_flipy.mha', memT)
M15 = cc.LoadMHA(M15dir + 'Affine/T2_MRI.mha', memT)
M15_mask = cc.LoadNRRD(
    M15dir + 'Affine/M15_01_MRI_Full_Mask_lessBrainStem.nrrd', memT)
M13_mask = cc.LoadNRRD(
    M13dir + 'Affine/M13_01_MRI_Full_Mask_lessBrainStem.nrrd', memT)

M15_mask.setGrid(M15.grid())
M13_mask.setGrid(M13_aff.grid())

M15 *= M15_mask
M13_aff *= M13_mask

# Points in the M15 were chosen in Flipped Y coordiante system, so flip them back
# for pts in m15pts:
#     pts[0]= 256-pts[0]