-
Notifications
You must be signed in to change notification settings - Fork 22
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 #13 from camicroscope/release
For 3.1.0
- Loading branch information
Showing
2 changed files
with
19 additions
and
23 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
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 |
---|---|---|
@@ -1,30 +1,28 @@ | ||
import requests | ||
import openslide | ||
from multiprocessing.pool import ThreadPool | ||
import requests | ||
import sys | ||
from PIL import Image | ||
|
||
Image.MAX_IMAGE_PIXELS = None | ||
|
||
if len(sys.argv <2): | ||
sys.exit("Expects a url as second argument") | ||
|
||
url = sys.argv[1] | ||
|
||
FILE_FIELD = "file-location" | ||
NAME_FIELD = "case_id" | ||
URL = "http://172.20.11.223:9099/services/Camic_TCIA/Image/query/find" | ||
IM_SIZE = 200 | ||
THREADS = 10 | ||
data = requests.get(url=url).json() | ||
|
||
def gen_thumbnail(filename, slide, size, imgtype="png"): | ||
dest = filename + "." + imgtype | ||
print(dest) | ||
slide.get_thumbnail([size, size]).save(dest, imgtype.upper()) | ||
|
||
def process(record): | ||
file = record[FILE_FIELD] | ||
name = record[NAME_FIELD] | ||
def get_thumbnail(obj): | ||
slide = obj['file-location'] | ||
dest = obj['case_id'] + '.png' | ||
try: | ||
slide = openslide.OpenSlide(file) | ||
gen_thumbnail(name, slide, IM_SIZE, imgtype="png") | ||
return "" | ||
image = openslide.open_slide(slide) | ||
image.get_thumbnail([200,200]).save(dest, "PNG") | ||
return dest | ||
except BaseException as e: | ||
# return errors only | ||
return name | ||
return e | ||
|
||
# do it | ||
manifest = requests.get(URL).json() | ||
res = ThreadPool(THREADS).imap_unordered(process, manifest) | ||
res = ThreadPool(20).imap_unordered(get_thumbnail, data) | ||
print([r for r in res]) |