Skip to content

Commit

Permalink
Create get_associated_images.py
Browse files Browse the repository at this point in the history
  • Loading branch information
birm authored Apr 21, 2021
1 parent f1b3852 commit ac30f8c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions get_associated_images.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit ac30f8c

Please sign in to comment.