{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nimport cv2 as cv\nimport PIL\nimport tifffile\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-22T03:52:02.130644Z","iopub.execute_input":"2022-07-22T03:52:02.131229Z","iopub.status.idle":"2022-07-22T03:52:02.553609Z","shell.execute_reply.started":"2022-07-22T03:52:02.131106Z","shell.execute_reply":"2022-07-22T03:52:02.55202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Purpose\n\nIn this competition, Dataset as Image has huge size. Therefore, resizing-saving dataset is the first approach that I am thinking to solve the \"allocation\" situation.\n\nSo, what the best format to save a resized Image? \n\n[TIFFs](https://www.adobe.com/vn_en/creativecloud/file-types/image/comparison/jpeg-vs-tiff.html) are a raster graphic file, but this format uses lossless compression to retain image data. This means that TIFF files are generally large. They tend to take up a lot of drive space and can be impossible to send via email. However, their high quality makes them a great choice for doing any digital editing work, especially if you store them in your back-up drive afterwards. And *TIFF is the original format in competition*\n\n*Other typical solution is JPEG*. The [JPEG](https://www.adobe.com/vn_en/creativecloud/file-types/image/comparison/jpeg-vs-tiff.html) format uses lossy compression, meaning that these files reduce picture quality to achieve a smaller, more manageable file size. This makes JPEGs easy to store on a drive, send via email, or move between cloud services. However, during compression some of the original image data is lost, causing a noticeable loss in picture resolution.","metadata":{}},{"cell_type":"markdown","source":"# Load Dataset","metadata":{}},{"cell_type":"code","source":"# Choose a example Image\npath = '../input/mayo-clinic-strip-ai/train/026c97_0.tif'\nimg = tifffile.imread(path)\nprint(img.shape)\nplt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T03:52:02.555851Z","iopub.execute_input":"2022-07-22T03:52:02.556239Z","iopub.status.idle":"2022-07-22T03:52:11.971443Z","shell.execute_reply.started":"2022-07-22T03:52:02.556206Z","shell.execute_reply":"2022-07-22T03:52:11.970022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resized_img = cv.resize(img,(4096,4096))\nplt.imshow(resized_img)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T03:52:11.973176Z","iopub.execute_input":"2022-07-22T03:52:11.976153Z","iopub.status.idle":"2022-07-22T03:52:13.757917Z","shell.execute_reply.started":"2022-07-22T03:52:11.976092Z","shell.execute_reply":"2022-07-22T03:52:13.756548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Save to file and read out","metadata":{}},{"cell_type":"code","source":"# Save to JPEG and TIFF\ncv.imwrite(f\"test.jpg\", resized_img)\ncv.imwrite(f\"test.tif\", resized_img)","metadata":{"execution":{"iopub.status.busy":"2022-07-22T03:52:13.760874Z","iopub.execute_input":"2022-07-22T03:52:13.761368Z","iopub.status.idle":"2022-07-22T03:52:14.592588Z","shell.execute_reply.started":"2022-07-22T03:52:13.761317Z","shell.execute_reply":"2022-07-22T03:52:14.591711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Read again the saved files\nsample_jpg = cv.imread(\"test.jpg\")\nsample_tiff = tifffile.imread(\"test.tif\")","metadata":{"execution":{"iopub.status.busy":"2022-07-22T03:52:14.594208Z","iopub.execute_input":"2022-07-22T03:52:14.594576Z","iopub.status.idle":"2022-07-22T03:52:15.262083Z","shell.execute_reply.started":"2022-07-22T03:52:14.594541Z","shell.execute_reply":"2022-07-22T03:52:15.260835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check the differences\nnp.setdiff1d (sample_jpg[:,:,2],sample_tiff[:,:,2])","metadata":{"execution":{"iopub.status.busy":"2022-07-22T03:52:15.264089Z","iopub.execute_input":"2022-07-22T03:52:15.264478Z","iopub.status.idle":"2022-07-22T03:52:16.254857Z","shell.execute_reply.started":"2022-07-22T03:52:15.26444Z","shell.execute_reply":"2022-07-22T03:52:16.253205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"==> Having difference in 2 saved image. \n\n## What format file do you choose to save resized image in this competition??","metadata":{}}]}