Export contour annotations as geojson formatted data
Project description
cv2geojson
cv2geojson is an open source project to export annotation contours extracted using OpenCV-python package to GeoJSON format.
Introduction
In digital pathology, images are often quite large and dedicated software tools like QuPath are required to aid visualisation. The python package cv2geojson export contours detected using cv2.findContours
as polygons using GeoJSON format for visualisation in QuPath. For example, download the whole slide image with tissue sample ID GTEX-12584-1526 from histology page. This image has 45,815x38,091 pixels which requires about 5GB of storage uncompressed. Rather than storing a binary mask for the foreground segmentation, the mask can be converted to polygons and stored as a geojson file. The image below shows a snapshot from the QuPath software. The foreground contour is in blue.
Installation
The recommended way to install is via pip:
pip install cv2geojson
Example
Here is a dummy example to demonstrate the utility of cv2geojson package.
import cv2 as cv
from cv2geojson import find_geocontours, export_annotations
# read sample image
img = cv.imread('./example/img_01.png')
mask = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
# Extract annotation contours
geocontours = find_geocontours(mask, mode='imagej')
# convert geocontours to geojson.Feature format
features = [contour.export_feature(color=(0, 255, 0), label='roi') for contour in geocontours]
export_annotations(features, './example/img_01.geojson')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cv2geojson-0.0.6.tar.gz
.
File metadata
- Download URL: cv2geojson-0.0.6.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e137b02ebf6e3093100d0a32d0ae97f852c6e401ae757d5bf2f60fe03a1dc526 |
|
MD5 | dd6c3403aa192ed641da6a3c6bc6b887 |
|
BLAKE2b-256 | b772f0a325d9db45d03c48c3420d5b5901f6180297b3ca643f2b063da311ab93 |
File details
Details for the file cv2geojson-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: cv2geojson-0.0.6-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 495ca46215165710495f04c2eaabc2910a0ffb1f97de55d9547973a2f5794291 |
|
MD5 | bf31dc7f35d6e871bbad3432aa1c7cf8 |
|
BLAKE2b-256 | 701c85a7ff02bbc4a6bf94ad6bef4d4d2556dec335a8473714b70731258a7c3c |