segment-animals 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # Project-specific files
13
+ *.jpg
14
+ *.png
15
+ *.webp
16
+ *.pth
@@ -0,0 +1 @@
1
+ 3.10
@@ -0,0 +1,75 @@
1
+ Metadata-Version: 2.4
2
+ Name: segment-animals
3
+ Version: 1.0.0
4
+ Summary: Segment (Extract) Animals from Images - Removing Background
5
+ Author-email: Ben Evans <ben@bluechimp.io>
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: megadetector>=5.0.29
8
+ Requires-Dist: pillow>=11.2.1
9
+ Requires-Dist: requests>=2.32.4
10
+ Requires-Dist: segment-anything
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Segment Animals
14
+
15
+ 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.
16
+
17
+ Segment Animals builds upon the [Segment Anything](https://github.com/facebookresearch/segment-anything) and [MegaDetector](https://github.com/agentmorris/MegaDetector/blob/main/getting-started.md) models.
18
+
19
+ # Installation
20
+
21
+ You can install Segment Animals using pip:
22
+
23
+ ```bash
24
+ pip install segment-animals
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Here's a quick example of how to use Segment Animals, for a more detailed guide refer to the [notebook](./notebook.ipynb).
30
+
31
+ ### Importing the library and processing an image
32
+
33
+ ```python
34
+ from segment_animals import AutoAnimalSegmenter
35
+ from segment_animals.util import load_image
36
+
37
+ model = AutoAnimalSegmenter()
38
+
39
+ image = load_image("path/to/your/image.jpg")
40
+
41
+ detections, masks = model.process_image(image)
42
+ print(f"Found {len(detections)} animals.")
43
+ ```
44
+
45
+ ### Visualizing detections and masks
46
+
47
+ ```python
48
+ from segment_animals.viz import plot_detections_and_masks
49
+
50
+ plot_detections_and_masks(image, detections, masks)
51
+ ```
52
+
53
+ You should then see a visualisation along the lines of this ([original image from Wikipedia](https://commons.wikimedia.org/wiki/File:Camouflaged_Predator.jpg))...
54
+
55
+ ![Example Segmentation](./example_viz.png)
56
+
57
+ ### Extracting and saving masks
58
+
59
+ ```python
60
+ from segment_animals.viz import extract_masks
61
+
62
+ # Setting whole_image to False will return individual masks cropped to the extent
63
+ # of the predicted masks.
64
+ for i, mask_extract in enumerate(extract_masks(image, masks, whole_image=False)):
65
+ # mask_extract is a PIL Image object so you can save it or manipulate it further
66
+ mask_extract.save(f"animal_mask_{i}.png")
67
+ ```
68
+
69
+ Resulting in something like this:
70
+
71
+ ![Example Mask](./example_extract.png)
72
+
73
+ # Working with Segment Animals?
74
+
75
+ 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](https://github.com/bencevans/segment-animals/issues).
@@ -0,0 +1,63 @@
1
+ # Segment Animals
2
+
3
+ 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.
4
+
5
+ Segment Animals builds upon the [Segment Anything](https://github.com/facebookresearch/segment-anything) and [MegaDetector](https://github.com/agentmorris/MegaDetector/blob/main/getting-started.md) models.
6
+
7
+ # Installation
8
+
9
+ You can install Segment Animals using pip:
10
+
11
+ ```bash
12
+ pip install segment-animals
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Here's a quick example of how to use Segment Animals, for a more detailed guide refer to the [notebook](./notebook.ipynb).
18
+
19
+ ### Importing the library and processing an image
20
+
21
+ ```python
22
+ from segment_animals import AutoAnimalSegmenter
23
+ from segment_animals.util import load_image
24
+
25
+ model = AutoAnimalSegmenter()
26
+
27
+ image = load_image("path/to/your/image.jpg")
28
+
29
+ detections, masks = model.process_image(image)
30
+ print(f"Found {len(detections)} animals.")
31
+ ```
32
+
33
+ ### Visualizing detections and masks
34
+
35
+ ```python
36
+ from segment_animals.viz import plot_detections_and_masks
37
+
38
+ plot_detections_and_masks(image, detections, masks)
39
+ ```
40
+
41
+ You should then see a visualisation along the lines of this ([original image from Wikipedia](https://commons.wikimedia.org/wiki/File:Camouflaged_Predator.jpg))...
42
+
43
+ ![Example Segmentation](./example_viz.png)
44
+
45
+ ### Extracting and saving masks
46
+
47
+ ```python
48
+ from segment_animals.viz import extract_masks
49
+
50
+ # Setting whole_image to False will return individual masks cropped to the extent
51
+ # of the predicted masks.
52
+ for i, mask_extract in enumerate(extract_masks(image, masks, whole_image=False)):
53
+ # mask_extract is a PIL Image object so you can save it or manipulate it further
54
+ mask_extract.save(f"animal_mask_{i}.png")
55
+ ```
56
+
57
+ Resulting in something like this:
58
+
59
+ ![Example Mask](./example_extract.png)
60
+
61
+ # Working with Segment Animals?
62
+
63
+ 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](https://github.com/bencevans/segment-animals/issues).