Commit b0cb156b authored by sjromuel's avatar sjromuel
Browse files

das

parent 7c9de3a1
Pipeline #185 canceled with stages
FROM tensorflow/tensorflow:2.1.0-py3
RUN pip install SimpleITK
RUN pip install numpy
RUN pip install scikit-image
RUN pip install matplotlib
RUN apt-get update && apt-get install -y git
FROM tensorflow/tensorflow:2.1.0-gpu-py3
RUN pip install SimpleITK
RUN pip install numpy
RUN pip install scikit-image
RUN pip install matplotlib
RUN apt-get update && apt-get install -y git
apiVersion: apps/v1
kind: Deployment
metadata:
name: p9pv-deployment
namespace: romuel
spec:
selector:
matchLabels:
app: pv-pod
template:
metadata:
labels:
app: pv-pod
spec:
containers:
- image: ubuntu:18.04
imagePullPolicy: IfNotPresent
name: ubuntu-container
command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]
resources:
limits:
nvidia.com/gpu: 0
volumeMounts:
- mountPath: home/pv/
name: p9headct
restartPolicy: Always
volumes:
- name: p9headct
persistentVolumeClaim:
claimName: p9headct
apiVersion: batch/v1
kind: Job
metadata:
name: testjobgpu
namespace: romuel
spec:
template:
spec:
containers:
- name: testjobgpu
image: romueller/ma_img:gpu_1.0
command: ["/bin/sh","-c"]
args:
- git clone https://fsstud.is.uni-due.de:8090/sjromuel/masterarbeit.git ./code/
&& cd ./code
&& manualNN/python3 main.py
resources:
limits:
nvidia.com/gpu: 1
volumeMounts:
- mountPath: home/pv/
name: p9headct
volumes:
- name: p9headct
persistentVolumeClaim:
claimName: p9headct
restartPolicy: Never
"""
Script to obtain bone segmentation via thresholding
"""
import os
from glob import glob
import argparse
import SimpleITK as sitk
import pathlib
def segment_bone(args):
lowthresh = [100, 150, 200]
for lt in lowthresh:
input_dir = args.input_dir
dataset = args.dataset
output_dir = args.output_dir
#lt = args.lt
ut = args.ut
print("Input folder: {}".format(input_dir))
print("Output folder: {}".format(output_dir))
print("Lower: {} HU".format(lt))
print("Upper: {} HU".format(ut))
os.makedirs(output_dir, exist_ok=True)
# prepare list of folders
if dataset == 'all':
pattern = os.path.join(input_dir, "*")
folders = sorted(glob(pattern))
else:
folders = [os.path.join(input_dir, dataset)]
# exclude changelog.md
folders = [folder for folder in folders if folder!=os.path.join(input_dir, "changelog.md")]
print("{} elements are found".format(len(folders)))
print("*" * 80)
for folder_path in folders:
folder_name = pathlib.Path(folder_path).name
print(folder_name)
os.makedirs(os.path.join(output_dir, folder_name), exist_ok=True)
print("Loading ct image...")
ct_pattern = os.path.join(folder_path, "*ct*.gipl")
ct_file = glob(ct_pattern)
ct_image = sitk.ReadImage(ct_file[0], sitk.sitkFloat32)
print("-> loaded")
print("Segmenting bone...")
binary_threshold = sitk.BinaryThresholdImageFilter()
binary_threshold.SetLowerThreshold(lt)
binary_threshold.SetUpperThreshold(ut)
binary_threshold.SetInsideValue(1)
binary_threshold.SetOutsideValue(0)
bone_mask = binary_threshold.Execute(ct_image)
bone_mask.SetSpacing(ct_image.GetSpacing())
bone_mask = sitk.Cast(bone_mask, sitk.sitkInt8)
sitk.WriteImage(bone_mask, os.path.join(output_dir, folder_name, "{}_bone_mask".format(folder_name)+ str(lt) + ".gipl".format(folder_name)))
print("-> saved")
print("*" * 80)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--input_dir',
type=str,
default="data/threshIMGs",
help="Root folder. (Default: data/threshIMGs)")
parser.add_argument('--output_dir',
type=str,
default="data/threshIMGs",
help="Output folder. (Default: threshIMGs)")
parser.add_argument('--dataset',
type=str,
default="all",
help="Dataset name [patient_001 | ...| all] (Default: all)")
parser.add_argument('--lt',
type=int,
default=250,
help="Lower threshold value (Default: 250 HU)")
parser.add_argument('--ut',
type=int,
default=3500,
help="Upper threshold value (Default: 3500 HU)")
args = parser.parse_args()
segment_bone(args)
apiVersion: apps/v1
kind: Deployment
metadata:
name: p9pv-deployment
namespace: romuel
spec:
selector:
matchLabels:
app: pv-pod
template:
metadata:
labels:
app: pv-pod
spec:
containers:
- image: ubuntu:18.04
imagePullPolicy: IfNotPresent
name: ubuntu-container
command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]
resources:
limits:
nvidia.com/gpu: 0
volumeMounts:
- mountPath: PycharmProjects/Masterarbeit/data/
name: p9headct
restartPolicy: Always
volumes:
- name: p9headct
persistentVolumeClaim:
claimName: p9headct
apiVersion: batch/v1
kind: Job
metadata:
name: testjob
namespace: romuel
spec:
template:
spec:
containers:
- name: testjob
image: romueller/ma_img:nogpu_1.0
command: ["/bin/sh","-c"]
args:
- git clone https://fsstud.is.uni-due.de:8090/sjromuel/masterarbeit.git ./code/
&& cd ./code
&& python3 manualNN/main.py
resources:
limits:
nvidia.com/gpu: 1
volumeMounts:
- mountPath: PycharmProjects/Masterarbeit/data/
name: headct
volumes:
- name: headct
persistentVolumeClaim:
claimName: headct
restartPolicy: Never
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment