{"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":7109370,"sourceType":"datasetVersion","datasetId":4098969}],"dockerImageVersionId":30587,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport cv2\nimport zipfile\n\n# Input directories\ninput_directories = [\n    '/kaggle/input/pre-processed-images/CC',\n    '/kaggle/input/pre-processed-images/EC',\n    '/kaggle/input/pre-processed-images/HGSC',\n    '/kaggle/input/pre-processed-images/LGSC',\n    '/kaggle/input/pre-processed-images/MC'\n]\n\n# Output base directory\noutput_base_directory = '/kaggle/working/improved_images/'\n\n# Zip file name\nzip_file_name = '/kaggle/working/improved_images.zip'\n\n# Function to enhance image quality/contrast\ndef enhance_image(image_path, output_directory):\n    # Read the image\n    img = cv2.imread(image_path)\n\n    # Apply contrast enhancement or any other image processing techniques\n    # For example, you can use cv2.equalizeHist() for histogram equalization\n    # Another option is to use cv2.addWeighted() for contrast adjustment\n\n    # Save the enhanced image to the output directory\n    output_path = os.path.join(output_directory, os.path.basename(image_path))\n    cv2.imwrite(output_path, img)\n\n# Loop through input directories\nfor input_directory in input_directories:\n    # Extract label from the input directory\n    label = os.path.basename(input_directory)\n\n    # Create output directory for the label\n    output_directory = os.path.join(output_base_directory, label)\n    os.makedirs(output_directory, exist_ok=True)\n\n    # Loop through files in the directory\n    for filename in os.listdir(input_directory):\n        # Check if the file is an image (you may need to adjust the condition)\n        if filename.endswith(('.jpg', '.jpeg', '.png')):\n            # Get the full path of the image\n            image_path = os.path.join(input_directory, filename)\n\n            # Enhance the image and save it to the output directory\n            enhance_image(image_path, output_directory)\n\n# Create a zip file and add the contents of the improved_images directory\nwith zipfile.ZipFile(zip_file_name, 'w') as zip_file:\n    for root, dirs, files in os.walk(output_base_directory):\n        for file in files:\n            file_path = os.path.join(root, file)\n            arc_name = os.path.relpath(file_path, output_base_directory)\n            zip_file.write(file_path, arc_name)\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-12-03T13:57:33.831441Z","iopub.execute_input":"2023-12-03T13:57:33.831915Z","iopub.status.idle":"2023-12-03T13:57:47.758433Z","shell.execute_reply.started":"2023-12-03T13:57:33.831879Z","shell.execute_reply":"2023-12-03T13:57:47.757517Z"},"trusted":true},"execution_count":null,"outputs":[]}]}