11import os
2- from glob import glob
2+ from pathlib import Path
33
44import imageio .v3 as imageio
55import h5py
6- import mrcfile
76import napari
8- import numpy as np
97
10- # TODO refactor everything once things are merged
11- ROOT = "/home/ag-wichmann/data/otoferlin/tomograms"
12- if not os .path .exists (ROOT ):
13- ROOT = "./data/tomograms"
14-
15- SEG_ROOT = "./segmentation/v2"
8+ from synapse_net .file_utils import read_mrc
9+ from common import get_all_tomograms , get_seg_path
1610
1711
1812def correct_structure_segmentation (mrc_path ):
19- rel_path = os .path .relpath (mrc_path , ROOT )
20- rel_folder , fname = os .path .split (rel_path )
21- fname = os .path .splitext (fname )[0 ]
22- seg_path = os .path .join (SEG_ROOT , rel_folder , f"{ fname } .h5" )
23-
24- with mrcfile .open (mrc_path , permissive = True ) as mrc :
25- data = np .asarray (mrc .data [:])
26- data = np .flip (data , axis = 1 )
13+ seg_path = get_seg_path (mrc_path )
2714
28- correction_folder = os .path .join (SEG_ROOT , rel_folder , "correction" )
15+ data , _ = read_mrc (mrc_path )
16+ correction_folder = os .path .join (os .path .split (seg_path )[0 ], "correction" )
17+ fname = Path (mrc_path ).stem
2918
3019 names = ("ribbon" , "PD" , "membrane" , "veiscles_postprocessed" )
3120 segmentations = {}
@@ -52,10 +41,7 @@ def correct_structure_segmentation(mrc_path):
5241
5342
5443def main ():
55- tomograms = glob (os .path .join (ROOT , "**" , "*.mrc" ), recursive = True )
56- tomograms += glob (os .path .join (ROOT , "**" , "*.rec" ), recursive = True )
57- tomograms = sorted (tomograms )
58-
44+ tomograms = get_all_tomograms ()
5945 for tomo in tomograms :
6046 correct_structure_segmentation (tomo )
6147
0 commit comments