def test_PREPROCESSOR_patchwisegrid_skipBlanks(self):
     sample_list = self.data_io3D.get_indiceslist()
     pp = Preprocessor(self.data_io3D,
                       data_aug=None,
                       batch_size=1,
                       analysis="patchwise-grid",
                       patch_shape=(4, 4, 4))
     pp.patchwise_skip_blanks = True
     batches = pp.run(sample_list[0:3], training=True, validation=False)
     sample = self.data_io3D.sample_loader(sample_list[0], load_seg=True)
     sample.seg_data = to_categorical(sample.seg_data,
                                      num_classes=sample.classes)
     ready_data = pp.analysis_patchwise_grid(sample,
                                             data_aug=False,
                                             training=True)
     self.assertEqual(len(ready_data), 64)
     self.assertEqual(ready_data[0][0].shape, (4, 4, 4, 1))
     self.assertEqual(ready_data[0][1].shape, (4, 4, 4, 3))
 def test_SUBFUNCTIONS_postprocessing(self):
     ds = dict()
     for i in range(0, 10):
         img = np.random.rand(16, 16, 16) * 255
         img = img.astype(int)
         seg = np.random.rand(16, 16, 16) * 3
         seg = seg.astype(int)
         sample = (img, seg)
         ds["TEST.sample_" + str(i)] = sample
     io_interface = Dictionary_interface(ds, classes=3, three_dim=True)
     self.tmp_dir = tempfile.TemporaryDirectory(prefix="tmp.CESP.")
     tmp_batches = os.path.join(self.tmp_dir.name, "batches")
     dataio = Data_IO(io_interface,
                      input_path="",
                      output_path="",
                      batch_path=tmp_batches,
                      delete_batchDir=False)
     sf = [Resize((9, 9, 9)), Normalization(), Clipping(min=-1.0, max=0.0)]
     pp = Preprocessor(dataio,
                       batch_size=1,
                       prepare_subfunctions=False,
                       analysis="patchwise-grid",
                       subfunctions=sf,
                       patch_shape=(4, 4, 4))
     sample_list = dataio.get_indiceslist()
     for index in sample_list:
         sample = dataio.sample_loader(index)
         for sf in pp.subfunctions:
             sf.preprocessing(sample, training=False)
         pp.cache["shape_" + str(index)] = sample.img_data.shape
         sample.seg_data = np.random.rand(9, 9, 9) * 3
         sample.seg_data = sample.seg_data.astype(int)
         sample.seg_data = to_categorical(sample.seg_data, num_classes=3)
         data_patches = pp.analysis_patchwise_grid(sample,
                                                   training=True,
                                                   data_aug=False)
         seg_list = []
         for i in range(0, len(data_patches)):
             seg_list.append(data_patches[i][1])
         seg = np.stack(seg_list, axis=0)
         self.assertEqual(seg.shape, (27, 4, 4, 4, 3))
         pred = pp.postprocessing(index, seg)
         self.assertEqual(pred.shape, (16, 16, 16))
     self.tmp_dir.cleanup()