Browse Source

Update 'automatic_segmentation_program/runner.py'

Frederik Filip Stæger 4 years ago
parent
commit
3f99a6fc46
1 changed files with 5 additions and 7 deletions
  1. 5 7
      automatic_segmentation_program/runner.py

+ 5 - 7
automatic_segmentation_program/runner.py

@@ -68,14 +68,10 @@ def apply_transform(segmentation, fixed, index, out_dir, temporary_directory):
     return post_transform_loc
 
 def generate_segmentation(slice_path, segment_path, template_path, approx_index, dapi, output_directory):     
-        
+    tools.create_dir(output_directory)
+
     if slice_path.endswith('.tiff') or slice_path.endswith('.tif'):
         Image.MAX_IMAGE_PIXELS = None
-        #  tif_image = Image.open(slice_path)
-        #  ch_nm = (list(tif_image.tag_v2[270].split('='))[2])
-        #  if int(ch_nm[0]) < dapi:
-        #      print(f'DAPI channel out of range, max range is {ch_nm[0]} channels')
-        #      sys.exit()
         tif_path = preprocess.tiff_to_nii(slice_path, output_directory)
         slice_path = tif_path[0]
     elif not slice_path.endswith(".nii"):
@@ -84,15 +80,17 @@ def generate_segmentation(slice_path, segment_path, template_path, approx_index,
         
     out_subdir = Path(output_directory) / Path(slice_path).stem.replace(' ', '_').replace(',','_').replace('.','')
     tools.create_dir(out_subdir)
-    temporary_directory = Path(output_directory) / Path(out_subdir) / 'tmp'
+    temporary_directory = Path(out_subdir) / 'tmp'
     tools.create_dir(temporary_directory)
     channel_paths = preprocess.split_nii_channels(slice_path, out_subdir, True, dapi-1)
     optimal_index = find_optimal_index(channel_paths[dapi-1], template_path, approx_index, temporary_directory)
     seg_loc = apply_transform(segment_path, channel_paths[dapi-1], optimal_index, out_subdir, temporary_directory)
+    
     tools.remove_dir(temporary_directory)
     os.remove(Path(out_subdir) / 'segment_slice.nii')
     os.rename(Path(out_subdir) / 'TemplateSlice_Composite.h5', Path(out_subdir) / 'Transformation_Composite.h5')
     os.rename(Path(out_subdir) / 'TemplateSlice_InverseComposite.h5', Path(out_subdir) / 'Transformation_InverseComposite.h5')
+    
     return seg_loc
 
 if __name__ == "__main__":