Skip to main content

Segment Animals

Segment Animals is a Python package for segmenting (extracting) animals from images using deep learning models. It provides a pipeline that combines object detection and segmentation to identify and extract animals from images, making it useful for wildlife research, conservation efforts, and any application where you wish to remove the background from images containing animals.

Segment Animals builds upon the Segment Anything and MegaDetector models.

Installation

You can install Segment Animals using pip:

pip install segment-animals

Usage

Here's a quick example of how to use Segment Animals, for a more detailed guide refer to the notebook.

Importing the library and processing an image

from segment_animals import AutoAnimalSegmenter
from segment_animals.util import load_image

model = AutoAnimalSegmenter()

image = load_image("path/to/your/image.jpg")

detections, masks = model.process_image(image)
print(f"Found {len(detections)} animals.")

Visualizing detections and masks

from segment_animals.viz import plot_detections_and_masks

plot_detections_and_masks(image, detections, masks)

You should then see a visualisation along the lines of this (original image from Wikipedia)...

Example Segmentation

Extracting and saving masks

from segment_animals.viz import extract_masks

# Setting whole_image to False will return individual masks cropped to the extent
# of the predicted masks.
for i, mask_extract in enumerate(extract_masks(image, masks, whole_image=False)):
    # mask_extract is a PIL Image object so you can save it or manipulate it further
    mask_extract.save(f"animal_mask_{i}.png")

Resulting in something like this:

Example Mask

Working with Segment Animals?

It'd be great to hear how you're using Segment Animals! Drop me a line at Benjamin.Evans at ioz.ac.uk or open an issue on the GitHub repository.

Download files

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

Source Distribution

segment_animals-1.1.2.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

segment_animals-1.1.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file segment_animals-1.1.2.tar.gz.

File metadata

  • Download URL: segment_animals-1.1.2.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for segment_animals-1.1.2.tar.gz
Algorithm Hash digest
SHA256 8422b19da320fbcd66a3df6d4b6b07bf3488d34858d02466c781843ce9316ce7
MD5 cc2c1bc024b2ba2ce416fb6290f90ef5
BLAKE2b-256 ef29ffdeb411df0c6d1a212218481d7c54baf280c8dcfbab5153d10a2e5f4bc3

See more details on using hashes here.

File details

Details for the file segment_animals-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: segment_animals-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for segment_animals-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f22797073a875741325cde2abdc82fa9e2a0e802e5ad2f221ec577a6dc488da0
MD5 1a592a2339bca8a7e83319e435f660b2
BLAKE2b-256 bdc6e4dca6f0db7aed427ff2d9a14c0a05d38f36b369d67b43a66fa8e6b37483

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page