{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Resize the Images","metadata":{}},{"cell_type":"markdown","source":"#### How to work with large datasets like high quality images (1024 1024) by converting them into lower dimensions (224 224).","metadata":{}},{"cell_type":"markdown","source":"### This updated version have some crucial changes. So, do follow the recent version.","metadata":{}},{"cell_type":"code","source":"import os\nimport glob\nfrom tqdm import tqdm\nfrom PIL import Image, ImageFile\nfrom joblib import Parallel, delayed\n\nImageFile.LOAD_TRUNCATED_IMAGES = True","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-09-12T08:55:35.331590Z","iopub.execute_input":"2023-09-12T08:55:35.331977Z","iopub.status.idle":"2023-09-12T08:55:35.367133Z","shell.execute_reply.started":"2023-09-12T08:55:35.331945Z","shell.execute_reply":"2023-09-12T08:55:35.366075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### Create a function for 1 image .\n## Take the image path and extract the last bit of it.\ndef resize_image(image_path, output_folder, resize):\n    base_name = os.path.basename(image_path) ## extarcts the last name.jpg\n    outpath = os.path.join(output_folder, base_name)\n    img = Image.open(image_path)\n    img = img.resize(\n        (resize[1], resize[0]), resample=Image.BILINEAR ##why image.bilinear\n    )\n    img.save(outpath) ","metadata":{"execution":{"iopub.status.busy":"2023-09-12T08:55:35.368905Z","iopub.execute_input":"2023-09-12T08:55:35.369299Z","iopub.status.idle":"2023-09-12T08:55:35.375264Z","shell.execute_reply.started":"2023-09-12T08:55:35.369268Z","shell.execute_reply":"2023-09-12T08:55:35.374297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! mkdir /kaggle/working/train224\n! mkdir /kaggle/working/test224","metadata":{"execution":{"iopub.status.busy":"2023-09-12T08:55:35.376668Z","iopub.execute_input":"2023-09-12T08:55:35.377257Z","iopub.status.idle":"2023-09-12T08:55:37.617062Z","shell.execute_reply.started":"2023-09-12T08:55:35.377205Z","shell.execute_reply":"2023-09-12T08:55:37.615711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_folder = '../input/siim-isic-melanoma-classification/jpeg/train/'\noutput_folder = \"/kaggle/working/train224/\"\n\nimages = glob.glob(os.path.join(input_folder, \"*.jpg\"))\nParallel(n_jobs=12)(\n    delayed(resize_image)(i, output_folder, (224, 224))\n    for i in tqdm(images)\n)","metadata":{"execution":{"iopub.status.busy":"2023-09-12T08:55:37.623067Z","iopub.execute_input":"2023-09-12T08:55:37.625357Z","iopub.status.idle":"2023-09-12T08:55:37.631939Z","shell.execute_reply.started":"2023-09-12T08:55:37.625321Z","shell.execute_reply":"2023-09-12T08:55:37.630816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_folder = '../input/siim-isic-melanoma-classification/jpeg/test/'\noutput_folder = \"/kaggle/working/test224/\"\n\nimages = glob.glob(os.path.join(input_folder, \"*.jpg\"))\nParallel(n_jobs=12)(\n    delayed(resize_image)(i, output_folder, (224, 224))\n    for i in tqdm(images)\n)","metadata":{"execution":{"iopub.status.busy":"2023-09-12T08:55:37.635061Z","iopub.execute_input":"2023-09-12T08:55:37.635953Z","iopub.status.idle":"2023-09-12T09:14:05.758246Z","shell.execute_reply.started":"2023-09-12T08:55:37.635921Z","shell.execute_reply":"2023-09-12T09:14:05.757186Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]}],"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"}}