{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Install Pyvips"},{"metadata":{"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"#!apt-get update\n!apt -y install --fix-missing libvips libvips-dev\n!pip install pyvips\n#!conda install --channel conda-forge pyvips","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Import libraries"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import pyvips\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nformat_to_dtype = {\n    'uchar': np.uint8,\n    'char': np.int8,\n    'ushort': np.uint16,\n    'short': np.int16,\n    'uint': np.uint32,\n    'int': np.int32,\n    'float': np.float32,\n    'double': np.float64,\n    'complex': np.complex64,\n    'dpcomplex': np.complex128,\n}","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# load region"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"%%timeit\nfor i in range(5):\n    image = pyvips.Image.new_from_file('../input/hubmap-kidney-segmentation/train/0486052bb.tiff')\n    patch = image.crop(i*2048, i*2048, 2048, 2048)\n\n    np_img = np.ndarray(buffer=patch.write_to_memory(),\n                       dtype=format_to_dtype[patch.format],\n                       shape=[patch.height, patch.width, patch.bands])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image = pyvips.Image.new_from_file('../input/hubmap-kidney-segmentation/train/0486052bb.tiff')\npatch = image.crop(10000, 10000, 2048, 2048)\n\nnp_img = np.ndarray(buffer=patch.write_to_memory(),\n                   dtype=format_to_dtype[patch.format],\n                   shape=[patch.height, patch.width, patch.bands])\nplt.imshow(np_img)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Enjoy this competition !!"}],"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":4,"nbformat_minor":4}