# mask2bbox
[![PyPI](https://img.shields.io/pypi/v/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)
[![PyPI - License](https://img.shields.io/pypi/l/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)
[![main](https://github.com/saezlab/liana-py/actions/workflows/main.yml/badge.svg)](https://github.com/schapirolabor/mask2bbox/actions)
For a given mask, gets the coordinates of bounding box of each element of the mask. It will also allow for more operations in the future.
## Installation
```bash
pip install mask2bbox
```
## CLI
```bash
isolate-cells -h
isolate-cells-from-file -h
get-average-iou -h
```
## Usage
```python
import numpy as np
from mask2bbox import BBoxes
# Create a BBoxes object
all_boxes = BBoxes.from_mask("path/to/mask.png")
# Expand the bounding boxes
all_boxes = all_boxes.expand(n=10)
# Remove the bounding boxes that are located on the edge of the image
all_boxes = all_boxes.remove_from_edge()
# Get the sides of all the bounding boxes
sides = all_boxes.get("sides")
# Filter the bounding boxes by the sides
filtered_boxes = all_boxes.filter("sides", np.greater_equal, (35, 35))
# Get the IoU matrix of all the bounding boxes
iou = filtered_boxes.iou_matrix()
# Save the overlapping pairs to
filtered_boxes.save_overlapping_pairs("path/to/save/overlapping_pairs.csv")
# Save the IOU matrix to a csv file
filtered_boxes.save_iou_matrix("path/to/save/iou_matrix.csv")
# Plot the bounding boxes on the mask image
filtered_boxes.draw(to="image", method="matplotlib", show="False", save="path/to/save/image.png")
# Save your bounding boxes
filtered_boxes.save_csv("path/to/bounding_boxes.csv")
# Get resize factors to resize the bounding boxes to a given size
resize_factors = filtered_boxes.de(desired_ratio=0.7, size=(256, 256))
# Extract the bounding boxes as images
filtered_boxes.extract(resize_factors, size=(256, 256), output="path/to/save/images")
```
## License
mask2bbox offers a dual licensing mode the [GNU Affero General Public License v3.0](LICENSE) - see [LICENSE](LICENSE) and [ESSENTIAL_LICENSE_CONDITIONS.txt](ESSENTIAL_LICENSE_CONDITIONS.txt)
Raw data
{
"_id": null,
"home_page": null,
"name": "mask2bbox",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "cell, mask, bounding box",
"author": null,
"author_email": "\"Miguel A. Ibarra-Arellano\" <c180l058j@mozmail.com>",
"download_url": "https://files.pythonhosted.org/packages/4e/94/34b28daaf38ec2de29aad3496ca767e04890c82fe7b926c3a6ac2bad600e/mask2bbox-0.0.23.tar.gz",
"platform": null,
"description": "# mask2bbox\n[![PyPI](https://img.shields.io/pypi/v/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)\n[![PyPI - License](https://img.shields.io/pypi/l/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)\n[![main](https://github.com/saezlab/liana-py/actions/workflows/main.yml/badge.svg)](https://github.com/schapirolabor/mask2bbox/actions)\n\nFor a given mask, gets the coordinates of bounding box of each element of the mask. It will also allow for more operations in the future.\n\n## Installation\n\n```bash\npip install mask2bbox\n```\n\n## CLI\n\n```bash\nisolate-cells -h\nisolate-cells-from-file -h\nget-average-iou -h\n```\n\n## Usage\n\n```python\nimport numpy as np\nfrom mask2bbox import BBoxes\n\n# Create a BBoxes object\nall_boxes = BBoxes.from_mask(\"path/to/mask.png\")\n\n# Expand the bounding boxes\nall_boxes = all_boxes.expand(n=10)\n\n# Remove the bounding boxes that are located on the edge of the image\nall_boxes = all_boxes.remove_from_edge()\n\n# Get the sides of all the bounding boxes\nsides = all_boxes.get(\"sides\")\n\n# Filter the bounding boxes by the sides\nfiltered_boxes = all_boxes.filter(\"sides\", np.greater_equal, (35, 35))\n\n# Get the IoU matrix of all the bounding boxes\niou = filtered_boxes.iou_matrix()\n\n# Save the overlapping pairs to\nfiltered_boxes.save_overlapping_pairs(\"path/to/save/overlapping_pairs.csv\")\n\n# Save the IOU matrix to a csv file\nfiltered_boxes.save_iou_matrix(\"path/to/save/iou_matrix.csv\") \n\n# Plot the bounding boxes on the mask image\nfiltered_boxes.draw(to=\"image\", method=\"matplotlib\", show=\"False\", save=\"path/to/save/image.png\")\n\n# Save your bounding boxes\nfiltered_boxes.save_csv(\"path/to/bounding_boxes.csv\")\n\n# Get resize factors to resize the bounding boxes to a given size\nresize_factors = filtered_boxes.de(desired_ratio=0.7, size=(256, 256))\n\n# Extract the bounding boxes as images\nfiltered_boxes.extract(resize_factors, size=(256, 256), output=\"path/to/save/images\")\n```\n\n## License\n\nmask2bbox offers a dual licensing mode the [GNU Affero General Public License v3.0](LICENSE) - see [LICENSE](LICENSE) and [ESSENTIAL_LICENSE_CONDITIONS.txt](ESSENTIAL_LICENSE_CONDITIONS.txt)\n",
"bugtrack_url": null,
"license": "AGPL-3.0-or-later",
"summary": "Gets the bounding boxes from a mask file.",
"version": "0.0.23",
"project_urls": {
"Homepage": "https://github.com/SchapiroLabor/mask2bbox",
"Issues": "https://github.com/SchapiroLabor/mask2bbox/issues"
},
"split_keywords": [
"cell",
" mask",
" bounding box"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2481700b6d141941e65b5a80b7eb7ee181d027b95ede11294a5cf069c3e67846",
"md5": "97167c0838ca9a286daadbb81d376a47",
"sha256": "794cf8ea6d273793113f265b3bef066eb6c0831f73401cbef708837bd4610c34"
},
"downloads": -1,
"filename": "mask2bbox-0.0.23-py3-none-any.whl",
"has_sig": false,
"md5_digest": "97167c0838ca9a286daadbb81d376a47",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 29920,
"upload_time": "2024-08-02T12:13:59",
"upload_time_iso_8601": "2024-08-02T12:13:59.076921Z",
"url": "https://files.pythonhosted.org/packages/24/81/700b6d141941e65b5a80b7eb7ee181d027b95ede11294a5cf069c3e67846/mask2bbox-0.0.23-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4e9434b28daaf38ec2de29aad3496ca767e04890c82fe7b926c3a6ac2bad600e",
"md5": "c4cfd99265aa802abcb2cc9457be1436",
"sha256": "df8d867b9d207d28caa59c15b0c8e817d257f5ce4e24060bc6d47e7441b8ad90"
},
"downloads": -1,
"filename": "mask2bbox-0.0.23.tar.gz",
"has_sig": false,
"md5_digest": "c4cfd99265aa802abcb2cc9457be1436",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 26978,
"upload_time": "2024-08-02T12:14:00",
"upload_time_iso_8601": "2024-08-02T12:14:00.466303Z",
"url": "https://files.pythonhosted.org/packages/4e/94/34b28daaf38ec2de29aad3496ca767e04890c82fe7b926c3a6ac2bad600e/mask2bbox-0.0.23.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-02 12:14:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SchapiroLabor",
"github_project": "mask2bbox",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "mask2bbox"
}