{"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"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":45867,"databundleVersionId":6924515,"sourceType":"competition"},{"sourceId":7283385,"sourceType":"datasetVersion","datasetId":4223278}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from PIL import Image\nimport os\nfrom tqdm import tqdm  \nimport shutil\n\nImage.MAX_IMAGE_PIXELS = None","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-12-26T20:55:23.771806Z","iopub.execute_input":"2023-12-26T20:55:23.772918Z","iopub.status.idle":"2023-12-26T20:55:23.777302Z","shell.execute_reply.started":"2023-12-26T20:55:23.772883Z","shell.execute_reply":"2023-12-26T20:55:23.776171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def copy_files(source_folder, destination_folder):\n#     # Create the destination folder if it doesn't exist\n#     if not os.path.exists(destination_folder):\n#         os.makedirs(destination_folder)\n\n#     # Get a list of all files in the source folder\n#     files_to_copy = [f for f in os.listdir(source_folder) if os.path.isfile(os.path.join(source_folder, f))]\n\n#     # Use tqdm for a progress bar\n#     for file_name in tqdm(files_to_copy, desc=\"Copying files\"):\n#         source_path = os.path.join(source_folder, file_name)\n#         destination_path = os.path.join(destination_folder, file_name)\n\n#         try:\n#             shutil.copy(source_path, destination_path)\n#         except Exception as e:\n#             print(f\"Error copying {file_name}: {e}\")\n\ndef resize_images(input_folder, output_folder, skip_files, new_width, new_height):\n    # Create the output folder if it doesn't exist\n    if not os.path.exists(output_folder):\n        os.makedirs(output_folder)\n\n    # Get the list of files in the input folder\n    filenames = os.listdir(input_folder)[skip_files:]\n    print(len(filenames))\n\n    # Use tqdm to create a progress bar\n    with tqdm(total=len(filenames), desc=\"Resizing images\", unit=\"image\") as pbar:\n        # Loop through each file in the input folder\n        for filename in filenames:\n            input_path = os.path.join(input_folder, filename)\n            output_path = os.path.join(output_folder, filename)\n\n            try:\n                # Open the image\n                with Image.open(input_path) as img:\n                    # Resize the image\n                    resized_img = img.resize((new_width, new_height), Image.Resampling.LANCZOS)\n\n                    # Save the resized image to the output folder\n                    resized_img.save(output_path)\n                    pbar.update(1)  # Update the progress bar\n                    pbar.set_postfix({\"Processed\": filename})\n\n            except Exception as e:\n                print(f\"Error processing image {input_path}: {e}\")\n\n                \n# Specify input and output folders, and the desired dimensions\ninput_folder = '/kaggle/input/UBC-OCEAN/train_images'\noutput_folder = '/kaggle/working'\nnew_width = 8192\nnew_height = 8192\nskip_files = 269\n\n# Copy files\n# copy_files(source_copy_folder, output_folder, already_resized_folder)\n\n# Call the function to resize images\nresize_images(input_folder, output_folder, skip_files, new_width, new_height)","metadata":{"execution":{"iopub.status.busy":"2023-12-26T20:55:23.779021Z","iopub.execute_input":"2023-12-26T20:55:23.779396Z","iopub.status.idle":"2023-12-26T20:55:26.135092Z","shell.execute_reply.started":"2023-12-26T20:55:23.779363Z","shell.execute_reply":"2023-12-26T20:55:26.133897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}