A package for data manipulation, it has different functions e.g: encode/decode RLE, POLYGON manipulation, etc...
Project description
A Python package for handling various data encoding and manipulation tasks, including run-length encoding (RLE), mask operations, and polygon manipulations.
Installation
Install the package using pip:
pip install dataweave
USAGE
Run-Length Encoding (RLE)
RLE stands for Run-Length Encoding. It's a simple form of data compression where consecutive data elements of the same value are replaced with a count and a single value.
Basic Principle: In RLE, sequences of the same data value are stored as a single data value and count pair. For example, the sequence "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A".
Example:
-
Original data: "AAABBBCCCCDDDD"
-
Encoded with RLE: "3A3B4C4D"
Applications:
-
Image Compression: RLE can be used for compressing images, especially those with large areas of the same color.
-
Text Compression: It can be used in compressing text files where certain characters or sequences are repeated.
-
Simple Data Compression: RLE can be useful in scenarios where the data has long sequences of repeated values. Use RLEHandler for encoding and decoding sequences of data using run-length encoding.
from dataweave import RLEHandler
# Example data
data = [0, 0, 1, 1, 1, 0, 0, 0, 1]
# Encode data using RLE
encoded = RLEHandler.encode(data)
print(encoded) # Output: [(0, 2), (1, 3), (0, 3), (1, 1)]
# Decode the RLE encoded data
decoded = RLEHandler.decode(encoded)
print(decoded) # Output: [0, 0, 1, 1, 1, 0, 0, 0, 1]
Mask Operations
Use MaskHandler for converting between mask data and RLE encoding.
from dataweave import MaskHandler
# Example mask data
mask_data = [[0, 0, 1],
[1, 1, 0],
[0, 0, 1]]
# Convert mask data to RLE
rle_encoded = MaskHandler.mask_to_rle(mask_data)
print(rle_encoded)
shape = (3, 3) # The shape of the mask data (height, width)
# Convert RLE back to mask data
decoded_mask = MaskHandler.rle_to_mask(rle_encoded, shape)
print(decoded_mask)
Polygon Operations
Use PolygonHandler for converting between polygon vertices and RLE encoding as well as masks.
from dataweave import PolygonHandler
# Example polygon data (list of vertices)
data = [(100, 100), # Vertex 1
(200, 150), # Vertex 2
(250, 300), # Vertex 3
(180, 400), # Vertex 4
(120, 350)] # Vertex 5
polyhandler = PolygonHandler()
# Convert polygon vertices to RLE and bounding box
rle, bbox = polyhandler.polygon_to_rle(data)
print(rle)
# Convert RLE and bounding box back to polygon vertices
polygon = polyhandler.rle_to_polygon(rle, bbox)
print(polygon)
mask = polyhandler.polygon_to_mask(data, shape=(height, width))
print(mask)
# Convert mask back to polygon vertices
polygon_from_mask = polyhandler.mask_to_polygon(mask)
print(polygon_from_mask)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
Authors
Tsilavo Tahina R.
- Mail: rtsilavotahina@gmail.com
- Github: https://github.com/Rtsil
- Gitlab: https://gitlab.com/tsilavotahina
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
Built Distribution
Hashes for dataweave-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf8ece3edfafdfd24b13353f4a7efb3629d904e90daf672557649402be21da8e |
|
MD5 | ee7505ea8f41d1419e577d79eed18b8d |
|
BLAKE2b-256 | b77ace8bd33e3184811ec37d15c1ab1d68ddf97befa1d1f6939c7c6dfe6a8bae |