{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19991,"databundleVersionId":1117522,"sourceType":"competition"}],"dockerImageVersionId":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport cv2\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.fftpack import dct","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def convert_to_rgb_opencv(image_path):\n    # Read the image\n    image = cv2.imread(image_path)\n    # Convert the image to RGB\n    rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    return rgb_image\n\nimage_path = '/kaggle/input/alaska2-image-steganalysis/Cover/00001.jpg'\n\nrgb_image = convert_to_rgb_opencv(image_path)\nimage = cv2.cvtColor(rgb_image, cv2.COLOR_BGR2RGB)\nplt.imshow(image)\nplt.axis('off')\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def convert_folder_to_rgb_opencv(input_folder, output_folder):\n    if not os.path.exists(output_folder):\n        os.makedirs(output_folder)\n    \n    for file_name in os.listdir(input_folder):\n        if file_name.endswith(('jpg', 'jpeg', 'png')):\n            # Read the image\n            image_path = os.path.join(input_folder, file_name)\n            image = cv2.imread(image_path)\n            \n            # Convert the image to RGB\n            rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n            \n            # Save the RGB image\n            output_path = os.path.join(output_folder, file_name)\n            cv2.imwrite(output_path, cv2.cvtColor(rgb_image, cv2.COLOR_RGB2BGR))\n\ninput_folder = '/kaggle/input/alaska2-image-steganalysis/Cover'\noutput_folder = '/kaggle/working/converted_images'\n# convert_folder_to_rgb_opencv(input_folder, output_folder)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def convert_image_to_dct(image_path):\n    # Read the image\n    image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)\n    \n    # Convert the image to float32\n    image = np.float32(image)\n    \n    # Perform DCT\n    dct_image = dct(dct(image.T, norm='ortho').T, norm='ortho')\n    \n    return dct_image\n\ndef show_dct_image(dct_image):\n    # Normalize the DCT image for display purposes\n    dct_image_normalized = cv2.normalize(dct_image, None, 0, 255, cv2.NORM_MINMAX)\n    dct_image_normalized = np.uint8(dct_image_normalized)\n    \n    # Display the DCT image using matplotlib\n    plt.figure(figsize=(8, 8))\n    plt.imshow(dct_image_normalized, cmap='gray')\n    plt.title('DCT Image')\n    plt.axis('off')\n    plt.show()\n\nimage_path = '/kaggle/input/alaska2-image-steganalysis/Cover/00001.jpg'\ndct_image = convert_image_to_dct(image_path)\nshow_dct_image(dct_image)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def convert_folder_to_dct(input_folder, output_folder):\n    if not os.path.exists(output_folder):\n        os.makedirs(output_folder)\n    \n    for file_name in os.listdir(input_folder):\n        if file_name.endswith(('jpg', 'jpeg', 'png')):\n            # Read the image\n            image_path = os.path.join(input_folder, file_name)\n            image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)\n            \n            # Convert the image to float32\n            image = np.float32(image)\n            \n            # Perform DCT\n            dct_image = dct(dct(image.T, norm='ortho').T, norm='ortho')\n            \n            # Normalize and convert DCT image to uint8\n            dct_image = cv2.normalize(dct_image, None, 0, 255, cv2.NORM_MINMAX)\n            dct_image = np.uint8(dct_image)\n            \n            # Save the DCT image\n            output_path = os.path.join(output_folder, file_name)\n            cv2.imwrite(output_path, dct_image)\n\ninput_folder = '/kaggle/input/alaska2-image-steganalysis/Cover'\noutput_folder = '/kaggle/working/dct_images'\n# convert_folder_to_dct(input_folder, output_folder)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def count_images_in_folder(folder_path):\n    image_extensions = ('.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff')\n    \n    image_count = sum(1 for file in os.listdir(folder_path) if file.lower().endswith(image_extensions))\n    \n    return image_count\n\nfolder_path_cover = '/kaggle/input/alaska2-image-steganalysis/Cover'\nfolder_path_test = '/kaggle/input/alaska2-image-steganalysis/Test'\nfolder_path_JMiPOD = '/kaggle/input/alaska2-image-steganalysis/JMiPOD'\nfolder_path_UERD = '/kaggle/input/alaska2-image-steganalysis/UERD'\nfolder_path_JUNIWARD = '/kaggle/input/alaska2-image-steganalysis/JUNIWARD'\n\nprint(f\"Number of images in the folder {folder_path_cover}: {count_images_in_folder(folder_path_cover)}\")\nprint(f\"Number of images in the folder {folder_path_test}: {count_images_in_folder(folder_path_test)}\")\nprint(f\"Number of images in the folder {folder_path_JMiPOD}: {count_images_in_folder(folder_path_JMiPOD)}\")\nprint(f\"Number of images in the folder {folder_path_UERD}: {count_images_in_folder(folder_path_UERD)}\")\nprint(f\"Number of images in the folder {folder_path_JUNIWARD}: {count_images_in_folder(folder_path_JUNIWARD)}\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Path to the folder containing images\nfolder_path_Cover = '/kaggle/input/alaska2-image-steganalysis/Cover'\nfolder_path_Test = '/kaggle/input/alaska2-image-steganalysis/Test'\nfolder_path_JMiPOD = '/kaggle/input/alaska2-image-steganalysis/JMiPOD'\nfolder_path_JUNIWARD = '/kaggle/input/alaska2-image-steganalysis/JUNIWARD'\nfolder_path_UERD = '/kaggle/input/alaska2-image-steganalysis/UERD'\n\n\n# Get list of all image files in the folder\nimage_files_Cover = [os.path.join(folder_path_Cover, file) for file in os.listdir(folder_path_Cover) if file.endswith(('jpg', 'jpeg', 'png'))]\nimage_files_Test = [os.path.join(folder_path_Test, file) for file in os.listdir(folder_path_Test) if file.endswith(('jpg', 'jpeg', 'png'))]\nimage_files_JMiPOD = [os.path.join(folder_path_JMiPOD, file) for file in os.listdir(folder_path_JMiPOD) if file.endswith(('jpg', 'jpeg', 'png'))]\nimage_files_JUNIWARD = [os.path.join(folder_path_JUNIWARD, file) for file in os.listdir(folder_path_JUNIWARD) if file.endswith(('jpg', 'jpeg', 'png'))]\nimage_files_UERD = [os.path.join(folder_path_UERD, file) for file in os.listdir(folder_path_UERD) if file.endswith(('jpg', 'jpeg', 'png'))]\n\n\n# Select the first 5 images\nimage_files_Cover = image_files_Cover[:5]\nimage_files_Test = image_files_Test[:5]\nimage_files_JMiPOD = image_files_JMiPOD[:5]\nimage_files_JUNIWARD = image_files_JUNIWARD[:5]\nimage_files_UERD = image_files_UERD[:5]\n\n\n# Read and display images\nplt.figure(figsize=(15, 5))\nfor i, image_file in enumerate(image_files_Cover):\n    image = cv2.imread(image_file)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.subplot(1, 5, i + 1)\n    plt.imshow(image)\n    plt.axis('off')\nplt.show()\n\nfor i, image_file in enumerate(image_files_JMiPOD):\n    image = cv2.imread(image_file)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.subplot(1, 5, i + 1)\n    plt.imshow(image)\n    plt.axis('off')\nplt.show()\n\nfor i, image_file in enumerate(image_files_JUNIWARD):\n    image = cv2.imread(image_file)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.subplot(1, 5, i + 1)\n    plt.imshow(image)\n    plt.axis('off')\nplt.show()\n\nfor i, image_file in enumerate(image_files_UERD):\n    image = cv2.imread(image_file)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.subplot(1, 5, i + 1)\n    plt.imshow(image)\n    plt.axis('off')\nplt.show()\n\nfor i, image_file in enumerate(image_files_Test):\n    image = cv2.imread(image_file)\n    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n    plt.subplot(1, 5, i + 1)\n    plt.imshow(image)\n    plt.axis('off')\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf /kaggle/working/*","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}