Skip to main content

Trace and label skeleton of a 2D image.

Project description

The trace_skeleton Python package

A python package for tracing the skeleton of a 2D image. This work uses the Skeleton Tracing algorithm developed by LingDong. This repo provides an easy to install python package for tracing the skeleton. This is done to ease the use of the algorithm in other Python projects. We've taken the SWIG C implementation for optimal performance.

Usage

Quick and easy installation:

pip install trace-skeleton

Example

The examples shown are a copy-paste from the original repo.

import trace_skeleton
import cv2
import random

im = cv2.imread("../test_images/opencv-thinning-src-img.png",0)

_,im = cv2.threshold(im,128,255,cv2.THRESH_BINARY);

polys = trace_skeleton.from_numpy(im);

for l in polys:
	c = (200*random.random(),200*random.random(),200*random.random())
	for i in range(0,len(l)-1):
		cv2.line(im,(l[i][0],l[i][1]),(l[i+1][0],l[i+1][1]),c)

cv2.imshow('',im);cv2.waitKey(0)

Advanced

The aforementioned API's have a tiny linear time overhead for transforming input and output between internal datastructures and python objects. Alternatively, you can use the following:

from trace_skeleton import *

im = "\0\1\0\0\1\0\0\1\0 ..... " #image stored as a (char*)
w = 128 #dimensions
h = 64

trace(im,w,h)

# iterate over each point in each polyline
# by popping them off the internal datastructure
# len_polyline() gets the length of current polyline
# -1 means no more polylines
while (len_polyline() != -1):
	n = len_polyline();
	for i in range(0,n):
		# pop_point() retrieve and remove the next point
		# on the polyline. It returns the flat index in image
		# mod/div it with width to get (x,y) coordinate
		idx = pop_point()
		x = idx % w;
		y = idx //w;
		print(x,y)
	print("\n")

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

trace_skeleton-0.1.6.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trace_skeleton-0.1.6-cp39-cp39-macosx_10_9_x86_64.whl (20.5 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

Details for the file trace_skeleton-0.1.6.tar.gz.

File metadata

  • Download URL: trace_skeleton-0.1.6.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for trace_skeleton-0.1.6.tar.gz
Algorithm Hash digest
SHA256 7337a6b55b127f1193f9af9c95127b89417d85dce413bf727268c632d85a9827
MD5 6cee5a1ab2fc8eb5f4961fe6c76dcf5f
BLAKE2b-256 b87bbb6a6df54f192136dc7da619eb0dd05a225f68b0fee7dc97ba1ebca78bbf

See more details on using hashes here.

File details

Details for the file trace_skeleton-0.1.6-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for trace_skeleton-0.1.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8c66b68879e8e84a0263283fe99d03c1b18fb12fd46fc45ae88f6a107af68dc3
MD5 22fac586e862b8235beed77bc4214622
BLAKE2b-256 b5bef53b83ec3364066376f45ce8a94eb6c7d0bfd731b17f88450389f049f8e1

See more details on using hashes here.

Supported by

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