def test_inverse_mapping(self):
     reader = get_label_reader()
     data_param = MOD_LABEL_DATA
     sampler = GridSampler(reader=reader,
                           data_param=data_param,
                           batch_size=10,
                           spatial_window_size=None,
                           window_border=(3, 4, 5),
                           queue_length=50)
     aggregator = GridSamplesAggregator(
         image_reader=reader,
         name='label',
         output_path=os.path.join('testing_data', 'aggregated'),
         window_border=(3, 4, 5),
         interp_order=0)
     more_batch = True
     with self.test_session() as sess:
         coordinator = tf.train.Coordinator()
         sampler.run_threads(sess, coordinator, num_threads=2)
         while more_batch:
             out = sess.run(sampler.pop_batch_op())
             more_batch = aggregator.decode_batch(
                 out['label'], out['label_location'])
     output_filename = '{}_niftynet_out.nii.gz'.format(
         sampler.reader.get_subject_id(0))
     output_file = os.path.join(
         'testing_data', 'aggregated', output_filename)
     self.assertAllClose(
         nib.load(output_file).shape, [256, 168, 256, 1, 1])
     sampler.close_all()
     output_data = nib.load(output_file).get_data()[..., 0, 0]
     expected_data = nib.load(
         'testing_data/T1_1023_NeuroMorph_Parcellation.nii.gz').get_data()
     self.assertAllClose(output_data, expected_data)
 def test_25d_init(self):
     reader = get_25d_reader()
     sampler = GridSampler(reader=reader,
                           data_param=SINGLE_25D_DATA,
                           batch_size=10,
                           spatial_window_size=None,
                           window_border=(3, 4, 5),
                           queue_length=50)
     aggregator = GridSamplesAggregator(
         image_reader=reader,
         name='image',
         output_path=os.path.join('testing_data', 'aggregated'),
         window_border=(3, 4, 5),
         interp_order=0)
     more_batch = True
     with self.test_session() as sess:
         coordinator = tf.train.Coordinator()
         sampler.run_threads(sess, coordinator, num_threads=2)
         while more_batch:
             out = sess.run(sampler.pop_batch_op())
             more_batch = aggregator.decode_batch(
                 out['image'], out['image_location'])
     output_filename = '{}_niftynet_out.nii.gz'.format(
         sampler.reader.get_subject_id(0))
     output_file = os.path.join('testing_data',
                                'aggregated',
                                output_filename)
     self.assertAllClose(
         nib.load(output_file).shape, [255, 168, 256, 1, 1],
         rtol=1e-03, atol=1e-03)
     sampler.close_all()
 def test_inverse_mapping(self):
     reader = get_label_reader()
     data_param = MOD_LABEL_DATA
     sampler = GridSampler(reader=reader,
                           data_param=data_param,
                           batch_size=10,
                           spatial_window_size=None,
                           window_border=(3, 4, 5),
                           queue_length=50)
     aggregator = GridSamplesAggregator(image_reader=reader,
                                        name='label',
                                        output_path=os.path.join(
                                            'testing_data', 'aggregated'),
                                        window_border=(3, 4, 5),
                                        interp_order=0)
     more_batch = True
     with self.test_session() as sess:
         coordinator = tf.train.Coordinator()
         sampler.run_threads(sess, coordinator, num_threads=2)
         while more_batch:
             out = sess.run(sampler.pop_batch_op())
             more_batch = aggregator.decode_batch(out['label'],
                                                  out['label_location'])
     output_filename = '{}_niftynet_out.nii.gz'.format(
         sampler.reader.get_subject_id(0))
     output_file = os.path.join('testing_data', 'aggregated',
                                output_filename)
     self.assertAllClose(nib.load(output_file).shape, [256, 168, 256, 1, 1])
     sampler.close_all()
     output_data = nib.load(output_file).get_data()[..., 0, 0]
     expected_data = nib.load(
         'testing_data/T1_1023_NeuroMorph_Parcellation.nii.gz').get_data()
     self.assertAllClose(output_data, expected_data)
 def test_25d_init(self):
     reader = get_25d_reader()
     sampler = GridSampler(reader=reader,
                           data_param=SINGLE_25D_DATA,
                           batch_size=10,
                           spatial_window_size=None,
                           window_border=(3, 4, 5),
                           queue_length=50)
     aggregator = GridSamplesAggregator(image_reader=reader,
                                        name='image',
                                        output_path=os.path.join(
                                            'testing_data', 'aggregated'),
                                        window_border=(3, 4, 5),
                                        interp_order=0)
     more_batch = True
     with self.test_session() as sess:
         coordinator = tf.train.Coordinator()
         sampler.run_threads(sess, coordinator, num_threads=2)
         while more_batch:
             out = sess.run(sampler.pop_batch_op())
             more_batch = aggregator.decode_batch(out['image'],
                                                  out['image_location'])
     output_filename = '{}_niftynet_out.nii.gz'.format(
         sampler.reader.get_subject_id(0))
     output_file = os.path.join('testing_data', 'aggregated',
                                output_filename)
     self.assertAllClose(nib.load(output_file).shape, [255, 168, 256, 1, 1],
                         rtol=1e-03,
                         atol=1e-03)
     sampler.close_all()
예제 #5
0
 def test_3d_initialising(self):
     sampler = GridSampler(reader=get_3d_reader(),
                           data_param=MULTI_MOD_DATA,
                           batch_size=10,
                           spatial_window_size=None,
                           window_border=(0, 0, 0),
                           queue_length=10)
     with self.test_session() as sess:
         coordinator = tf.train.Coordinator()
         sampler.run_threads(sess, coordinator, num_threads=2)
         out = sess.run(sampler.pop_batch_op())
         self.assertAllClose(out['image'].shape, (10, 8, 10, 2, 2))
     sampler.close_all()
예제 #6
0
 def test_dynamic_window_initialising(self):
     sampler = GridSampler(reader=get_dynamic_window_reader(),
                           data_param=DYNAMIC_MOD_DATA,
                           batch_size=10,
                           spatial_window_size=None,
                           window_border=(0, 0, 0),
                           queue_length=10)
     with self.test_session() as sess:
         coordinator = tf.train.Coordinator()
         sampler.run_threads(sess, coordinator, num_threads=1)
         out = sess.run(sampler.pop_batch_op())
         self.assertAllClose(out['image'].shape, (10, 8, 2, 256, 2))
     sampler.close_all()
예제 #7
0
 def test_25d_initialising(self):
     sampler = GridSampler(reader=get_3d_reader(),
                           data_param=MULTI_MOD_DATA,
                           batch_size=10,
                           spatial_window_size=(1, 20, 15),
                           window_border=(0, 0, 0),
                           queue_length=10)
     with self.test_session() as sess:
         coordinator = tf.train.Coordinator()
         sampler.run_threads(sess, coordinator, num_threads=2)
         out = sess.run(sampler.pop_batch_op())
         self.assertAllClose(out['image'].shape, (10, 20, 15, 2))
     sampler.close_all()