diff --git a/SlideServer.py b/SlideServer.py index 0e02a3a..81b0efa 100644 --- a/SlideServer.py +++ b/SlideServer.py @@ -35,6 +35,10 @@ # dataset storage location for the workbench tasks app.config['DATASET_FOLDER'] = "/images/dataset/" +#creating a uploading folder if it doesn't exist +if not os.path.exists('/images/uploading/'): + os.mkdir('/images/uploading') + # where to put and get slides app.config['UPLOAD_FOLDER'] = "/images/" app.config['TEMP_FOLDER'] = "/images/uploading/" diff --git a/get_associated_images.py b/get_associated_images.py new file mode 100644 index 0000000..c19c197 --- /dev/null +++ b/get_associated_images.py @@ -0,0 +1,33 @@ +import openslide +import os + +dir = "./PDACG/images/" +out_dir = "./PDACG/images/associated/" + +for fn in os.listdir(dir): + if fn.endswith(".svs"): + try: + img = openslide.OpenSlide(dir + fn) + except: + print("[ERR]", fn) + continue + img_rgba = img.associated_images; + if "macro" in img_rgba: + macro_rgb = img_rgba["macro"].convert("RGB"); + if "label" in img_rgba: + label_rgb = img_rgba["label"].convert("RGB"); + if "thumbnail" in img_rgba: + thumb_rgb = img_rgba["thumbnail"].convert("RGB"); + else: + thumb_rgb = img.get_thumbnail((img_w,img_h)).convert("RGB"); + fname_pre = out_dir + "/" + os.path.splitext(fn)[0]; + if macro_rgb is not None: + fname_out = fname_pre + "-macro.jpg"; + macro_rgb.save(fname_out); + if label_rgb is not None: + fname_out = fname_pre + "-label.jpg"; + label_rgb.save(fname_out); + if thumb_rgb is not None: + fname_out = fname_pre + "-thumb.jpg"; + thumb_rgb.save(fname_out); + print("[OK]", fn)