-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from j-frei/master
Switch from HTTP to HTTPS
- Loading branch information
Showing
5 changed files
with
117 additions
and
4 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ click | |
tinydb | ||
m2r | ||
sphinxcontrib-googleanalytics | ||
pyOpenSSL |
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 |
---|---|---|
|
@@ -15,5 +15,6 @@ | |
'requests', | ||
'click', | ||
'tinydb', | ||
'pyOpenSSL', | ||
], | ||
) |
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,50 @@ | ||
import sys, os | ||
# We need to add "tomaat"-directory (../..) to PATH to import the tomaat package | ||
sys.path.append( os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))) | ||
|
||
from tomaat.server import TomaatService, TomaatApp | ||
|
||
import SimpleITK as sitk | ||
import numpy as np | ||
|
||
config = { | ||
"name": "Example TOMAAT thresholding app", | ||
"modality": "Example Modality", | ||
"task": "Example Task", | ||
"anatomy": "Example Anatomy", | ||
"description":"Example Description", | ||
"port": 9001, | ||
"announce": False, | ||
"api_key": "", | ||
} | ||
|
||
iface_in = [{'type':'volume','destination':'images'}] | ||
iface_out = [{'type':'LabelVolume','field':'images'}] | ||
|
||
def preprocess(input): | ||
return {'images':[sitk.ReadImage(input['images'][0])] } | ||
|
||
def inference(data): | ||
itk_image = data['images'][0] | ||
image_data = sitk.GetArrayFromImage(itk_image) | ||
treshold = np.mean(image_data) | ||
image_binary = image_data >= treshold | ||
return { | ||
'image_data': image_binary, | ||
'image_old': itk_image, | ||
} | ||
|
||
def postprocess(output): | ||
binarized_image = output['image_data'].astype(np.float) | ||
image_new = sitk.GetImageFromArray(binarized_image) | ||
image_new.CopyInformation(output['image_old']) | ||
return { | ||
'images':[image_new] | ||
} | ||
|
||
|
||
my_app = TomaatApp(preprocess,inference,postprocess) | ||
|
||
my_service = TomaatService(config, my_app, iface_in, iface_out) | ||
|
||
my_service.run() |
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,36 @@ | ||
from OpenSSL import crypto, SSL | ||
from socket import gethostname | ||
from pprint import pprint | ||
from time import gmtime, mktime | ||
from os.path import exists | ||
|
||
def create_self_signed_cert(CERT_FILE = "./tomaat.crt",KEY_FILE = "./tomaat.key"): | ||
if not exists(CERT_FILE) or not exists(KEY_FILE): | ||
# create a key pair | ||
k = crypto.PKey() | ||
k.generate_key(crypto.TYPE_RSA, 4096) | ||
|
||
# create a self-signed cert | ||
cert = crypto.X509() | ||
cert.get_subject().C = "US" | ||
cert.get_subject().ST = "TOMAAT" | ||
cert.get_subject().L = "TOMAAT" | ||
cert.get_subject().O = "TOMAAT" | ||
cert.get_subject().OU = "TOMAAT" | ||
cert.get_subject().CN = "*" | ||
cert.set_serial_number(1000) | ||
cert.gmtime_adj_notBefore(0) | ||
cert.gmtime_adj_notAfter(10*365*24*60*60) | ||
cert.set_issuer(cert.get_subject()) | ||
cert.set_pubkey(k) | ||
cert.sign(k, 'sha256') | ||
cert.sign(k, 'sha1') | ||
|
||
# write keys | ||
with open(CERT_FILE, "wb") as f: | ||
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert)) | ||
with open(KEY_FILE, "wb") as f: | ||
f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k)) | ||
|
||
if __name__ == "__main__": | ||
create_self_signed_cert(".") |
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