GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rajsingh16/ProductPlace-AI: An AI-driven post-production pipeline for e-commerce, enabling natural language object segmentation and precise spatial repositioning in product photography.

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
node_modules
node_modules
 
 
README.md
README.md
 
 
example.jpg
example.jpg
 
 
masked_example.png
masked_example.png
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
repositioned_example.png
repositioned_example.png
 
 
run.py
run.py
 
 

Repository files navigation

Object Repositioning Tool

This project implements a solution for the two-part problem of object segmentation and repositioning based on a text prompt and pixel shift values.

Approach

The solution is implemented in a single Python script, run.py, which handles both Task 1 (Segmentation) and Task 2 (Repositioning) based on the command-line arguments provided.

Task 1: Text-Prompt-Based Segmentation

The assignment requires segmentation based on a user-given class prompt. Since a dedicated, easily deployable open-source model like Grounded-SAM requires complex setup (model weights, multiple dependencies), a vision-enabled Large Language Model (LLM) (gpt-4.1-mini) was used as a creative alternative, as suggested in the problem statement ("use existing models (including the amazing one you have in your skull)").

  1. Segmentation: The LLM is prompted with the image and the class prompt (e.g., "red circle"). It is instructed to return a JSON object containing a list of normalized polygon coordinates ([0, 1000]) that define the object's boundary.
  2. Mask Generation: The returned normalized coordinates are scaled to the actual image dimensions. A binary mask is created, and a semi-transparent red overlay is applied to the original image using the mask, fulfilling the requirement for an image with a red mask on the segmented object.

Task 2: Object Repositioning

This task involves moving the segmented object and creating a composite image.

  1. Object Extraction: The polygon coordinates from Task 1 are used to create a transparent image containing only the segmented object.
  2. Background Generation (Limitation): The assignment references inpainting models (e.g., Stable Diffusion Inpainting) to remove the object from its original location. Due to the constraints of the sandbox environment (lack of a dedicated inpainting model), a true inpainting step could not be performed. The current implementation uses the original image as the background. This means the original object remains visible in the background, which is a known limitation.
  3. Repositioning and Compositing:
    • The user-specified pixel shifts (--x and --y) are applied. Note that the image coordinate system has the origin (0,0) at the top-left, so a positive vertical shift (+y for up) is translated to a negative pixel shift in the y-axis.
    • The extracted object (with transparency) is pasted onto the background image at the new, shifted coordinates.
    • The final composite image is saved as a PNG file to preserve transparency.

Execution

Prerequisites

The script requires Python 3.11+ and the following libraries:

pip3 install openai Pillow numpy

You must also have your OPENAI_API_KEY set in your environment variables for the LLM-based segmentation to work.

Task 1: Segmentation and Masking

To run Task 1, provide the input image, the class prompt, and the output path.

Command:

python3.11 run.py --image <input_image_path> --class "<object_class_prompt>" --output <output_image_path>

Example (using the test image):

python3.11 run.py --image example.jpg --class "red circle" --output masked_example.png

Task 2: Object Repositioning

To run Task 2, provide the input image, the class prompt, and the pixel shifts. The output file will be named repositioned_<input_image_name>.png.

Command:

python3.11 run.py --image <input_image_path> --class "<object_class_prompt>" --x <x_shift> --y <y_shift>

Example (Shift 50 pixels right, 50 pixels up):

python3.11 run.py --image example.jpg --class "red circle" --x 50 --y 50

Results and Analysis

Successful Experiment (Task 1 & 2)

Input Image Class Prompt Task Command Output Image
example.jpg (White background, red circle) "red circle" Task 1 --output masked_example.png masked_example.png (Red circle with red overlay)
example.jpg (White background, red circle) "red circle" Task 2 --x 50 --y 50 repositioned_example.png (Red circle shifted 50px right, 50px up)

The segmentation (Task 1) and repositioning (Task 2) logic work correctly for simple, high-contrast objects, demonstrating the core functionality of extracting and shifting the object based on the prompt and pixel values.

Failures and Improvements

Area Successes Failures Ideas for Improvement
Segmentation (Task 1) Successfully segments simple, distinct objects by generating a polygon mask via LLM. Reliability: LLM-based segmentation is not guaranteed to return a perfect polygon or a valid JSON object, especially for complex scenes or ambiguous prompts. Replace the LLM with a dedicated, robust zero-shot segmentation model like Grounded-SAM or SAM 3 (as referenced in the assignment) for higher accuracy and reliability.
Repositioning (Task 2) Correctly extracts the object and applies the pixel shift in the correct direction (+x right, +y up). Inpainting: The original object remains visible in the background (ghosting effect) because true inpainting was not possible. Integrate a dedicated Stable Diffusion Inpainting model (e.g., via a cloud API or local deployment) to seamlessly fill the void left by the moved object.
User Experience Simple command-line interface as requested. Requires an OpenAI API key and internet access for every operation. Implement a caching mechanism for segmentation masks to avoid repeated LLM calls for the same image/prompt combination.

Conclusion

The project successfully meets the core requirements of Task 1 (text-prompt segmentation and masking) and Task 2 (object repositioning via pixel shift) using a creative approach that leverages a vision-enabled LLM for the segmentation step. The primary limitation is the lack of a dedicated inpainting model, which results in a visible "ghost" of the original object in the background. This limitation is a direct result of tool constraints and is noted as the key area for future improvement.

About

An AI-driven post-production pipeline for e-commerce, enabling natural language object segmentation and precise spatial repositioning in product photography.

Resources

Readme
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.