Skip to main content

Calculate Feret diameter.

Project description

Feret: A Python Module to calculate the Feret Diameter of Binary Images

Downloads

This python module can calculate the following parameters for binary images:

  • maximum Feret diameter (maxferet, maxf)
  • minimum Feret diameter (minferet, minf)
  • Feret diameter 90 ° to the minferet (minferet90, minf90)
  • Feret diameter 90 ° to maxferet (maxferet90, maxf90)

See this Wikipedia page to get the definition of those parameters.

This module gives the exact results as ImageJ (use edge=True as shown below), all the parameters are exactly calculated and not approximated.

Installations

This project is available via pip:

pip install feret

Pieces of Information

Convex Hull

The definition of the maxferet and minferet uses the image of a caliper. Therefore, only the points which correspond to the convex hull of the object play a role. That is why before any calculations the convex hull is determined to reduce the runtime.

Maxferet

The maxferet is calculated as the maximum Euclidean distance of all pixels.

Minferet

The minferet is exactly calculated and not approximated. My algorithm uses the fact, that the calipers that define the minferet run on one side through two points and on the other through one point. The script iterates over all edge points and defines a line through the point and the one next to it. Then all the distances to the other points are calculated and the maximum is taken. The minimum of all those maximums is the minferet. The maximum of all those maximums is not the maxferet, that is the reason it is calculated separately. The runtime of this is already pretty good but hopefully I can improve it in the future.

Use

The module can be used as followed:

First you need a binary image for which the feret diameter should be calculated. The background has to have the value zero, the object can have any nonzero value. The object doesn't have to be convex. At the moment the module only supports one object per image.This means, that if there are multiple not connected regions, the script will calculate a convexhull which include all regions and for this hull the feret diameter is calculated.

Thr calls are:

import feret

# tifffile is not required nor included in this module.
import tifffile as tif
img = tif.imread('example.tif') # Image has to be a numpy 2d-array.


# get the values
maxf, minf, minf90, maxf90 = feret.all(img)

# get only maxferet
maxf = feret.max(img)

# get only minferet
minf = feret.min(img)

# get only minferet90
minf90 = feret.min90(img)

# get only maxferet90
maxf90 = feret.max90(img)

# get all the informations
res = feret.calc(img)
maxf = res.maxf
minf =  res.minf
minf90 = res.minf90
minf_angle = res.minf_angle
minf90_angle = res.minf90_angle
maxf_angle = res.maxf_angle
maxf90_angle = res.maxf90_angle

There is an option to calculate the Feret diameters for the pixel edges instead of the centers. Just add an edge=True in the call as shown below. This works for all calls analogous.

import feret

# tifffile is not required nor included in this module.
import tifffile as tif
img = tif.imread('example.tif') # Image has to be a numpy 2d-array.

# get only maxferet
maxf = feret.max(img, edge=True)

Future Releases

  • add a return_angle in the calls
  • add the possibility to show plots of the results

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

feret-1.1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

feret-1.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file feret-1.1.1.tar.gz.

File metadata

  • Download URL: feret-1.1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.10 Windows/10

File hashes

Hashes for feret-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ccb57f33dd0570fcce6bd060bf828aef9495f96df26856785470d56a5548e4ab
MD5 436f32268ea9b24121371a21ad3e5856
BLAKE2b-256 e64cde99f1aeeffbcabac07f96f6e4cfc033d6aa29ac18e3f7afd5ead451a27a

See more details on using hashes here.

File details

Details for the file feret-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: feret-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.10 Windows/10

File hashes

Hashes for feret-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7eea212f7f5d9b67910170a57b62885e36bf97b8cf59b152c6e269d52bd1bda
MD5 627551c1d5fd4dc0b545e495ba9007a4
BLAKE2b-256 64e03c8bbc6157904aef4cc9c1b28045c94d1b44ef7b2e55ee043b2545a66571

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