def test_save_image_stack_based_on_filename(self): testdatadir = 'test_svimstack2' if os.path.exists(testdatadir): shutil.rmtree(testdatadir, ignore_errors=True) szx = 30 szy = 20 szz = 120 data3d = self.generate_waving_data( szx, szy, szz, value=150, dtype=np.uint8) # import sed3 # ed = sed3.sed3(data3d) # ed.show() # io3d.write(data3d, testdatadir + "/soubory{:04d}.tiff") dr = dreader.DataReader() data3dnew, metadata = dr.Get3DData( testdatadir, dataplus_format=False # 'sample_data/volumetrie/' ) # import sed3 # ed = sed3.sed3(data3dnew) # ed.show() self.assertEqual( np.sum(np.abs(data3d - data3dnew)), 0 ) shutil.rmtree(testdatadir)
def test_save_image_stack_with_unique_series_number_based_on_filename(self): testdatadir = 'test_svimstack2' if os.path.exists(testdatadir): shutil.rmtree(testdatadir, ignore_errors=True) szx = 30 szy = 20 szz = 120 data3d = self.generate_waving_data( szx, szy, szz, value=150, dtype=np.uint8) io3d.write(data3d, testdatadir + "/{series_number:03d}/soubory{slice_position:07.3f}.tiff") # second time there should be directory 002/ io3d.write(data3d, testdatadir + "/{series_number:03d}/soubory{slice_position:07.3f}.tiff") dr = dreader.DataReader() data3dnew, metadata = dr.Get3DData( testdatadir + "/002/", dataplus_format=False # 'sample_data/volumetrie/' ) # import sed3 # ed = sed3.sed3(data3dnew) # ed.show() self.assertEqual( np.sum(np.abs(data3d - data3dnew)), 0 ) shutil.rmtree(testdatadir)
def test_save_image_stack_based_on_filename(self): testdatadir = 'test_svimstack2' if os.path.exists(testdatadir): shutil.rmtree(testdatadir, ignore_errors=True) szx = 30 szy = 20 szz = 120 data3d = self.generate_waving_data( szx, szy, szz, value=150, dtype=np.uint8) # import sed3 # ed = sed3.sed3(data3d) # ed.show() # io3d.write(data3d, testdatadir + "/soubory{:04d}.tiff") dr = dreader.DataReader() data3dnew, metadata = dr.Get3DData( testdatadir, dataplus_format=False # 'sample_data/volumetrie/' ) # import sed3 # ed = sed3.sed3(data3dnew) # ed.show() self.assertEqual( np.sum(np.abs(data3d - data3dnew)), 0 ) shutil.rmtree(testdatadir)
def test_save_image_stack_with_unique_series_number_based_on_filename(self): testdatadir = 'test_svimstack2' if os.path.exists(testdatadir): shutil.rmtree(testdatadir, ignore_errors=True) szx = 30 szy = 20 szz = 120 data3d = self.generate_waving_data( szx, szy, szz, value=150, dtype=np.uint8) io3d.write(data3d, testdatadir + "/{series_number:03d}/soubory{slice_position:07.3f}.tiff") # second time there should be directory 002/ io3d.write(data3d, testdatadir + "/{series_number:03d}/soubory{slice_position:07.3f}.tiff") dr = dreader.DataReader() data3dnew, metadata = dr.Get3DData( testdatadir + "/002/", dataplus_format=False # 'sample_data/volumetrie/' ) # import sed3 # ed = sed3.sed3(data3dnew) # ed.show() self.assertEqual( np.sum(np.abs(data3d - data3dnew)), 0 ) shutil.rmtree(testdatadir)
def test_write_single_dicom(self): filename = 'tests_outputs/single_test_file.dcm' filedir = os.path.dirname(filename) data3d = np.zeros([10,10,10], dtype=np.uint8) data3d [1:, 5, 3:9] = 124 data3d [3:, 2:7, 4] = 60 io3d.write(data3d, filename) os.remove(filename)
def test_write_single_dicom(self): filename = 'tests_outputs/single_test_file.dcm' filedir = os.path.dirname(filename) data3d = np.zeros([10,10,10], dtype=np.uint8) data3d [1:, 5, 3:9] = 124 data3d [3:, 2:7, 4] = 60 io3d.write(data3d, filename) os.remove(filename)
def test_read_mhd_and_write_pklz(self): """ test data on sliver dataset :return: """ infn = op.join(op.expanduser(io3d.datasets.local_dir), "sliver07/training/liver-orig001.mhd") datap = io3d.read(infn, dataplus_format=True) datap["segmentation"] = np.zeros_like(datap["data3d"], dtype=np.uint8) io3d.write(datap, path="test_mhd.pklz")
def test_read_and_write_dataset_to_fix_problem_with_out_of_memory(self): """ voxelsize_mm[0] should be grater than zero """ dcmdir = r"E:\data\medical\orig\ct_porcine_liver\P01\29-8-12-a\MIkroCT-nejhrubsi_rozliseni\DICOM_liver-1st-important_Macro_pixel-size53.0585um" # dcmdir = r"E:\tmp\data\medical\orig\ct_porcine_liver\P01\29-8-12-a\MIkroCT-nejhrubší rozlišení\DICOM_liver-1st-important_Macro_pixel-size53.0585um" # dcmdir = r"E:\data\medical\orig\ct porctine liver\P01\29-8-12-a\Nejlep_rozli_nevycistene" datap = io3d.read(dcmdir) io3d.write(datap, "~/tmp/nejhrubsi.mhd") self.assertGreater(datap["voxelsize_mm"][0], 0)
def test_read_mhd_and_write_pklz(self): """ test data on sliver dataset :return: """ # infn = op.join(op.expanduser(io3d.datasets.local_dir), "sliver07/training/liver-orig001.mhd") infn = io3d.datasets.join_path("liver-orig001.mhd") datap = io3d.read(infn, dataplus_format=True) datap["segmentation"] = np.zeros_like(datap["data3d"], dtype=np.uint8) io3d.write(datap, path="test_mhd.pklz")
def test_read_and_write_dataset_to_fix_problem_with_out_of_memory(self): """ voxelsize_mm[0] should be grater than zero """ dcmdir = r"E:\data\medical\orig\ct_porcine_liver\P01\29-8-12-a\MIkroCT-nejhrubsi_rozliseni\DICOM_liver-1st-important_Macro_pixel-size53.0585um" # dcmdir = r"E:\tmp\data\medical\orig\ct_porcine_liver\P01\29-8-12-a\MIkroCT-nejhrubší rozlišení\DICOM_liver-1st-important_Macro_pixel-size53.0585um" # dcmdir = r"E:\data\medical\orig\ct porctine liver\P01\29-8-12-a\Nejlep_rozli_nevycistene" datap = io3d.read(dcmdir) io3d.write(datap, "~/tmp/nejhrubsi.mhd") self.assertGreater(datap["voxelsize_mm"][0], 0)
def test_io3d(self): import io3d data3d = np.zeros([10, 10, 10]) segmentation = np.zeros([10, 10, 10]) data3d[2:7, :3:5, :6] = 100 datap = { "data3d": data3d, # "segmentation": segmentation, "voxelsize_mm": [1, 1, 1] } io3d.write(datap, "file1.pklz")
def test_save_big_data(self): output_filename = "~/tmp/big_data.mhd" if op.exists(op.expanduser(output_filename)): os.remove(op.expanduser(output_filename)) data3d = np.zeros([1024, 1024, 1024], dtype=np.uint16) voxelsize_mm = [0.5, 0.5, 0.5] datap = dict(data3d=data3d, voxelsize_mm=voxelsize_mm) io3d.write(datap, output_filename) self.assertTrue(op.exists(op.expanduser(output_filename))) # clean if op.exists(op.expanduser(output_filename)): os.remove(op.expanduser(output_filename))
def test_save_big_data(self): output_filename = "~/tmp/big_data.mhd" if op.exists(op.expanduser(output_filename)): os.remove(op.expanduser(output_filename)) data3d = np.zeros([1024, 1024, 1024], dtype=np.uint16) voxelsize_mm = [0.5, 0.5, 0.5] datap = dict(data3d=data3d, voxelsize_mm=voxelsize_mm) io3d.write(datap, output_filename) self.assertTrue(op.exists(op.expanduser(output_filename))) # clean if op.exists(op.expanduser(output_filename)): os.remove(op.expanduser(output_filename))
def saveVolumeToFile(self, filename="output{:06d}.jpg"): if self.data3d is None: self.generate_volume() # self.tvgvol.saveToFile(filename) import io3d import io3d.misc import numpy as np data = { 'data3d': self.data3d.astype(np.uint8), #* self.output_intensity, 'voxelsize_mm': self.voxelsize_mm, # 'segmentation': np.zeros_like(self.data3d, dtype=np.int8) } io3d.write(data, filename)
def test_synthetic_volumetric_data_generation(): """ Generovani umeleho stromu do 3D a jeho evaluace. V testu dochazi ke kontrole predpokladaneho objemu a deky cev """ # from skelet3d.tree import TreeGenerator # from fibrous.tree import TubeSkeletonBuilder as TreeGenerator # from fibrous.tree import TreeBuilder as TreeGenerator from fibrous.tb_volume import TBVolume as TreeGenerator # print("zacatek podezreleho testu") # import segmentation # import misc # generate 3d data from yaml for testing tvg = TreeGenerator() yaml_path = os.path.join(path_to_script, "./hist_stats_test.yaml") tvg.importFromYaml(yaml_path) tvg.set_area_sampling(voxelsize_mm=[1, 1, 1], shape=[100, 101, 102]) # tvg.voxelsize_mm = [1, 1, 1] # tvg.shape = [100, 100, 100] # data3d = tvg.generateTree() data3d = tvg.buildTree() assert data3d.shape[0] == 100 assert data3d.shape[1] == 101 assert data3d.shape[2] == 102 # plt.imshow(data3d[:,:,50]) # plt.colorbar() # plt.show() io3d.write(data3d.astype(np.uint8), path="./slice{:04d}.jpg") # self.assertEqual(data3d.shape[0], 100) # self.assertEqual(data3d.shape[1], 101) # self.assertEqual(data3d.shape[2], 102) tvg = TreeGenerator() yaml_path = os.path.join(path_to_script, "./hist_stats_test.yaml") tvg.importFromYaml(yaml_path) tvg.set_area_sampling(voxelsize_mm=[0.5, 0.5, 0.5], shape=[100, 101, 102]) io3d.write(data3d.astype(np.uint8), path="./ssslice{:04d}.jpg")
def save(self, outputfile, filetype='pklz'): import io3d import io3d.misc import numpy as np data = { 'data3d': self.data3d.astype(np.uint8), # * self.output_intensity, 'voxelsize_mm': self.voxelsize_mm, # 'segmentation': np.zeros_like(self.data3d, dtype=np.int8) } # data3d = np.zeros([10,10,10]) # segmentation = np.zeros([10,10,10]) # # data3d [2:7,:3:5, :6] = 100 # datap = { # "data3d": data3d, # "segmentation": segmentation, # "voxelsize_mm": [1,1,1] # } # io3d.write(datap, "file1.pklz") # import ipdb; ipdb.set_trace() io3d.write(data, outputfile)
parser = argparse.ArgumentParser(description='Registration data from different files') parser.add_argument('-d', '--debug', action='store_true', help='run in debug mode') parser.add_argument('-i', '--inputfile', default=None, nargs="N", help='input file or directory with data') parser.add_argument('-o', '--outpufile', default=None, help='output file or directory with data') args = parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) for fn in args.inputfile: datap = io3d.read(fn) # pyed = sed3.sed3(datap['data3d'], contour=datap['segmentation'] == datap['slab']['porta']) # pyed.show() #pyed = sed3.sed3(data['segmentation']) #pyed.show() # Uvolneni pameti if args.outputfile == None: io3d.write(datap_out, args.outpufile)
def main(): #logger = logging.getLogger(__name__) logger = logging.getLogger() logger.setLevel(logging.WARNING) ch = logging.StreamHandler() logger.addHandler(ch) #logger.debug('input params') # input parser parser = argparse.ArgumentParser(description= 'Segmentation of bones, lungs and heart.') parser.add_argument('-i','--datadir', default=None, help='path to data dir') parser.add_argument('-o','--output', default=None, help='output file') parser.add_argument('-d', '--debug', action='store_true', help='run in debug mode') parser.add_argument('-ss', '--segspine', action='store_true', help='run spine segmentaiton') parser.add_argument('-sb', '--segbody', action='store_true', help='run body segmentaiton') parser.add_argument('-exd', '--exampledata', action='store_true', help='run unittest') parser.add_argument('-so', '--show_output', action='store_true', help='Show output data in viewer') args = parser.parse_args() if args.debug: logger.setLevel(logging.DEBUG) if args.exampledata: args.dcmdir = '../sample_data/liver-orig001.raw' # if dcmdir == None: #else: #dcm_read_from_dir('/home/mjirik/data/medical/data_orig/46328096/') #data3d, metadata = dcmr.dcm_read_from_dir(args.dcmdir) import io3d data3d , metadata = io3d.datareader.read(args.datadir) bn = BodyNavigation(data3d = data3d, voxelsize_mm = metadata['voxelsize_mm'], ) seg = np.zeros(data3d.shape, dtype=np.int8) #sseg.orientation() if args.segspine: seg += bn.get_spine() if args.segspine: seg += bn.get_body() #print ("Data size: " + str(data3d.nbytes) + ', shape: ' + str(data3d.shape) ) #igc = pycut.ImageGraphCut(data3d, zoom = 0.5) #igc.interactivity() #igc.make_gc() #igc.show_segmentation() # volume #volume_mm3 = np.sum(oseg.segmentation > 0) * np.prod(oseg.voxelsize_mm) #pyed = sed3.sed3(oseg.data3d, contour = oseg.segmentation) #pyed.show() if args.show_output: import sed3 sed3.show_slices(data3d, contour=seg) #savestring = raw_input ('Save output data? (y/n): ') #sn = int(snstring) if args.output is not None: # savestring in ['Y','y']: md = { 'voxelsize_mm': metadata['voxelsize_mm'], 'segmentation': seg, } io3d.write(data3d, args.output, metadata=md)
nObj=1, biggestObjects=args.biggest, # dataFiltering = True, interactivity=True, binaryClosingIterations=2, binaryOpeningIterations=0) datap['slab']['none'] = 0 datap['slab']['liver'] = 1 datap['slab']['porta'] = 2 #print np.max(output) #import pdb; pdb.set_trace() #data = {} #data['data3d'] = oseg.data3d #data['crinfo'] = oseg.crinfo #data['segmentation'] = oseg.segmentation datap['segmentation'][output] = datap['slab']['porta'] #data['slab'] = slab pyed = sed3.sed3(datap['data3d'], contour=datap['segmentation'] == datap['slab']['porta']) pyed.show() #pyed = sed3.sed3(data['segmentation']) #pyed.show() # Uvolneni pameti if args.outputfile == None: io3d.write(datap, args.outpufile)