Team Ai
Apppublic

thankyouforlovingme/3D-Image-Compressor

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
App README

3D Image Composer

An interactive application that segments a person from an image, inserts them into a stereoscopic background, and creates an anaglyph 3D image. The project allows dynamic depth adjustment to position the person closer or farther in the scene.


Features

  • —Person Segmentation: Automatically detects and isolates a person in an image using a pre-trained deep learning model.
  • —Stereoscopic Integration: Inserts the segmented person into left and right stereoscopic images.
  • —Anaglyph 3D Images: Combines left and right images into an anaglyph viewable with red-cyan glasses.
  • —Dynamic Depth Adjustment: Adjust the perceived depth of the inserted person with a slider.
  • —Interactive Gradio App: User-friendly interface for uploading images and generating results.

Installation

Prerequisites

  • —Python 3.9 or later
  • —pip (Python package manager)
  • —Git

Steps

  1. 1.Clone the repository:
bash
   git clone <repository-url>
   cd project
  1. 1.Install dependencies:
bash
   pip install -r requirements.txt
  1. 1.Ensure the following directories exist:
bash
   mkdir assets output
  1. 1.Add input images to the assets/ directory:
  2. 2.A person image (e.g., person.jpg).
  3. 3.A side-by-side stereoscopic image (e.g., stereo.jpg).

Running the Gradio App

  1. 1.Launch the app:
bash
   python src/main.py
  1. 1.Open the provided URL in a browser.
  1. 1.Upload your images:
  2. 2.Person Image: Upload the image to segment.
  3. 3.Stereoscopic Image: Upload the side-by-side stereoscopic image.
  1. 1.Adjust the depth level using the slider to generate a 3D anaglyph.

Running Locally

Segment a Person

  1. 1.Run the segmentation script:
bash
   python src/segmentation/segment_person.py
  1. 1.This generates the segmented image with a transparent background in the output/ directory:
  2. 2.output/person_segmented.png

Insert the Person into a Stereoscopic Image

  1. 1.Run the insertion script:
bash
   python src/stereoscopic/insert_person.py
  1. 1.This generates modified left and right stereoscopic images:
  2. 2.output/left_with_person.png
  3. 3.output/right_with_person.png

Generate Anaglyphs

  1. 1.Run the anaglyph creation script:
bash
   python src/anaglyph/create_anaglyph.py
  1. 1.This creates anaglyph images for different depths:
  2. 2.output/anaglyph_close.png
  3. 3.output/anaglyph_medium.png
  4. 4.output/anaglyph_far.png

Outputs

Generated Files

  • —Segmented Person:
  • —output/person_segmented.png (Transparent image of the detected person)
  • —Stereoscopic Pairs:
  • —output/left_with_person.png
  • —output/right_with_person.png
  • —Anaglyph Images:
  • —output/anaglyph_close.png
  • —output/anaglyph_medium.png
  • —output/anaglyph_far.png

Example

The resulting anaglyph images can be viewed with red-cyan 3D glasses to see the depth effect.


Future Enhancements

  • —Support for multiple objects with independent depth adjustments.
  • —Enhanced background blending for better integration.
  • —Integration with other 3D visualization techniques (e.g., VR).
  • —Real-time updates with WebSocket support.