Esempio n. 1
0
def DispImage(im, title=None,
              sliceIdx=None, dim='z',
              cmap='gray', newFig=True,
              rng=None, t=False, log=False):

    # if this volume is not a slice already, extract a slice
    sz = im.size().tolist()
    if sz[common.DIMMAP[dim]] > 1:
        im = common.ExtractSliceIm(im, sliceIdx, dim)
        im.toType(core.MEM_HOST)

    # transfer to host memory if necessary
    if im.memType() == core.MEM_DEVICE:
        tmp = core.Image3D(im.grid(), core.MEM_HOST)
        core.Copy(tmp, im)
        im = tmp
        
    # create the figure if requested
    if newFig:
        if title is None:
            plt.figure()
        else:
            plt.figure(title)
        plt.clf()
            
    # set the range
    if rng is None:
        vmin = None
        vmax = None
    else:
        vmin = rng[0]
        vmax = rng[1]

    if log:
        norm = matplotlib.colors.LogNorm(vmin=vmin, vmax=vmax)
    else:
        norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax)

    # convert to numpy array
    arr = np.squeeze(im.asnp().copy())

    # transpose if requested
    if t:
        arr = arr.T

    # display
    plt.imshow(arr, cmap=cmap, vmin=vmin, vmax=vmax, norm=norm, interpolation='nearest')
    plt.axis('tight')
    plt.axis('image')
    if title is not None:
        plt.title(title)
    plt.xticks([])
    plt.yticks([])
    plt.draw()
Esempio n. 2
0
def SaveSlice(fname, im, sliceIdx=None, dim='z',
              cmap='gray', rng=None, t=True):
    sliceIm = common.ExtractSliceIm(im, sliceIdx, dim)
    sliceIm.toType(core.MEM_HOST)
    if rng is None:
        vmin = None
        vmax = None
    else:
        vmin = rng[0]
        vmax = rng[1]
    if t:
        plt.imsave(fname, np.squeeze(sliceIm.asnp()).T,
                   cmap=cmap, vmin=vmin, vmax=vmax)
    else:
        plt.imsave(fname, np.squeeze(sliceIm.asnp()),
                   cmap=cmap, vmin=vmin, vmax=vmax)
Esempio n. 3
0
def ExtractSliceFunc(IDef, t):
    sliceIm = common.ExtractSliceIm(IDef)
    return sliceIm
Esempio n. 4
0
    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:
    BFIDef3D_VF = ca.Image3D(BFI3D.grid(), BFI3D.memType())
    ca.SetMem(BFIDef3D_VF, 0.0)

# Initialize the 2D slices
BFI = common.ExtractSliceIm(BFI3D, 0)
BFI.toType(ca.MEM_DEVICE)
BFI.setOrigin(ca.Vec3Df(0, 0, 0))
print BFI.grid()
grid2D = BFI.grid().copy()
if SaveRGB:
    BFI_def_RGB = ca.Field3D(grid2D, BFI.memType())
    ca.SetMem(BFI_def_RGB, 0.0)
if SaveVE:
    BFI_def_VE = ca.Image3D(grid2D, BFI.memType())
    ca.SetMem(BFI_def_VE, 0.0)
if SaveBW:
    BFI_def_BW = ca.Image3D(grid2D, BFI.memType())
    ca.SetMem(BFI_def_BW, 0.0)

for sliceIdx in xrange(BFI3D.grid().size().z):