{"id":15009622,"url":"https://github.com/subratamondal1/document-extraction","last_synced_at":"2026-01-24T07:05:17.632Z","repository":{"id":252220482,"uuid":"839758527","full_name":"subratamondal1/document-extraction","owner":"subratamondal1","description":"Document extraction from pdfs and images with OpenCV.","archived":false,"fork":false,"pushed_at":"2024-08-20T08:43:05.000Z","size":7298,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-18T09:46:32.285Z","etag":null,"topics":["computer-vision","document-extraction","image-processing","opencv","py","python3","pytorch"],"latest_commit_sha":null,"homepage":"https://document-extraction-algohype.replit.app/","language":"Python","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/subratamondal1.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-08-08T09:13:49.000Z","updated_at":"2024-11-15T07:50:16.000Z","dependencies_parsed_at":"2024-10-15T01:45:43.386Z","dependency_job_id":null,"html_url":"https://github.com/subratamondal1/document-extraction","commit_stats":null,"previous_names":["subratamondal1/document-extraction"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subratamondal1%2Fdocument-extraction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subratamondal1%2Fdocument-extraction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subratamondal1%2Fdocument-extraction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subratamondal1%2Fdocument-extraction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/subratamondal1","download_url":"https://codeload.github.com/subratamondal1/document-extraction/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235515427,"owners_count":19002481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["computer-vision","document-extraction","image-processing","opencv","py","python3","pytorch"],"created_at":"2024-09-24T19:27:02.554Z","updated_at":"2025-10-06T09:30:14.643Z","avatar_url":"https://github.com/subratamondal1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ccenter\u003e\u003ch1\u003eDocument Extraction\u003c/h1\u003e\u003c/center\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/python-3.10.14-yellow\" alt=\"python@3.10.14\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/numpy-2.0.1-moccasin\" alt=\"numpy@2.0.1\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/pandas-2.1.1-orange\" alt=\"pandas@2.1.1\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/opencv-4.10.0.84-papayawhip\" alt=\"opencv-python@4.10.0.84\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/streamlit-1.37.1-red\" alt=\"streamlit@1.37.1\"\u003e\n\u003c/p\u003e \n\n\n\u003cimg src=\"ss1.png\"/\u003e\n\n---\n**grayscale contrast**\n\n\u003cimg src=\"ss3.png\"/\u003e\n\n**enhance color contrast**\n\u003cimg src=\"ss4.png\"/\u003e\n\n**enhance color contrast and black \u0026 white**\n\u003cimg src=\"ss5.png\"/\u003e\n\n## ⚙️Tech-Stack\n- **Python**\n- **OpenCV**\n- **Streamlit**\n- **Numpy**\n- **Pandas**\n\n## 🧤Image Preprocessing Steps\n\n### Purpose\nThe `enhance_color_contrast` function is designed to preprocess an image by enhancing its color and contrast to make text more visible while reducing the effects of bleed-through. After these enhancements, the image is converted to grayscale and its brightness is adjusted to achieve a clearer, more readable result.\n\n### Function Signature\n```python\ndef enhance_color_contrast(uploaded_image):\n```\n\n### Parameters\n- **`uploaded_image`**: \n  - **Type**: File-like object (e.g., an uploaded image file)\n  - **Description**: The image file provided by the user. It should be in a standard image format such as JPEG, PNG, etc.\n\n### Returns\n- **`brightened_image`**:\n  - **Type**: PIL Image object\n  - **Description**: A grayscale version of the processed image with enhanced brightness, making text more visible and reducing bleed-through.\n\n### Step-by-Step Processing\n\n1. **Read the Image**\n   ```python\n   file_bytes = np.asarray(bytearray(uploaded_image.read()), dtype=np.uint8)\n   image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)\n   ```\n   - **Description**: Converts the uploaded image file into a NumPy array and decodes it into an OpenCV-compatible BGR format image.\n\n2. **Check Image Validity**\n   ```python\n   if image is None:\n       raise ValueError(\"Error: Unable to read the image. Please upload a valid image file.\")\n   ```\n   - **Description**: Ensures the image was loaded correctly. If the image cannot be read, an error is raised.\n\n3. **Convert Image to PIL Format**\n   ```python\n   pil_image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n   ```\n   - **Description**: Converts the image from OpenCV's BGR format to RGB format and then to a PIL Image object for easier manipulation.\n\n4. **Enhance Contrast**\n   ```python\n   contrast_enhancer = ImageEnhance.Contrast(pil_image)\n   pil_image = contrast_enhancer.enhance(1.5)\n   ```\n   - **Description**: Increases the contrast of the image by a factor of 1.5. This step helps make the text stand out more against the background.\n\n5. **Enhance Color Saturation**\n   ```python\n   color_enhancer = ImageEnhance.Color(pil_image)\n   pil_image = color_enhancer.enhance(1.5)\n   ```\n   - **Description**: Enhances the color saturation by a factor of 1.5, making the colors more vivid and improving text visibility.\n\n6. **Convert Back to OpenCV Format**\n   ```python\n   enhanced_image = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2BGR)\n   ```\n   - **Description**: Converts the enhanced image back to OpenCV's BGR format for further processing.\n\n7. **Optional: Apply Mild Denoising**\n   ```python\n   denoised_image = cv2.fastNlMeansDenoisingColored(enhanced_image, None, 10, 10, 7, 21)\n   ```\n   - **Description**: Applies mild denoising to reduce any noise in the image, which might have been enhanced along with the contrast and saturation. This step is optional.\n\n8. **Convert Back to PIL Format**\n   ```python\n   final_pil_image = Image.fromarray(denoised_image)\n   ```\n   - **Description**: Converts the denoised image back to a PIL Image object for final processing.\n\n9. **Convert to Grayscale**\n   ```python\n   grayscale_image = final_pil_image.convert('L')\n   ```\n   - **Description**: Converts the image to grayscale (luminance mode), removing color information while retaining the intensity.\n\n10. **Adjust Brightness**\n    ```python\n    brightness_enhancer = ImageEnhance.Brightness(grayscale_image)\n    brightened_image = brightness_enhancer.enhance(1.2)\n    ```\n    - **Description**: Increases the brightness of the grayscale image by a factor of 1.2. This adjustment helps make the image appear lighter and improves text readability.\n\n11. **Return the Final Image**\n    ```python\n    return brightened_image\n    ```\n    - **Description**: Returns the final processed image, which is now in grayscale with enhanced brightness.\n\n### Example Usage\n```python\n# Assuming 'uploaded_file' is an image file object obtained from a file upload\nprocessed_image = enhance_color_contrast(uploaded_file)\nprocessed_image.show()  # Displays the processed grayscale image with enhanced brightness\n```\n\n### Notes\n- **Adjustable Parameters**: The contrast, saturation, and brightness enhancement factors can be adjusted to better suit the specific characteristics of the image. The default factors are set to `1.5` for contrast and saturation, and `1.2` for brightness.\n- **Denoising**: The denoising step is optional and can be customized or skipped if the image is already clean or if noise reduction is not necessary.\n\nThis function is particularly useful for preprocessing scanned documents, making text clearer and reducing the visibility of any bleed-through from the reverse side of the page.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubratamondal1%2Fdocument-extraction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsubratamondal1%2Fdocument-extraction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubratamondal1%2Fdocument-extraction/lists"}