{"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":"* This is the notebook for creating 3D images in the [zstart, zstart+zdim] range from 65 tif files. \n* If you think this notebook is useful, please up vote!","metadata":{}},{"cell_type":"code","source":"import numpy as np\nfrom tqdm.notebook import tqdm\nfrom PIL import Image\nimport glob","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-20T21:23:24.176883Z","iopub.execute_input":"2023-03-20T21:23:24.178221Z","iopub.status.idle":"2023-03-20T21:23:24.311820Z","shell.execute_reply.started":"2023-03-20T21:23:24.178170Z","shell.execute_reply":"2023-03-20T21:23:24.310310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"z_start = 0\nz_end = 65\nz_step = 4\nimg_resize_ratio = 0.5","metadata":{"execution":{"iopub.status.busy":"2023-03-20T21:23:24.314209Z","iopub.execute_input":"2023-03-20T21:23:24.314865Z","iopub.status.idle":"2023-03-20T21:23:24.321682Z","shell.execute_reply.started":"2023-03-20T21:23:24.314807Z","shell.execute_reply":"2023-03-20T21:23:24.320282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1, 4):\n    images = [Image.open(filename) for filename in tqdm(sorted(glob.glob(f\"/kaggle/input/vesuvius-challenge-ink-detection/train/{i}/surface_volume/*.tif\")))]\n    \n    image_stack = np.stack([np.array(images[i].resize((int(images[i].height*img_resize_ratio), int(images[i].width*img_resize_ratio))), dtype=np.float32)/65535.0 for i in range(z_start, z_end, z_step)], axis=0)\n    print(image_stack.shape)\n    np.save(f\"/kaggle/working/img_stack_{i}\", image_stack)\n    del images, image_stack","metadata":{"execution":{"iopub.status.busy":"2023-03-20T21:23:47.186868Z","iopub.execute_input":"2023-03-20T21:23:47.187273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}