mask2bbox


Namemask2bbox JSON
Version 0.0.18 PyPI version JSON
download
home_page
SummaryGets the bounding boxes from a mask file.
upload_time2024-03-01 13:23:33
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords cell mask bounding box
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # mask2bbox
[![PyPI](https://img.shields.io/pypi/v/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)

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.

## Instalation

```bash
pip install mask2bbox
```

## CLI

```bash
python isolate-cells -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")
```

## Version Notes

### 0.0.15 - Update
- Update:
  - Add new entry points to the package to allow for improved CLI usage. New CLI usage is:`python isolate-cells -h`.
- Add:
  - Add `mask2bbox/scripts` folder.

### 0.0.14 - Update
- Update:
  - Remove LICENSE
  - Rename `BBoxes.save_iou()` to `BBoxes.save_overlapping_pairs()` in the CLI.
  - Convert `BBoxes._helper_box_drawer()` to static method.
- Add:
  - Add logger to the package.
  - Add `BBoxes.sample()` to get a random sample of the bounding boxes.
  - Add `BBoxes.save_iou_matrix()` to save the IoU matrix to a csv file.
  - Add `-os` to the CLI to save a sample of the isolated nuclei instead of the whole set.
  - Add `-log` to speciy the log level in the CLI (Options are: info and debug).

### 0.0.13 - Update
- Update:
  - Change setup.py to pyproject.toml.
- Add:
  - Added entry points to the package to allow for CLI usage.
  - Added dynamic versioning to the package `version.py` also accessible from the CLI `python -m mask2bbox -v`.

### 0.0.12 - Update
- Update:
  - `BBoxes.from_mask()` now accepts an image parameter as an additional input, this removes the need of having to load the image separately.
  - `__getitem__` magic attribute indexes based on the cell/mask id (making it base 1 instead of base 0).
- Replaced `BBoxes.extract_single()` and `BBoxes.grab()` -> with `BBoxes.grab_pixels_from()`
  - `BBoxes.grab_pixels_from()` gets the pixels from the image/mask that are inside the bounding boxes.
  - `BBoxes.grab_pixels_from()` makes optional the processing steps implemented in `BBoxes.extract()`.

### 0.0.11 - Added functionality
- Added `BBoxes.grab()`
- Replaced `plot_to_mask()`  and `BBoxes.plot_to_image()` -> with `BBoxes.draw()` 
  - `BBoxes.draw()` allows to plot the bounding boxes on the mask or the image.
  - `BBoxes.draw()` allows to choose between `matplotlib` and `numpy` to generate the plot.
- Modified `BBoxes.extract_single()`
  - `BBoxes.extract_single()` adds pre-processing steps such as `BBoxes.extract()`

### 0.0.10 - Added functionality
- Added `extract_single()`: This method allows to extract a single bounding box form the image/mask.
- Added check to `BBoxes.from_mask()`: Now the method checks if the mask contains any element or not and raises an error if it doesn't.

### 0.0.9 - Fix bug in `BBoxes.extract()`
- Fix bug in `BBoxes.extract()` that caused the images to be saved with the wrong name amd created a new folder.

### 0.0.8 - Change methods, change constructor, added functionality. 
- **Constructor:** BBox object is now constructed with the syntax `BBoxes.from_mask(mask)` instead of `BBoxes(mask)`.
- **Operations:** BBox object operations are no longer performed in place, the affected methods are:
  - `BBoxes.remove_from_edge()`
  - `BBoxes.expand()`
  - `BBoxes.filter()`

- **Removed methods:**
  - `is_area_smaller_than()`
  - `is_area_larger_than()`
  - `are_dims_smaller_than()`
  - `are_dims_larger_than()`
  - `filter_identities()`  

These methods used in-place operations and are no longer needed, they were substituted with.  
- **Renamed:**
  - `BBoxes.get_bbox_areas()` -> `BBoxes.get_areas()`
  - `BBoxes.get_bbox_dims()` -> `BBoxes.get_sizes()`
  - `BBoxes.get_bbox_centers()` -> `BBoxes.get_centers()`
  - `BBoxes.get_bbox_ratios()` -> `BBoxes.get_ratios()`
  
- **New methods:**
  - `BBoxes.filter():` This method allows to filter the bounding boxes by any of the attributes in the object specifying the comparison operator and threshold value. It returns a new BBoxes object with the filtered values.
  - `BBoxes.get():` This method allows to get the values of the attributes in the object. It works as a simplification to `BBoxes.get_areas()`, `BBoxes.get_centers()`, `BBoxes.get_sizes()` and `BBoxes.get_ratios()`.
  - `BBoxes.extract():` This new method isolates the bounding boxes as images and saves them to the desired location.
  - `BBoxes.calculate_resizing_factor():` This method calculates the resizing factor needed to resize the bounding boxes to a given size.
  - `BBoxes._pad_crop():` Helper method to pad or crop the bounding boxes to a desired output size.
  - `BBoxes.plot_to_image():` This method plots the bounding boxes to the corresponding image and saves it to the desired location.


### 0.0.7 - Improved functionality
Improvements in IoU calculation

### 0.0.6 - Added functionality

### 0.0.5 - Added functionality

- IoU related operations:
  - `boxes.get_iou_matrix()` - Gets the IoU of all the bounding boxes.
  - `boxes.are_overlaping()` - Returns identities where the IoU is greater than 0
  - `boxes.overlaping_pais()` - Returns the pairs of bounding boxes that are overlaping.
  - `boxes.save_iou()` - Saves the IoU matrix to a csv file.

- Plots
  - `boxes.plot_to_mask()` Plots the bounding boxes on the mask image.

Example of `boxes.plot_to_mask()`
![](tests/plot.png)

### 0.0.4 - Added functionality
Now is possible to extract:
- Bounding boxes dimensions `BBoxes.get_bbox_dims()`
- Bounding boxes area `BBoxes.get_bbox_areas()`
- Bounding boxes center `BBoxes.get_bbox_centers()`
- Bounding boxes ratios `BBoxes.get_bbox_ratios()`

### 0.0.3 - Added functionality  
Added the remove_edge_boxes method to remove the bounding boxes that are located on the edge of the image.

### 0.0.2 - Added the expand method to expand the bounding boxes by a given number of pixels.
Added the expand method to expand the bounding boxes by a given number of pixels.  
Fixed a bug in the setup.py file that made it hard to import the package.

### 0.0.1 - Initial release of the package.
Initial release of the package. It allows to get the bounding boxes of a mask and save them to a csv file.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mask2bbox",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "cell,mask,bounding box",
    "author": "",
    "author_email": "\"Miguel A. Ibarra-Arellano\" <c180l058j@mozmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/19/7d/aca9f542d2483157151825d9cd48ff6d794fc144d01c5f0ca526cb9507bc/mask2bbox-0.0.18.tar.gz",
    "platform": null,
    "description": "# mask2bbox\n[![PyPI](https://img.shields.io/pypi/v/mask2bbox?style=flat-square)](https://pypi.org/project/mask2bbox/)\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## Instalation\n\n```bash\npip install mask2bbox\n```\n\n## CLI\n\n```bash\npython isolate-cells -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## Version Notes\n\n### 0.0.15 - Update\n- Update:\n  - Add new entry points to the package to allow for improved CLI usage. New CLI usage is:`python isolate-cells -h`.\n- Add:\n  - Add `mask2bbox/scripts` folder.\n\n### 0.0.14 - Update\n- Update:\n  - Remove LICENSE\n  - Rename `BBoxes.save_iou()` to `BBoxes.save_overlapping_pairs()` in the CLI.\n  - Convert `BBoxes._helper_box_drawer()` to static method.\n- Add:\n  - Add logger to the package.\n  - Add `BBoxes.sample()` to get a random sample of the bounding boxes.\n  - Add `BBoxes.save_iou_matrix()` to save the IoU matrix to a csv file.\n  - Add `-os` to the CLI to save a sample of the isolated nuclei instead of the whole set.\n  - Add `-log` to speciy the log level in the CLI (Options are: info and debug).\n\n### 0.0.13 - Update\n- Update:\n  - Change setup.py to pyproject.toml.\n- Add:\n  - Added entry points to the package to allow for CLI usage.\n  - Added dynamic versioning to the package `version.py` also accessible from the CLI `python -m mask2bbox -v`.\n\n### 0.0.12 - Update\n- Update:\n  - `BBoxes.from_mask()` now accepts an image parameter as an additional input, this removes the need of having to load the image separately.\n  - `__getitem__` magic attribute indexes based on the cell/mask id (making it base 1 instead of base 0).\n- Replaced `BBoxes.extract_single()` and `BBoxes.grab()` -> with `BBoxes.grab_pixels_from()`\n  - `BBoxes.grab_pixels_from()` gets the pixels from the image/mask that are inside the bounding boxes.\n  - `BBoxes.grab_pixels_from()` makes optional the processing steps implemented in `BBoxes.extract()`.\n\n### 0.0.11 - Added functionality\n- Added `BBoxes.grab()`\n- Replaced `plot_to_mask()`  and `BBoxes.plot_to_image()` -> with `BBoxes.draw()` \n  - `BBoxes.draw()` allows to plot the bounding boxes on the mask or the image.\n  - `BBoxes.draw()` allows to choose between `matplotlib` and `numpy` to generate the plot.\n- Modified `BBoxes.extract_single()`\n  - `BBoxes.extract_single()` adds pre-processing steps such as `BBoxes.extract()`\n\n### 0.0.10 - Added functionality\n- Added `extract_single()`: This method allows to extract a single bounding box form the image/mask.\n- Added check to `BBoxes.from_mask()`: Now the method checks if the mask contains any element or not and raises an error if it doesn't.\n\n### 0.0.9 - Fix bug in `BBoxes.extract()`\n- Fix bug in `BBoxes.extract()` that caused the images to be saved with the wrong name amd created a new folder.\n\n### 0.0.8 - Change methods, change constructor, added functionality. \n- **Constructor:** BBox object is now constructed with the syntax `BBoxes.from_mask(mask)` instead of `BBoxes(mask)`.\n- **Operations:** BBox object operations are no longer performed in place, the affected methods are:\n  - `BBoxes.remove_from_edge()`\n  - `BBoxes.expand()`\n  - `BBoxes.filter()`\n\n- **Removed methods:**\n  - `is_area_smaller_than()`\n  - `is_area_larger_than()`\n  - `are_dims_smaller_than()`\n  - `are_dims_larger_than()`\n  - `filter_identities()`  \n\nThese methods used in-place operations and are no longer needed, they were substituted with.  \n- **Renamed:**\n  - `BBoxes.get_bbox_areas()` -> `BBoxes.get_areas()`\n  - `BBoxes.get_bbox_dims()` -> `BBoxes.get_sizes()`\n  - `BBoxes.get_bbox_centers()` -> `BBoxes.get_centers()`\n  - `BBoxes.get_bbox_ratios()` -> `BBoxes.get_ratios()`\n  \n- **New methods:**\n  - `BBoxes.filter():` This method allows to filter the bounding boxes by any of the attributes in the object specifying the comparison operator and threshold value. It returns a new BBoxes object with the filtered values.\n  - `BBoxes.get():` This method allows to get the values of the attributes in the object. It works as a simplification to `BBoxes.get_areas()`, `BBoxes.get_centers()`, `BBoxes.get_sizes()` and `BBoxes.get_ratios()`.\n  - `BBoxes.extract():` This new method isolates the bounding boxes as images and saves them to the desired location.\n  - `BBoxes.calculate_resizing_factor():` This method calculates the resizing factor needed to resize the bounding boxes to a given size.\n  - `BBoxes._pad_crop():` Helper method to pad or crop the bounding boxes to a desired output size.\n  - `BBoxes.plot_to_image():` This method plots the bounding boxes to the corresponding image and saves it to the desired location.\n\n\n### 0.0.7 - Improved functionality\nImprovements in IoU calculation\n\n### 0.0.6 - Added functionality\n\n### 0.0.5 - Added functionality\n\n- IoU related operations:\n  - `boxes.get_iou_matrix()` - Gets the IoU of all the bounding boxes.\n  - `boxes.are_overlaping()` - Returns identities where the IoU is greater than 0\n  - `boxes.overlaping_pais()` - Returns the pairs of bounding boxes that are overlaping.\n  - `boxes.save_iou()` - Saves the IoU matrix to a csv file.\n\n- Plots\n  - `boxes.plot_to_mask()` Plots the bounding boxes on the mask image.\n\nExample of `boxes.plot_to_mask()`\n![](tests/plot.png)\n\n### 0.0.4 - Added functionality\nNow is possible to extract:\n- Bounding boxes dimensions `BBoxes.get_bbox_dims()`\n- Bounding boxes area `BBoxes.get_bbox_areas()`\n- Bounding boxes center `BBoxes.get_bbox_centers()`\n- Bounding boxes ratios `BBoxes.get_bbox_ratios()`\n\n### 0.0.3 - Added functionality  \nAdded the remove_edge_boxes method to remove the bounding boxes that are located on the edge of the image.\n\n### 0.0.2 - Added the expand method to expand the bounding boxes by a given number of pixels.\nAdded the expand method to expand the bounding boxes by a given number of pixels.  \nFixed a bug in the setup.py file that made it hard to import the package.\n\n### 0.0.1 - Initial release of the package.\nInitial release of the package. It allows to get the bounding boxes of a mask and save them to a csv file.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Gets the bounding boxes from a mask file.",
    "version": "0.0.18",
    "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": "62f8f9edbdb7307c7dd1cfad1ba3a460e322cae49574f13de0cecf15a28f7144",
                "md5": "f60df188635f0880a167d3c7b1ad1249",
                "sha256": "f5f2ea7a52eed6c8d3d3471bbd82101c793c150276cc335ad54cf06fb2040946"
            },
            "downloads": -1,
            "filename": "mask2bbox-0.0.18-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f60df188635f0880a167d3c7b1ad1249",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 15982,
            "upload_time": "2024-03-01T13:23:32",
            "upload_time_iso_8601": "2024-03-01T13:23:32.490914Z",
            "url": "https://files.pythonhosted.org/packages/62/f8/f9edbdb7307c7dd1cfad1ba3a460e322cae49574f13de0cecf15a28f7144/mask2bbox-0.0.18-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "197daca9f542d2483157151825d9cd48ff6d794fc144d01c5f0ca526cb9507bc",
                "md5": "e63ff4fc22c62fc53f48e8d3848cde05",
                "sha256": "fd6fc5a7f8ee6c64e856e0514db2a0a3405186e65af6e1c18931fc97e4111474"
            },
            "downloads": -1,
            "filename": "mask2bbox-0.0.18.tar.gz",
            "has_sig": false,
            "md5_digest": "e63ff4fc22c62fc53f48e8d3848cde05",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16737,
            "upload_time": "2024-03-01T13:23:33",
            "upload_time_iso_8601": "2024-03-01T13:23:33.977163Z",
            "url": "https://files.pythonhosted.org/packages/19/7d/aca9f542d2483157151825d9cd48ff6d794fc144d01c5f0ca526cb9507bc/mask2bbox-0.0.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-01 13:23:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SchapiroLabor",
    "github_project": "mask2bbox",
    "github_not_found": true,
    "lcname": "mask2bbox"
}
        
Elapsed time: 0.19366s