Skip to main content

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 blue.

QuPath Snapshot 2
Snapshot from QuPath software visualising foreground segmentation

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')

QuPath Snapshot 2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cv2geojson-0.0.8.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

cv2geojson-0.0.8-py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page