DGtal 2.1.0
|
Package Overview
Since release 1.2, DGtal has a partial python binding using pybind11. To install the python package, just use:
For most use case, it is sufficient to install the library from its pypy repository.
If it fails, it is also possible to build from sources. See []. In short:
Which build the necessary shared library and copy the few plain python code; which may need to be further installed depending on your installation.
To import the module and access its functionalities:
This example loads a binary image and computes integral invariant estimators and displays them within an interactive viewer. It mostly follows Shortcuts examples with a one-to-one mapping. A few other utilities are provided not to loop over elements in python.
This example requires polyscope to be installed
In this section, we provide a list of functions and classes that can be used in python. You may find more documentation and example usage by calling the help function on these classes (eg. help(dgtal.Object4_8)). The python constructor column shows how objects can be inferred through their parameters (for example, point dimension and type from the data parameter). Often, this is done through factories that are written in python.
Python class(es) | C++ class(es) | Python constructor |
---|---|---|
Point2D, Point3D, RealPoint2D, RealPoint3D | DGtal::PointVector | Point(data=list_or_np_array) |
DomainZ2i, DomainZ3i | DGtal::HyperRectDomain | Domain(point_lower, point_upper) |
PreCell2D, SPreCell2D, KPreSpace2D, PreCell3D, SPreCell3D, KPreSpace3D | DGtal::KhalimskyPreSpaceND DGtal::KhalimskyPreCell | N/A |
Cell2D, SCell2D, KSpace2D Cell3D, SCell3D, KSpace3D | DGtal::KhalimskySpaceND DGtal::KhalimskyCell | KSpace(dim) |
Adj4, Adj8, Adj6, Adj18, Adj26 | DGtal::MetricAdjacency | MetricAdjacency(dim, maxnorm) Ex: adj26 implies dim=3, maxnorm=3 |
DT4_8, DT8_4, DT6_16, DT18_6, DT6_26, DT26_6 | DGtal::DigitalTopology | DigitalTopology(foreground, background) |
Object4_8, Object8_4, Object6_18, Object18_6, Object6_26, Object26_6 | DGtal::Object | Object(topology, domain, points, connectedness) |
Most shortcuts (see. Shortcuts (for the impatient developper)) also have their binding. These are available under:
Objects within this module are not expected to be manipulated by the user. They are meant to be passed around to the next functions and are prefixed by two underscores. We reference them for completeness
Python class(es) | C++ class(es) | Available methods (if any) | Comments |
---|---|---|---|
__PtrBInaryImage | DGtal::CountedPtr on DGtal::Shortcuts::BinaryImage | None | Not to be used. |
__PtrGrayScaleImage | DGtal::CountedPtr on DGtal::Shortcuts::GrayScaleImage | None | Not to be used. |
__PtrLightDigitalSurface | DGtal::CountedPtr on DGtal::Shortcuts::LightDigitalSurface | len(object): Number of surfels / object.size(): Number of surfels | Not to be used (except to query size) |
__PtrTriangulatedSurface | DGtal::CountedPtr on DGtal::Shortcuts::TriangulatedSurface | None | Not to be used. |
__PtrMesh | DGtal::CountedPtr on DGtal::Shortcuts::Mesh | len(object): Number of vertices / object.nbVertex: Number of vertices | Not to be used (except to query size) |
__PtrImplicitShape3D | DGtal::CountedPtr on DGtal::Shortcuts::ImplicitShape3D | None | Not to be used. |
__PtrDigitizedImplicitShape3D | DGtal::CountedPtr on DGtal::Shortcuts::DigitizedImplicitShape3D | None | Not to be used. |
Cell2Index | DGtal::Shortcuts::Cell2Index | None | Not to be used (except to be created and passed to funtions) |
ColorMap | DGtal::Shortcuts::ColorMap | ColorMap(min, max) / object.addColor(dgtal.Color): adds a color / object(value): convert value to color / | See: applyColorMap |
SurfelRange | DGtal::Shortcuts::SurfelRange | std::vector<SCell>. See documentation of kernel binding above. | |
ScalarStatistic | DGtal::Shortcuts::ScalarStatistic | samples(): number of samples / size(): number of samples / mean(): mean / variance(): biased variance / unbiasedVariance(): unbiased variance / min(): min / max(): max / values: list of values | Not to be created. |
Static functions are also bound. For overloads, we only indicate the main parameters, not the whole signature. Refer to the C++ functions for complete signature (1 to 1 match).
Looping through objects is slow in python and digital objects may be large. For this reason, we also provide a few helper functions for ease of usage and faster code:
Python function | Description | Example usage |
---|---|---|
SH3.applyColorMap | Applies a colormap to a list of values | cmap = SH3.getColorMap(params); colors = SH3.applyColorMap([0, 1, 2], cmap)
|
SH3.getEmbeddedPosition | Returns the position of a list of surfels. | K = SH3.getKSpace(image, params); surface = SH3.makeLightDigitalSurface(image, K, params); surfels = SH3.getSurfelRange(surface, params); pos = SH3.getEmbeddedPositions(K, surfels)
|