print ca.MinMax(weights) ca.Div_I(blocks, weights) else: # best imagedir = '/home/sci/crottman/korenberg/results/' blocks = cc.LoadMHA( imagedir + 'BFI_2D_Reg/block1_as_MRI_' + col + '_256.mha', ca.MEM_HOST) blk = cc.LoadMHA(imagedir + 'BFI_2D_Reg/block2_as_MRI_' + col + '_256.mha', ca.MEM_HOST) blocks += blk blk = cc.LoadMHA(imagedir + 'landmark/block3_as_MRI_' + col + '.mha', ca.MEM_HOST) blocks += blk blk = cc.LoadMHA(imagedir + 'landmark/block4_as_MRI_' + col + '.mha', ca.MEM_HOST) blocks += blk imagedir = '/home/sci/crottman/korenberg/results/best/' # Save Blocks maxval = ca.MinMax(blocks)[1] blocks /= maxval fname_out = imagedir + 'blocks' + fname_end cc.WriteMHA(blocks, fname_out) if col == 'rgb': fname_out = imagedir + 'blocks_as_MRI_rgba_' + str(sz) + '.mha' cc.WriteColorMHA(blocks, fname_out)
BFIfname = 'block{0}_reg_fillblanks_{1}_hd4.mha'.format(block, color) # BFI = cc.LoadMHA(BFIdir + BFIfname, mType) # outimage = common.ExtractSliceIm(BFI,100) cd.Disp3Pane(BFI_aff) if color in ['bw', 've', 'weight']: BFIdef = ca.ManagedImage3D(MRIgrid, mType) # these should be small enough else: BFIdef = ca.ManagedField3D(MRIgrid, mType) cc.ApplyHReal(BFIdef, BFI_aff, h) if sz == MRIsizes[-1] and color == colors[-1]: cd.Disp3Pane(BFIdef) # write data if Write: if color == 'rgb': fname = 'block{0}_as_MRI_rgba_{1}.mha'.format(block, sz) cc.WriteColorMHA(BFIdef, outdir + fname) fname = 'block{0}_as_MRI_rgb_{1}.mha'.format(block, sz) cc.WriteMHA(BFIdef, outdir + fname) else: #fname = 'block{0}_as_MRI_{1}_{2}_NEWLANDMARKS.mha'.format(block, color, sz) fname = 'M15_01_to_MRI_TPS_bw_256_VE.mha' cc.WriteMHA(BFIdef, outdir + fname) cc.WriteMHA(h, outdir + 'M15_01_to_MRI_TPS_def_256.mha') # cc.WriteMHA(h, outdir + 'block{0}_TPS_HField_{1}.mha'.format(block,sz)) cd.Disp3Pane(BFIdef) common.DebugHere() del BFIdef, BFI del h
def Fragmenter(): tmpOb = Config.Load( frgSpec, pth.expanduser( '~/korenbergNAS/3D_database/Working/configuration_files/SidescapeRelateBlockface/M{0}/section_{1}/section_{1}_frag0.yaml' .format(secOb.mkyNum, secOb.secNum))) dictBuild = {} #Load in the whole image so that the fragment can cropped out ssiSrc, bfiSrc, ssiMsk, bfiMsk = Loader(tmpOb, ca.MEM_HOST) #Because some of the functions only woth with gray images bfiGry = ca.Image3D(bfiSrc.grid(), bfiSrc.memType()) ca.Copy(bfiGry, bfiSrc, 1) lblSsi, _ = ndimage.label(np.squeeze(ssiMsk.asnp()) > 0) lblBfi, _ = ndimage.label(np.squeeze(bfiMsk.asnp()) > 0) seedPt = np.squeeze(pp.LandmarkPicker([lblBfi, lblSsi])) subMskBfi = common.ImFromNPArr(lblBfi == lblBfi[seedPt[0, 0], seedPt[0, 1]].astype('int8'), sp=bfiSrc.spacing(), orig=bfiSrc.origin()) subMskSsi = common.ImFromNPArr(lblSsi == lblSsi[seedPt[1, 0], seedPt[1, 1]].astype('int8'), sp=ssiSrc.spacing(), orig=ssiSrc.origin()) bfiGry *= subMskBfi bfiSrc *= subMskBfi ssiSrc *= subMskSsi #Pick points that are the bounding box of the desired subvolume corners = np.array( pp.LandmarkPicker( [np.squeeze(bfiGry.asnp()), np.squeeze(ssiSrc.asnp())])) bfiCds = corners[:, 0] ssiCds = corners[:, 1] #Extract the region from the source images bfiRgn = cc.SubVol(bfiSrc, xrng=[bfiCds[0, 0], bfiCds[1, 0]], yrng=[bfiCds[0, 1], bfiCds[1, 1]]) ssiRgn = cc.SubVol(ssiSrc, xrng=[ssiCds[0, 0], ssiCds[1, 0]], yrng=[ssiCds[0, 1], ssiCds[1, 1]]) #Extract the region from the mask images rgnMskSsi = cc.SubVol(subMskSsi, xrng=[ssiCds[0, 0], ssiCds[1, 0]], yrng=[ssiCds[0, 1], ssiCds[1, 1]]) rgnMskBfi = cc.SubVol(subMskBfi, xrng=[bfiCds[0, 0], bfiCds[1, 0]], yrng=[bfiCds[0, 1], bfiCds[1, 1]]) dictBuild['rgnBfi'] = np.divide( bfiCds, np.array(bfiSrc.size().tolist()[0:2], 'float')).tolist() dictBuild['rgnSsi'] = np.divide( ssiCds, np.array(ssiSrc.size().tolist()[0:2], 'float')).tolist() #Check the output directory for the source files of the fragment if not pth.exists( pth.expanduser(secOb.ssiSrcPath + 'frag{0}'.format(frgNum))): os.mkdir(pth.expanduser(secOb.ssiSrcPath + 'frag{0}'.format(frgNum))) if not pth.exists( pth.expanduser(secOb.bfiSrcPath + 'frag{0}'.format(frgNum))): os.mkdir(pth.expanduser(secOb.bfiSrcPath + 'frag{0}'.format(frgNum))) #Check the output directory for the mask files of the fragment if not pth.exists( pth.expanduser(secOb.ssiMskPath + 'frag{0}'.format(frgNum))): os.mkdir(pth.expanduser(secOb.ssiMskPath + 'frag{0}'.format(frgNum))) if not pth.exists( pth.expanduser(secOb.bfiMskPath + 'frag{0}'.format(frgNum))): os.mkdir(pth.expanduser(secOb.bfiMskPath + 'frag{0}'.format(frgNum))) dictBuild[ 'ssiSrcName'] = 'frag{0}/M{1}_01_ssi_section_{2}_frag1.tif'.format( frgNum, secOb.mkyNum, secOb.secNum) dictBuild[ 'bfiSrcName'] = 'frag{0}/M{1}_01_bfi_section_{2}_frag1.mha'.format( frgNum, secOb.mkyNum, secOb.secNum) dictBuild[ 'ssiMskName'] = 'frag{0}/M{1}_01_ssi_section_{2}_frag1_mask.tif'.format( frgNum, secOb.mkyNum, secOb.secNum) dictBuild[ 'bfiMskName'] = 'frag{0}/M{1}_01_bfi_section_{2}_frag1_mask.tif'.format( frgNum, secOb.mkyNum, secOb.secNum) #Write out the masked and cropped images so that they can be loaded from the YAML file #The BFI region needs to be saved as color and mha format so that the grid information is carried over. common.SaveITKImage( ssiRgn, pth.expanduser(secOb.ssiSrcPath + dictBuild['ssiSrcName'])) cc.WriteColorMHA( bfiRgn, pth.expanduser(secOb.bfiSrcPath + dictBuild['bfiSrcName'])) common.SaveITKImage( rgnMskSsi, pth.expanduser(secOb.ssiMskPath + dictBuild['ssiMskName'])) common.SaveITKImage( rgnMskBfi, pth.expanduser(secOb.bfiMskPath + dictBuild['bfiMskName'])) frgOb = Config.MkConfig(dictBuild, frgSpec) updateFragOb(frgOb) return None