Created
January 9, 2015 20:13
-
-
Save hirokai/150178c8ae7bb8aca8dd to your computer and use it in GitHub Desktop.
Cropping and showing images
This file contains hidden or 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
| import requests | |
| import keyring | |
| import json | |
| import csv | |
| gist_images = 'XXXX' | |
| gist_rois = 'YYYY' | |
| username = 'ZZZZ' | |
| password = keyring.get_password('Github API', username) | |
| r = requests.get('https://api.github.com/gists/'+gist_images, auth=(username, password)) | |
| r2 = requests.get('https://api.github.com/gists/'+gist_rois, auth=(username, password)) | |
| def get_content(r): | |
| obj = json.loads(r.content) | |
| files = obj['files'] | |
| k,file = files.items()[0] | |
| return file['content'] | |
| def parse_csv(str,convert=False): | |
| reader = csv.reader(str.splitlines(),delimiter='\t') | |
| hd = reader.next() | |
| print hd | |
| res = [] | |
| for row in reader: | |
| r = {} | |
| for i, col in enumerate(row): | |
| if col != '': | |
| r[hd[i]] = float(col) if convert else col | |
| res.append(r) | |
| return res | |
| def show_all(filelist, rois): | |
| for i,f in enumerate(filelist): | |
| idx = i + 1 | |
| import matplotlib.pyplot as plt | |
| import tifffile | |
| img = tifffile.imread(f) | |
| rois2 = filter(lambda a: a['Slice'] == idx, rois) | |
| for r in rois2: | |
| img2 = img[r['BY']:r['BY']+r['Height'],r['BX']:r['BX']+r['Width']] | |
| plt.imshow(img2,cmap='gray') | |
| plt.show() | |
| def main(): | |
| filelist = get_content(r).splitlines() | |
| rois = parse_csv(get_content(r2), convert=True) | |
| show_all(filelist,rois) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment