{"id":26722827,"url":"https://github.com/asadiahmad/steganography","last_synced_at":"2026-04-19T04:33:01.589Z","repository":{"id":242387516,"uuid":"809420340","full_name":"AsadiAhmad/Steganography","owner":"AsadiAhmad","description":"Steganography is for hiding text in the image without changeing image look with openCV and Numpy Library","archived":false,"fork":false,"pushed_at":"2025-05-11T13:05:51.000Z","size":3492,"stargazers_count":32,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-11T13:19:51.803Z","etag":null,"topics":["google-colab","hide-text","hide-text-in-image","numpy","opencv","steganography"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AsadiAhmad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-02T16:32:26.000Z","updated_at":"2025-05-11T13:05:54.000Z","dependencies_parsed_at":"2024-06-02T18:38:04.344Z","dependency_job_id":"45590863-e6dd-4b15-b5a3-1d9fb46350ed","html_url":"https://github.com/AsadiAhmad/Steganography","commit_stats":null,"previous_names":["asadiahmad/steganography"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AsadiAhmad/Steganography","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FSteganography","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FSteganography/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FSteganography/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FSteganography/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AsadiAhmad","download_url":"https://codeload.github.com/AsadiAhmad/Steganography/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FSteganography/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31994999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-colab","hide-text","hide-text-in-image","numpy","opencv","steganography"],"created_at":"2025-03-27T20:37:24.754Z","updated_at":"2026-04-19T04:33:01.583Z","avatar_url":"https://github.com/AsadiAhmad.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Steganography\nSteganography is for hiding text in the image without changeing image look with openCV and Numpy Library. In this project first we calculate image features like height width and size then convert the text into binary text then check if the image is big enough to store the text ? then extend the 0 bit to fit the text into image size. seprate the image into Red Green and Blue frame then seprate the text into 3 part then for every frame we remove the LSB bit of a pixel then replace it with our bit from the text then do this for all pixels then our text is decoded into image. now we can do it reverse for encodeing text from image.\n\n\u003cimg src=\"/Images/steganography.jpg\"/\u003e\n\n## Tech :hammer_and_wrench: Languages and Tools :\n\n\u003cdiv\u003e\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/python/python-original.svg\" title=\"Python\" alt=\"Python\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/jupyter/jupyter-original.svg\" title=\"Jupyter Notebook\" alt=\"Jupyter Notebook\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://assets.st-note.com/img/1670632589167-x9aAV8lmnH.png\" title=\"Google Colab\" alt=\"Google Colab\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/opencv/opencv-original.svg\" title=\"OpenCV\" alt=\"OpenCV\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/numpy/numpy-original.svg\" title=\"Numpy\" alt=\"Numpy\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n\u003c/div\u003e\n\n- Python : Popular language for implementing Neural Network\n- Jupyter Notebook : Best tool for running python cell by cell\n- Google Colab : Best Space for running Jupyter Notebook with hosted server\n- OpenCV : Best Library for working with images\n- Numpy : Best Library for working with arrays in python\n\n## 💻 Run the Notebook on Google Colab\n\nYou can easily run this code on google colab by just clicking this badge [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/AsadiAhmad/Steganography/blob/main/Code/Steganography.ipynb)\n\n## 📝 Tutorial\n### Step1: Install Librarys\nWe need to have installed Python, OpenCV and Numpy\n\nfor windows and ubuntu we need install python, OpenCV and Numpy\n\nand for Google colab just install OpenCV\n\ninstall OpenCV\n```sh\n!pip install opencv-python\n```\n\ninstall Numpy\n```sh\n!pip install numpy\n```\n\n### Step2: Import Librarys\nimport opencv,numpy library and cv2_imshow for showing picture in google colab\n\n```sh\nimport cv2\nimport numpy as np\nfrom google.colab.patches import cv2_imshow\n```\n\n### Step3: Load Image\nUpload your image into google colab or for local device using a local image.\n\nfound your image location and copy the path\n\n```sh\nimage_path = \"/content/Wallpaper.jpg\"\nimage = cv2.imread(image_path)\ncv2_imshow(image)\n```\n\n\u003cimg src=\"/Images/Wallpaper.jpg\"/\u003e\n\n### Step4: Load text data\nhere you can enter your text to hide it in image\n\n```sh\ntext = \"\"\"here is your text\"\"\"\n```\n\n### Step5: Convert text to binary\nyou need to convert your text into binary text\n\n```sh\ndef text_to_bin(text):\n    binary = ''.join(format(ord(char), '08b') for char in text)\n    return binary\nbinary_text = text_to_bin(text)\nprint(binary_text)\n```\n\nhere is the sample of binary converted:\n\n010000000110100101101101\n\n### Step6: Calculate size of image\nnow you need to know what is your image size and how much it can hold data within\n\n```sh\nheight, width, channels = image.shape\nimage_size = height*width\nmax_chars = int((channels*image_size)/8)\n```\n\n```sh\nprint(\"image height : \" + str(height))\nprint(\"image width : \" + str(width))\nprint(\"image size : \" + str(image_size))\nprint(\"max charechter can hide in picture : \" + str(max_chars))\nprint(\"image can hide : \" + str((channels*image_size)/80) + \" Words\")\n```\n\nhere is some information about our image :\n\nimage height : 720\n\nimage width : 1280\n\nimage size : 921600\n\nmax charechter can hide in picture : 345600\n\nimage can hide : 34560.0 Words\n\n### Step7: Extend binary bits\nHere you should change the format of your text into image to fit the text to image\n\nif your text is to big for your image here you see the error\n\n```sh\ndef extend_binary_text(image_size, binary_text, max_chars):\n    needed_bits = len(binary_text)\n    if(needed_bits \u003e max_chars*8):\n        print(\"text size is too high\")\n        return\n\n    extended_binary_text = binary_text.ljust(max_chars*8, '0')\n    return extended_binary_text\nextended_binary_text = extend_binary_text(image_size, binary_text, max_chars)\n```\n\n### Step8: Spereate binary text into channel parts\nBecause we have RGB image for using maximum space from the image we should separate the text into 3 part\n\n```sh\ndef divide_string_parts(text, channels):\n    part_length = len(text) // channels\n    text_parts = []\n    \n    for i in range(channels):\n        part_start = part_length * i\n        part_end = part_length * (i + 1)\n        text_parts.append(text[part_start:part_end])\n    \n    return text_parts\ntext_parts = divide_string_parts(extended_binary_text, channels)\n```\n\n### Step9: Seperate image to channel parts\nSperate image into Red Green and Blue frame\n\n```sh\nif channels == 3:\n    blue_channel, green_channel, red_channel = cv2.split(image)\n    blue_matrix = np.array(blue_channel)\n    green_matrix = np.array(green_channel)\n    red_matrix = np.array(red_channel)\n```\n\n### Step10: Decode text into image\nHere is our main function for decoding data into image in here we remove the first bit(LSB) of a pixel then replace it with our data then do it for all pixels\n\n```sh\ndef decimalToBinary(n): \n    return format(n, '08b')\n\ndef binaryToDecimal(n):\n    return int(n,2)\n\ncounter = 0\nfor i in range(height):\n    for j in range(width):\n        red_matrix[i,j] = binaryToDecimal(decimalToBinary(red_matrix[i,j])[0:7] + text_parts[0][counter])\n        green_matrix[i,j] = binaryToDecimal(decimalToBinary(green_matrix[i,j])[0:7] + text_parts[1][counter])\n        blue_matrix[i,j] = binaryToDecimal(decimalToBinary(blue_matrix[i,j])[0:7] + text_parts[2][counter])\n        counter += 1\n```\n\n### Step11: Build image\nWe need to gather Red Green and Blue Frame and Biuld our image.\n\n```sh\nreconstructed_image = cv2.merge([blue_matrix, green_matrix, red_matrix])\ncv2.imwrite(\"/content/ImageWithData.png\", reconstructed_image)\ncv2_imshow(reconstructed_image)\n```\n\n\u003cimg src=\"/Images/ImageWithData.png\"/\u003e\n\nif you notice you cant see any changes from the picture.\n\n### Step12: Encode text from image\nEncode the image with reading the image by 8bit and extract the text.\n\n```sh\ndef bin_to_text(binary):\n    text = ''.join(chr(int(binary[i:i+8], 2)) for i in range(0, len(binary), 8))\n    return text\n\ndef cut_binary_at_8_zeros(binary_str):\n    for i in range(0, len(binary_str), 8):\n        chunk = binary_str[i:i+8]\n        if chunk == '00000000':\n            return binary_str[:i]\n    return binary_str\n\ndef decode_text_from_image(image_path):\n    image = cv2.imread(image_path)\n    blue_channel, green_channel, red_channel = cv2.split(image)\n\n    blue_matrix = np.array(blue_channel)\n    green_matrix = np.array(green_channel)\n    red_matrix = np.array(red_channel)\n\n    text1 = \"\"\n    text2 = \"\"\n    text3 = \"\"\n    counter = 0\n    for i in range(height):\n        for j in range(width):\n            text1 = text1 + decimalToBinary(red_matrix[i,j])[-1]\n            text2 = text2 + decimalToBinary(green_matrix[i,j])[-1]\n            text3 = text3 + decimalToBinary(blue_matrix[i,j])[-1]\n            counter += 1\n    concated_binary_text = text1 + text2 + text3\n    cuted_binary_text = cut_binary_at_8_zeros(concated_binary_text)\n    return bin_to_text(cuted_binary_text)\n\ndecode_text_from_image(\"/content/ImageWithData.png\")\n```\n\nafter running this method you can see the hided text\n\n## 🪪 License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasadiahmad%2Fsteganography","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasadiahmad%2Fsteganography","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasadiahmad%2Fsteganography/lists"}