-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import compileall | ||
|
||
compileall.compile_dir("/app/", force=True,legacy=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import sys | ||
import SimpleITK as sitk | ||
import numpy as np | ||
import torch | ||
from caller import call | ||
import os | ||
import glob | ||
from percentageLungTissues.percentageLungTissues import * | ||
|
||
species_dict = {"human":"human_org", | ||
"mice":"mice_TL", | ||
"macaque":"mix_no_TL_a_mac"} | ||
|
||
|
||
def ReadImage(path : str, image_extension =".mhd"): | ||
|
||
def read_dicom(path): | ||
reader = sitk.ImageSeriesReader() | ||
dicom_names = reader.GetGDCMSeriesFileNames(path) | ||
reader.SetFileNames(dicom_names) | ||
return reader.Execute() | ||
|
||
|
||
if image_extension == ".mhd": | ||
image = sitk.ReadImage(path) | ||
elif image_extension == ".dcm" or image_extension == "": | ||
image = read_dicom(path) | ||
|
||
return image | ||
|
||
|
||
images_folder = "/app/Images" | ||
results_folder = "/app/Results" | ||
|
||
biological_species=sys.argv[1].lower() | ||
|
||
if len(sys.argv) <= 2: | ||
model = species_dict["human"] | ||
else: | ||
if "human" in biological_species: | ||
model = species_dict["human"] | ||
|
||
elif ("mouse" or "mice") in biological_species: | ||
model = species_dict["mice"] | ||
|
||
elif "nhp" or "macaque" or "monkey" in biological_species: | ||
model = species_dict["macaque"] | ||
|
||
else: | ||
print("Unknown species:", biological_species) | ||
print("Species must be one of the following:") | ||
for k in species_dict.keys(): | ||
print(" -",k) | ||
sys.exit("Choose a correct one!") | ||
|
||
|
||
|
||
images_path = glob.glob(images_folder + "/*.mhd") | ||
|
||
for path in images_path: | ||
name = os.path.split(path)[1] | ||
image_extension = os.path.splitext(path)[1] | ||
|
||
image = ReadImage(path,image_extension) | ||
|
||
mask = call.apply(image,model) | ||
|
||
seg = sitk.GetImageFromArray(mask) | ||
|
||
sitk.WriteImage(seg, os.path.join(results_folder, 'Res_' + name)) | ||
|
||
getPercentageLungTissues(images_folder,results_folder) |