{"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":"%%writefile resize.py\nimport argparse\nimport os\nimport cv2\nfrom PIL import Image\nimport numpy as np\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\nImage.MAX_IMAGE_PIXELS = None","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-10-23T03:17:48.579864Z","iopub.execute_input":"2023-10-23T03:17:48.581054Z","iopub.status.idle":"2023-10-23T03:17:48.588578Z","shell.execute_reply.started":"2023-10-23T03:17:48.580967Z","shell.execute_reply":"2023-10-23T03:17:48.587453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%writefile -a resize.py\nparser = argparse.ArgumentParser()\nparser.add_argument('--imgsize',   type=int,   default=2048)\nparser.add_argument('--input',     type=str,   default=\"input file path\")\nparser.add_argument('--output',   type=str,   default=\"output file path\")\nargs = parser.parse_args()","metadata":{"execution":{"iopub.status.busy":"2023-10-23T03:17:48.590831Z","iopub.execute_input":"2023-10-23T03:17:48.591459Z","iopub.status.idle":"2023-10-23T03:17:48.603837Z","shell.execute_reply.started":"2023-10-23T03:17:48.591426Z","shell.execute_reply":"2023-10-23T03:17:48.602893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%writefile -a resize.py\nimage = Image.open( args.input )\nw, h = image.size\n\nratio = args.imgsize / min([w, h])\nw2 = int(w*ratio)\nh2 = int(h*ratio)\n\nimage = image.resize( (w2, h2) )\nprint(f\"debug: ({w}, {h}) --> ({w2}, {h2})\")\nif not os.path.exists(os.path.dirname(args.output)):\n    os.makedirs(os.path.dirname(args.output))\nimage.save( args.output )\nprint(f\"save done.\")","metadata":{"execution":{"iopub.status.busy":"2023-10-23T03:17:48.605145Z","iopub.execute_input":"2023-10-23T03:17:48.606053Z","iopub.status.idle":"2023-10-23T03:17:48.618401Z","shell.execute_reply.started":"2023-10-23T03:17:48.606018Z","shell.execute_reply":"2023-10-23T03:17:48.61742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python resize.py --imgsize 2048 --input /kaggle/input/UBC-OCEAN/train_thumbnails/10077_thumbnail.png --output /tmp/test/test.png","metadata":{"execution":{"iopub.status.busy":"2023-10-23T03:17:48.620865Z","iopub.execute_input":"2023-10-23T03:17:48.621665Z","iopub.status.idle":"2023-10-23T03:17:51.715924Z","shell.execute_reply.started":"2023-10-23T03:17:48.621629Z","shell.execute_reply":"2023-10-23T03:17:51.715049Z"},"trusted":true},"execution_count":null,"outputs":[]}]}