def test_preprocessing(self, input_path):
        pre = DataPreProcessing3D([input_path], input_type="data_uint8", output_type="data_uint8",
                                  save_directory="PreProcessing", filter_type="gaussian", filter_param=1.0)

        # run preprocessing
        output_paths = pre()

        # assert output path correctness
        basepath, basename = os.path.split(input_path)
        assert output_paths[0] == os.path.join(basepath, "PreProcessing", basename)
Esempio n. 2
0
    def test_preprocessing_voxel_size(self, input_path):
        with h5py.File(input_path, 'r') as f:
            expected_voxel_size = f['raw'].attrs['element_size_um']

        pre = DataPreProcessing3D([input_path], input_type="data_uint8", output_type="data_uint8")
        # run preprocessing
        output_paths = pre()

        # check output voxel_size
        with h5py.File(output_paths[0], 'r') as f:
            voxel_size = f['raw'].attrs['element_size_um']

        assert np.array_equal(np.array(expected_voxel_size), np.array(voxel_size))
Esempio n. 3
0
    def test_preprocessing_default_voxel_size(self, tmpdir):
        path = os.path.join(tmpdir, 'test.h5')
        # create a new file without element_size_um
        with h5py.File(path, 'w') as f:
            f.create_dataset('raw', data=np.random.rand(32, 128, 128))

        pre = DataPreProcessing3D([path], input_type="data_uint8", output_type="data_uint8")
        # run preprocessing
        output_paths = pre()

        # check output voxel_size
        with h5py.File(output_paths[0], 'r') as f:
            voxel_size = f['raw'].attrs['element_size_um']

        assert np.array_equal((1, 1, 1), voxel_size)
Esempio n. 4
0
    def test_preprocessing_crop(self, input_path):
        with h5py.File(input_path, 'r') as f:
            raw = f['raw'][...]

        target_shape = (raw.shape[0], 32, 32)
        pre = DataPreProcessing3D([input_path], input_type="data_uint8", output_type="data_uint8",
                                  save_directory="PreProcessing", filter_type=None, filter_param=None,
                                  crop='[:, :32, :32]')

        output_paths = pre()

        with h5py.File(output_paths[0], 'r') as f:
            raw = f['raw'][...]

        assert raw.shape == target_shape
Esempio n. 5
0
    def test_tiff_voxel_size(self, input_path):
        """
        Take input h5, convert to tiff, convert to h5, check if the voxel size matches the original
        """
        # convert to h5 to tiff
        post = DataPostProcessing3D([input_path], input_type="labels", output_type="labels", out_ext='.tiff')
        output_paths = post()
        # convert tiff to h5
        pre = DataPreProcessing3D(output_paths, input_type="labels", output_type="labels")
        output_paths = pre()

        # check output voxel_size
        with h5py.File(input_path, 'r') as f:
            expected_voxel_size = f['raw'].attrs['element_size_um']

        with h5py.File(output_paths[0], 'r') as f:
            voxel_size = f['raw'].attrs['element_size_um']

        assert np.array_equal(expected_voxel_size, voxel_size)
Esempio n. 6
0
def configure_preprocessing_step(input_paths, config):
    output_type = config.get('output_type', "data_uint8")
    save_directory = config.get('save_directory', 'PreProcessing')
    factor = config.get('factor', [1, 1, 1])

    filter_type = None
    filter_param = None
    if config["filter"]["state"]:
        filter_type = config["filter"]["type"]
        filter_param = config["filter"]["param"]

    state = config.get('state', True)
    return DataPreProcessing3D(input_paths,
                               input_type="data_float32",
                               output_type=output_type,
                               save_directory=save_directory,
                               factor=factor,
                               filter_type=filter_type,
                               filter_param=filter_param,
                               state=state)