This release is a pre-release and may not be stable for production use.
Crackle: Next gen. 3D segmentation compression codec.
crackle data.npy # creates data.ckl
crackle -d data.ckl # recovers data.npy
import crackle
import numpy
labels = np.load("example.npy") # a 2D or 3D dense segmentation
binary = crackle.compress(labels)
labels = crackle.decompress(binary)
# get unique labels without decompressing
uniq = crackle.labels(binary)
# Remap labels without decompressing. Could
# be useful for e.g. proofreading.
remapped = crackle.remap(
binary, { 1: 2, 2: 3, ... },
preserve_missing_labels=True
)
# for working with files
# if .gz is appended to the filename, the file will be
# automatically gzipped (or ungzipped)
crackle.save(labels, "example.ckl.gz")
labels = crackle.load("example.ckl.gz")
arr = crackle.CrackleArray(binary)
res = arr[:10,:10,:10] # array slicing (efficient z ranges)
20 in arr # highly efficient search
This repository is currently experimental.
Crackle is a new codec inspired by Compresso [1] for creating highly compressed 3D dense segmentation images. Compresso innovated by separating labels from boundary structures. There were conceptually four (but really five) elements in the format: header, labels, bit packed and RLE encoded binary image boundaries, and indeterminate boundary locations.
Crackle improves upon Compresso by replacing the bit-packed boundary map with a "crack code" and also uses 3D information to reduce redundancy in labels using "pins". Like Compresso, Crackle uses a two pass compression strategy where the output of crackle may be further comrpessed with a bitstream compressor like gzip, bzip2, zstd, or lzma.
Based on benchmarks, it seems likely that the output of Crackle will be in the ballpark of 20% to 50% the size of Compresso. The second stage compressed Crackle file will likely be about 60% to 85% the size of the equivalent Compresso file.
Boundary Structure: Crack Code
Our different approach is partially inspired by the work of Zingaretti et al. [2]. We represent the boundary not by border voxels, but by a "crack code" that represents the edges between voxels. This code can be thought of as directions to draw edges on a graph where the vertices are where the corners of four pixels touch and the edges are the cracks in between them.
Since this regular graph is 4-connected, each "move" in a cardinal direction can be described using two bits. To represent special symbols such as "branch" and "terminate", an impossible set of instructions on an undirected graph such as "left-right" or "up-down" can be used (occupying 4 bits). In order to avoid creating palendromic sequences such as (3, 0, 3) meaning (down, branch) but can be read (terminate, down), we can use the left-right impossible directions to rewrite it as (3, 2, 1).
While the image is 3D, we treat the image in layers because working in 3D introduces a large increase in geometric complexity (a cube has 6 faces, 12 edges, and 8 corners while a square has 4 edges and 4 corners). This increase in complexity would inflate the size of the crack code and make the implementation more difficult.
Label Map: Method of Pins
Each 2D CCL region must has a label assigned. Due to the 2D nature of the crack code, we cannot use 3D CCL. However, for example, a solid cube of height 100 would need 100 labels to represent the same color on every slice as in Compresso.
It is still possible to reduce the amount of redundant information even without 3D CCL. For each label, we find a set of vertical line segments ("pins") that fully cover the label's 2D CCL regions. Sharp readers may note that this is the NP-hard set cover problem.
Once a reasonably small or minimal set of pins are found, they can be encoded in two forms:
Condensed Form: [label][num_pins][pin_1][pin_2]...[pin_N]
Fixed Width Form: [label][pin_1][label][pin_2]...[label][pin_N]
Pin Format: [linear index of pin top][number of voxels to bottom]
Fixed width example with label 1 with a pin between (1,1,1) and (1,1,5) on a 10x10x10 image: [1][111][4]
An alternative formulation [label][idx1][idx2] was shown in an experiment on connectomics.npy.cpso to compress slightly worse than Compresso labels. However, this alternative formulation theoretically allows arbitrary pin orientations and so might be useful for reducing the overall number of pins.
The condensed format is a bit smaller than the fixed width format, but the fixed width format enables rapid searches if the set of pins are sorted by either the label (enables fast label in file) or the likely more useful sorting by top index to filter candidate pins when performing random access to a z-slice.
References
-
Matejek, B., Haehn, D., Lekschas, F., Mitzenmacher, M., Pfister, H., 2017. Compresso: Efficient Compression of Segmentation Data for Connectomics, in: Descoteaux, M., Maier-Hein, L., Franz, A., Jannin, P., Collins, D.L., Duchesne, S. (Eds.), Medical Image Computing and Computer Assisted Intervention − MICCAI 2017, Lecture Notes in Computer Science. Springer International Publishing, Cham, pp. 781–788. https://doi.org/10.1007/978-3-319-66182-7_89
-
Zingaretti, P., Gasparroni, M., Vecci, L., 1998. Fast chain coding of region boundaries. IEEE Transactions on Pattern Analysis and Machine Intelligence 20, 407–415. https://doi.org/10.1109/34.677272
-
Freeman, H., 1974. Computer Processing of Line-Drawing Images. ACM Comput. Surv. 6, 57–97. https://doi.org/10.1145/356625.356627
Metadata
Release files for crackle-codec 0.0.1.dev211
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crackle-codec-0.0.1.dev211.tar.gz | 57.0 kB | Without provenance | Details for crackle-codec-0.0.1.dev211.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crackle_codec-0.0.1.dev211-cp310-cp310-macosx_10_9_universal2.whl | CPython 3.10 | CPython 3.10 | macOS 10.9+ universal2 (ARM64, x86-64) | Details for crackle_codec-0.0.1.dev211-cp310-cp310-macosx_10_9_universal2.whl |
Total release size: 996.4 kB
Release files / crackle-codec-0.0.1.dev211.tar.gz
| Download URL | crackle-codec-0.0.1.dev211.tar.gz |
|---|---|
| Size | 57.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31bd442b96a9149bcb5bab786b8eb0ec0caaa3e6b0f092c08255c46239864109
|
|
BLAKE2b-256 checksum How to use checksums |
3bed856624f7cc42b4b6a21ceaada5f54ebb588a732254a493d4c354a0964261
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.21.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.10
|
Release files / crackle_codec-0.0.1.dev211-cp310-cp310-macosx_10_9_universal2.whl
| Download URL | crackle_codec-0.0.1.dev211-cp310-cp310-macosx_10_9_universal2.whl |
|---|---|
| Size | 939.5 kB |
| Tags | CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
edfe593645adb34dfe020a428cd69bb54a2e354ae8c257cb06bfc7fb08519aa8
|
|
BLAKE2b-256 checksum How to use checksums |
67d638c6cb1d5abe400cfbd86eca26cf9cf2642af800e3bfd51df40b7da27c42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.21.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.10
|
Security for crackle-codec 0.0.1.dev211
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.