Commit 252627c4 authored by asus's avatar asus

Add Model Training

parent b7d4c69c
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "72ba86ae",
"metadata": {},
"outputs": [
{
"ename": "OSError",
"evalue": "cannot write mode RGBA as JPEG",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
"File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PIL\\JpegImagePlugin.py:643\u001b[0m, in \u001b[0;36m_save\u001b[1;34m(im, fp, filename)\u001b[0m\n\u001b[0;32m 642\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 643\u001b[0m rawmode \u001b[38;5;241m=\u001b[39m \u001b[43mRAWMODE\u001b[49m\u001b[43m[\u001b[49m\u001b[43mim\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m]\u001b[49m\n\u001b[0;32m 644\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"\u001b[1;31mKeyError\u001b[0m: 'RGBA'",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[1;31mOSError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn [2], line 32\u001b[0m\n\u001b[0;32m 30\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, transformed_image \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(transformed_images):\n\u001b[0;32m 31\u001b[0m transformed_image_path \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(new_folder_path, \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfilename\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m_transformed_\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mi\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.jpg\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 32\u001b[0m \u001b[43mtransformed_image\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msave\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtransformed_image_path\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 34\u001b[0m \u001b[38;5;66;03m# Increment the number of processed images and check if we've processed 400 images\u001b[39;00m\n\u001b[0;32m 35\u001b[0m processed_images \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n",
"File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PIL\\Image.py:2431\u001b[0m, in \u001b[0;36mImage.save\u001b[1;34m(self, fp, format, **params)\u001b[0m\n\u001b[0;32m 2428\u001b[0m fp \u001b[38;5;241m=\u001b[39m builtins\u001b[38;5;241m.\u001b[39mopen(filename, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mw+b\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 2430\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 2431\u001b[0m \u001b[43msave_handler\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 2432\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m 2433\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m open_fp:\n",
"File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PIL\\JpegImagePlugin.py:646\u001b[0m, in \u001b[0;36m_save\u001b[1;34m(im, fp, filename)\u001b[0m\n\u001b[0;32m 644\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 645\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcannot write mode \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mim\u001b[38;5;241m.\u001b[39mmode\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m as JPEG\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m--> 646\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m(msg) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[0;32m 648\u001b[0m info \u001b[38;5;241m=\u001b[39m im\u001b[38;5;241m.\u001b[39mencoderinfo\n\u001b[0;32m 650\u001b[0m dpi \u001b[38;5;241m=\u001b[39m [\u001b[38;5;28mround\u001b[39m(x) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m info\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdpi\u001b[39m\u001b[38;5;124m\"\u001b[39m, (\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m0\u001b[39m))]\n",
"\u001b[1;31mOSError\u001b[0m: cannot write mode RGBA as JPEG"
]
}
],
"source": [
"from PIL import Image\n",
"import os\n",
"\n",
"# Path to the existing folder with image files\n",
"existing_folder_path = r\"C:\\Users\\asus\\Desktop\\New folder\"\n",
"\n",
"# Create a new folder to store the transformed images\n",
"new_folder_path =r\"C:\\Users\\asus\\Desktop\\New folder (2)\"\n",
"if not os.path.exists(new_folder_path):\n",
" os.makedirs(new_folder_path)\n",
"\n",
"# Loop through all image files in the existing folder\n",
"processed_images = 0\n",
"for filename in os.listdir(existing_folder_path):\n",
" # Check if the file is an image file\n",
" if filename.endswith(\".jpg\") or filename.endswith(\".png\"):\n",
" # Open the existing image\n",
" existing_image_path = os.path.join(existing_folder_path, filename)\n",
" existing_image = Image.open(existing_image_path)\n",
"\n",
" # Apply some transformations to the image\n",
" transformed_images = []\n",
" for i in range(5):\n",
" # Example transformations - you can modify these to fit your needs\n",
" transformed_image = existing_image.rotate(90*i)\n",
" transformed_image = transformed_image.transpose(Image.FLIP_LEFT_RIGHT)\n",
" transformed_images.append(transformed_image)\n",
"\n",
" # Save the transformed images to the new folder\n",
" for i, transformed_image in enumerate(transformed_images):\n",
" transformed_image_path = os.path.join(new_folder_path, f\"{filename}_transformed_{i}.jpg\")\n",
" transformed_image.save(transformed_image_path)\n",
"\n",
" # Increment the number of processed images and check if we've processed 400 images\n",
" processed_images += 1\n",
" if processed_images == 400:\n",
" break\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3026991e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e4e351af",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c4a92f9b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Image 'C:\\Users\\asus\\Desktop\\New folder\\10698937_001.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\10698937_001.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\11266455-pomegranate-cultivation.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\11266455-pomegranate-cultivation.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\11602069.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\11602069.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\1402797214_000.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\1402797214_000.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\1433164762_001.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\1433164762_001.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\1439045981_001.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\1439045981_001.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\175962-847x567-Pomegranate-tree.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\175962-847x567-Pomegranate-tree.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\2285841216_3ca24bf8b1_z.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\2285841216_3ca24bf8b1_z.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\26.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\26.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\2886677846_b8aace8c6b_z.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\2886677846_b8aace8c6b_z.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\3872.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\3872.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\43db0c65-ad6f-46b6-9654-8faee547cdad.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\43db0c65-ad6f-46b6-9654-8faee547cdad.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\634593320-Picture_177.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\634593320-Picture_177.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\66ew2bdrkqc41.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\66ew2bdrkqc41.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\756224e140667413556b0f4f831319ba.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\756224e140667413556b0f4f831319ba.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\97098804.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\97098804.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\9xzshmd6fwd41.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\9xzshmd6fwd41.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\Dr3oKup2JBr5kNjMdgQ49g06Iv1FbaRaeFox4-uJgSA.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\Dr3oKup2JBr5kNjMdgQ49g06Iv1FbaRaeFox4-uJgSA.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\home-design.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\home-design.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\IMG_20140719_191227073_HDR.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\IMG_20140719_191227073_HDR.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\maxresdefault.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\maxresdefault.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\maxresdefault_2.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\maxresdefault_2.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\maxresdefault_3.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\maxresdefault_3.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\maxresdefault_4.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\maxresdefault_4.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\n2nrn93282401.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\n2nrn93282401.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\open-pomegranate-leaves-tree-branch-179436758.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\open-pomegranate-leaves-tree-branch-179436758.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\P1010059.JPG' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\P1010059.JPG'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\Pomegranate - Punica granatum seedlings.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\Pomegranate - Punica granatum seedlings.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\pomegranate-fruit-tree-28488923.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\pomegranate-fruit-tree-28488923.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\pomegranate-seed-germination-process-seedling-small-black-pot-window-172369828.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\pomegranate-seed-germination-process-seedling-small-black-pot-window-172369828.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\pomegranate-seedling-sprouts-growing-seed-pot-grow-exotic-tree-home-dwarf-145222172.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\pomegranate-seedling-sprouts-growing-seed-pot-grow-exotic-tree-home-dwarf-145222172.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\Pomegranate-Seedlings-Growing-in-the-Garden.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\Pomegranate-Seedlings-Growing-in-the-Garden.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\pomegranate-tree-with-flowers.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\pomegranate-tree-with-flowers.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\pw72umqtuda41.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\pw72umqtuda41.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\red-pomegranates-ripened-tree-garden-north-state-israel-tree-garden-israel-ripe-pomegranates-160631268.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\red-pomegranates-ripened-tree-garden-north-state-israel-tree-garden-israel-ripe-pomegranates-160631268.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\Salavatski_Pomegranate_Page-16_SS.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\Salavatski_Pomegranate_Page-16_SS.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th_2.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th_2.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th_3.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th_3.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th_4.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th_4.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th_5.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th_5.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th_6.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th_6.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th_7.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th_7.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th_8.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th_8.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\th_9.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\th_9.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\Ubali-pomegranates_basket-proteas-festival-lemons-trees-farm.jpg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\Ubali-pomegranates_basket-proteas-festival-lemons-trees-farm.jpg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\WhatsApp Image 2023-08-28 at 8.51.39 PM.jpeg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\WhatsApp Image 2023-08-28 at 8.51.39 PM.jpeg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\WhatsApp Image 2023-08-28 at 8.51.41 PM.jpeg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\WhatsApp Image 2023-08-28 at 8.51.41 PM.jpeg'.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Image 'C:\\Users\\asus\\Desktop\\New folder\\WhatsApp Image 2023-08-28 at 8.51.42 PM (2).jpeg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\WhatsApp Image 2023-08-28 at 8.51.42 PM (2).jpeg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\WhatsApp Image 2023-08-28 at 8.51.42 PM.jpeg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\WhatsApp Image 2023-08-28 at 8.51.42 PM.jpeg'.\n",
"Image 'C:\\Users\\asus\\Desktop\\New folder\\WhatsApp Image 2023-08-28 at 8.51.43 PM.jpeg' resized to 256x256 pixels and saved as 'C:\\Users\\asus\\Desktop\\New folder (2)\\WhatsApp Image 2023-08-28 at 8.51.43 PM.jpeg'.\n"
]
}
],
"source": [
"from PIL import Image\n",
"import os\n",
"\n",
"def resize_to_256(input_path, output_path):\n",
" \"\"\"\n",
" Resize an image to 256x256 pixels.\n",
" \n",
" Args:\n",
" input_path (str): Path to the input image file.\n",
" output_path (str): Path to save the resized image.\n",
" \"\"\"\n",
" try:\n",
" # Open the image file\n",
" image = Image.open(input_path)\n",
" \n",
" # Resize the image to 256x256 pixels\n",
" resized_image = image.resize((256, 256))\n",
" \n",
" # Save the resized image to the specified output path\n",
" resized_image.save(output_path)\n",
" \n",
" print(f\"Image '{input_path}' resized to 256x256 pixels and saved as '{output_path}'.\")\n",
" except Exception as e:\n",
" print(f\"An error occurred while processing '{input_path}': {str(e)}\")\n",
"\n",
"# Specify the input directory containing images to be resized\n",
"input_directory = r\"C:\\Users\\asus\\Desktop\\New folder\"\n",
"\n",
"\n",
"# Specify the output directory to save resized images\n",
"output_directory =r\"C:\\Users\\asus\\Desktop\\New folder (2)\"\n",
"\n",
"# Create the output directory if it doesn't exist\n",
"if not os.path.exists(output_directory):\n",
" os.makedirs(output_directory)\n",
"\n",
"# Iterate through input images and resize each one\n",
"for filename in os.listdir(input_directory):\n",
" if filename.lower().endswith(('.jpg', '.jpeg', '.png')):\n",
" input_image_path = os.path.join(input_directory, filename)\n",
" output_image_path = os.path.join(output_directory, filename)\n",
" resize_to_256(input_image_path, output_image_path)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e1d20b08",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment