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.1.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.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: segment_animals-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b5180b6598db5f8eddc810feae37ff1a469734bc7c3b7146b62290aee319d46e
MD5 b9aaa93aeab3b29a579fc251499b5574
BLAKE2b-256 911b7d5aaa3636a09c339a669384c09f357cf8ab89c502574a439bc8379192e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: segment_animals-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9fac3d3cb120b374626812c9b99feb743a981951501d85e366953760f6c3acc3
MD5 0c79473eae9da9f1e3da1ce36e5ef78d
BLAKE2b-256 7d31610fb6a245a2d1a668a9bd64263824e9fd1a32395921e4649950ceb9e7f1

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.2

2 files

This release

1.1.1 This release

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