from __future__ import print_function import cv2 import numpy as np import sys from matplotlib import pyplot as plt from svsutils import Slide s = Slide( slide_path= '/home/nathan/data/ccrcc/TCGA_KIRC/TCGA-A3-3346-01Z-00-DX1.95280216-fd71-4a03-b452-6e3d667f2542.svs', process_mag=5, process_size=512, oversample_factor=1.25) s.initialize_output(n_classes=3) s.print_info() for idx, img in enumerate(s.generator()): s.place(img[:, :, ::-1], idx) reconstruction = s.output_img print(reconstruction.shape) plt.imshow(reconstruction) plt.show()
def feature_fn(img): r, g, b = np.split(img, 3, axis=2) output = np.asarray([np.mean(r), np.mean(g), np.mean(b)]) return np.expand_dims(output, axis=0) with tf.Session(config=config) as sess: ds = tf.data.Dataset.from_generator(generator=svs.generate_index, output_types=tf.int64) ds = ds.map(read_region_at_index, num_parallel_calls=4) ds = ds.prefetch(512) iterator = ds.make_one_shot_iterator() img, idx = iterator.get_next() print('Starting') tstart = time.time() while True: try: img_, idx_ = sess.run([img, idx]) features = feature_fn(img_) svs.place(features, idx_, name='features', mode='tile') except tf.errors.OutOfRangeError: print('End') break print('Finished in {}s'.format(time.time() - tstart)) img_out = svs.output_imgs['features'] cv2.imwrite('test_tile_reconstruction.jpg', img_out * (255. / img_out.max()))