{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# CPTAC-PDA image conversion\n\n> Convert svs files to zarr files\n\n***","metadata":{}},{"cell_type":"code","source":"# Install zarr and load packages\n!pip install -qq zarr\nimport tifffile, cv2, zarr\nfrom pathlib import Path\nimport matplotlib.pyplot as plt\nfrom tqdm.notebook import tqdm","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Settings\nscale = 2\npath = Path('../input/cptacpda')\nfiles = [f for f in path.iterdir() if f.suffix=='.svs']\ng_data = zarr.group(f'images_scale{scale}')","metadata":{"_kg_hide-input":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Loop over files\nfor f in tqdm(files):\n    print(f.name)\n    img = tifffile.imread(f)\n    \n    if scale!=1:\n        new_size = (img.shape[1] // scale, img.shape[0] // scale)\n        print(f'Resizing from {img.shape[:2]} to {new_size}')\n        img = cv2.resize(img, new_size)\n    \n    g_data[f.stem] = img\n    print(g_data[f.stem].info)\n    \n    print('Plotting')\n    fig, ax = plt.subplots(figsize=(15,15))\n    shape = img.shape\n    ax.imshow(cv2.resize(img, (1024, 1024*shape[0]//shape[1])))\n    plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}