Skip to main content

A tool for annotating images with polygons and rectangles, supporting multi-dimensional images and SAM2-assisted annotations

Project description

DigitalSreeni Image Annotator

Python Version License PyPI version

A powerful and user-friendly tool for annotating images with polygons and rectangles, built with PyQt5.

DigitalSreeni Image Annotator Demo

@DigitalSreeni Dr. Sreenivas Bhattiprolu

Features

  • Semi-automated annotations with SAM-2 assistance (Segment Anything Model) — Because who doesn't love a helpful AI sidekick?
  • Manual annotations with polygons and rectangles — For when you want to show SAM-2 who's really in charge.
  • Save annotations in COCO-compatible JSON format.
  • Edit existing annotations.
  • Load and continue previous annotation work.
  • Handle multi-dimensional images (TIFF stacks and CZI files).
  • Zoom and pan for detailed annotations.
  • Support for multiple classes with customizable colors.
  • Import and export annotations.
  • User-friendly interface with intuitive controls.
  • Change the application font size on the fly — Make your annotations as big or small as your caffeine level requires.
  • Dark mode for those late-night annotation marathons — Who needs sleep when you have dark mode?
  • NEW: Load custom SAM2 pre-trained models for flexible and improved semi-automated annotations.

Installation

You can install the DigitalSreeni Image Annotator directly from PyPI:

pip install digitalsreeni-image-annotator

Important: PyQt5 Requirement

This application requires PyQt5 version 5.15.7 or higher. If you encounter any issues related to PyQt5, you may need to install or upgrade it separately:

pip install PyQt5>=5.15.7

If you're using an older version of PyQt5, please upgrade to ensure compatibility:

pip install --upgrade PyQt5>=5.15.7

On some systems, especially Linux, you might need to install additional system packages. For example, on Ubuntu or Debian:

sudo apt-get install python3-pyqt5

Note that the system package manager might not always provide the latest version. In such cases, using pip as shown above is recommended.

For other operating systems or if you encounter any issues, please refer to the PyQt5 documentation.

SAM-2 Installation for Semi-Automated Annotations

To use the Segment Anything Model (SAM-2) assisted annotations feature, you need to install PyTorch and SAM-2 libraries. Follow these steps:

  1. Install PyTorch:

  2. Install SAM-2:

    • Visit the SAM-2 repository: https://github.com/facebookresearch/segment-anything-2
    • Follow these key steps: a. Open a console (command prompt). We recommend using Anaconda Prompt for easy environment management. b. Ensure you're in the right environment. If needed, create a new environment with the specified Python version and activate it. c. Change directory to where you want to download the repository (e.g., your Downloads folder). d. Clone the SAM-2 repository:
      git clone https://github.com/facebookresearch/segment-anything-2.git
      
      (This assumes you have Git installed. On Windows, you can use Git for Windows: https://gitforwindows.org/) e. Change to the repository directory:
      cd segment-anything-2
      
      f. Install SAM-2:
      pip install .
      
      (Note: Do not use pip install -e . if you intend to delete the downloaded repository after installation)

Your system is now ready to use SAM-2 for semi-automated annotations.

Usage

  1. Run the DigitalSreeni Image Annotator application:

    digitalsreeni-image-annotator
    

    or

    sreeni
    

    or

    python -m digitalsreeni_image_annotator.main
    
  2. Using the application:

    • Click "Open New Image Set" to load a new set of images from your computer.
    • Use "Add More Images" to append images to the current set.
    • Add classes using the "Add Class" button.
    • Select a class and use the Polygon or Rectangle tool to create manual annotations.
    • To use SAM2 Magic Wand:
      • Click "Load SAM2 Model" and select the config (.yaml) and model (.pt) files.
      • Select the SAM2 Magic Wand button and draw a rectangle around your object of interest for automated annotation.
    • Edit existing annotations by double-clicking on them.
    • Save your annotations using the "Save Annotations" button.
    • Use "Import Saved Annotations" to load previously created annotations.
    • Access the help documentation by clicking the "Help" button.
    • Explore the interface – you might stumble upon some hidden gems and secret features!
  3. Keyboard shortcuts:

    • Use the mouse wheel or trackpad to zoom in/out
    • Hold Ctrl and drag to pan the image
    • Press 'Esc' to cancel the current annotation
    • Press 'Enter' to finish the current polygon annotation or accept a SAM2-generated mask

Development

For development purposes, you can clone the repository and install it in editable mode:

  1. Clone the repository:

    git clone https://github.com/bnsreenu/digitalsreeni-image-annotator.git
    cd digitalsreeni-image-annotator
    
  2. Create a virtual environment (optional but recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
    
  3. Install the package and its dependencies in editable mode:

    pip install -e .
    

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Thanks to all my YouTube subscribers who inspired me to work on this project
  • Inspired by the need for efficient image annotation in computer vision tasks

Contact

Dr. Sreenivas Bhattiprolu - @DigitalSreeni

Project Link: https://github.com/bnsreenu/digitalsreeni-image-annotator

Citing

If you use this software in your research, please cite it as follows:

Bhattiprolu, S. (2024). DigitalSreeni Image Annotator [Computer software]. https://github.com/bnsreenu/digitalsreeni-image-annotator

@software{digitalsreeni_image_annotator,
  author = {Bhattiprolu, Sreenivas},
  title = {DigitalSreeni Image Annotator},
  year = {2024},
  url = {https://github.com/bnsreenu/digitalsreeni-image-annotator}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

digitalsreeni_image_annotator-0.3.1.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file digitalsreeni_image_annotator-0.3.1.tar.gz.

File metadata

File hashes

Hashes for digitalsreeni_image_annotator-0.3.1.tar.gz
Algorithm Hash digest
SHA256 448ff4bc83904e9c7cf1108f6652e25cbc10655f182fe37504791be9be2d6c07
MD5 18029d751bca3e22dc7048e33ecc9eef
BLAKE2b-256 e60737e95884af20f7ee63512f5ab317c191e8bd7a42a9a258d23397696b3201

See more details on using hashes here.

File details

Details for the file digitalsreeni_image_annotator-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for digitalsreeni_image_annotator-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c37df90f48ce0b76352a4c57197224b366c82b352993849db3820feb01cf741e
MD5 b9257d86922eac446ef2d20ff8bf8385
BLAKE2b-256 37472bd6d551b40d89b5eccc50e06b711999008e23de3442002c2cbdb799a9f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page