Image segmentation and processing library with CLI support
Project description
segimage
A Python library for image segmentation and processing with command-line interface support.
Features
- MATLAB .mat file support: Read and process MATLAB data files
- Multiple output formats: Convert to standard image formats (PNG, JPG, TIFF)
- Command-line interface: Easy-to-use CLI for batch processing
- Extensible architecture: Easy to add new processing methods
Installation
From PyPI (when published)
pip install segimage
From source
git clone https://github.com/yourusername/segimage.git
cd segimage
pip install -e .
Quick Start
Command Line Usage
The library provides a command-line interface that can be used directly:
# Convert a MATLAB .mat file to PNG format (default)
segimage process input.mat output_directory --process-type mat_to_image
# Convert to JPG format
segimage process input.mat output_directory -t mat_to_image -f jpg
# With verbose output
segimage process input.mat output_directory -t mat_to_image -f png -v
# Show supported formats
segimage formats
# Show library information
segimage info
Python API Usage
from pathlib import Path
from segimage import ImageProcessor
# Initialize the processor
processor = ImageProcessor()
success = processor.process_image(
Path("input.png"),
Path("out/input_clustered.png"),
"color_cluster",
K=4,
palette="rainbow",
)
if success:
print("Conversion successful!")
else:
print("Conversion failed!")
Supported Formats
Input Formats
.mat- MATLAB data files.npy- NumPy array files.tif,.tiff- TIFF images.png,.jpg,.jpeg- Common image formats
Output Formats
.png- PNG images (default, lossless).jpg,.jpeg- JPEG images (compressed).tif,.tiff- TIFF images.npy- NumPy array files
Processing Types
Currently supported processing types:
mat_to_image(default): Convert MATLAB .mat files to standard image formatscolor_cluster: Group pixels by most frequent exact colors into up to K clustersslico: SLICO superpixels using scikit-image's SLIC withslic_zero=True
SLICO usage examples
# Run SLICO with defaults
segimage process input.png output_dir -t slico
# Customize superpixel parameters
segimage process input.png output_dir -t slico --n-segments 500 --compactness 10 --sigma 1 --start-label 1
Python API:
from pathlib import Path
from segimage import ImageProcessor
processor = ImageProcessor()
processor.process_image(
Path("input.png"),
Path("out/input_slico.png"),
"slico",
n_segments=280,
compactness=2.0,
sigma=1.0,
start_label=1,
)
Examples
Basic MATLAB to PNG conversion
segimage process data/2018.mat output/ --process-type mat_to_image
Convert to JPG format
segimage process input.mat output/ -t mat_to_image -f jpg
Convert to TIFF format
segimage process input.mat output/ -t mat_to_image -f tif
Verbose processing
segimage process input.mat output/ -t mat_to_image -f png -v
How It Works
The library automatically:
- Reads MATLAB .mat files and extracts numeric data
- Handles complex data structures including object arrays and structured arrays
- Normalizes data to appropriate ranges for image formats
- Converts to PIL Image objects for proper image processing
- Saves in standard formats that macOS and other systems recognize as images
- Preserves metadata in companion .meta files
Development
Setup development environment
pip install -e ".[dev]"
Run tests
pytest
Code formatting
black src/
Project Structure
segimage/
├── src/
│ └── segimage/
│ ├── __init__.py # Main package exports
│ ├── processor.py # Core image processing logic
│ └── cli.py # Command-line interface
├── pyproject.toml # Project configuration
└── README.md # This file
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the terms specified in the LICENSE file.
Support
For issues and questions, please use the GitHub issue tracker.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file segimage-0.0.1.tar.gz.
File metadata
- Download URL: segimage-0.0.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fe96c8b156499d4c0eeffd3442c2ffe8aefb02aa4de7fc8cb524913f99bb764
|
|
| MD5 |
996573763b631e646984be4f230fc027
|
|
| BLAKE2b-256 |
e8a528fd32f69496902e8fa04a4fda016272e23d97835cc3596cd9305c27a5a8
|
Provenance
The following attestation bundles were made for segimage-0.0.1.tar.gz:
Publisher:
publish-pypi.yml on lucaslopes/segimage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
segimage-0.0.1.tar.gz -
Subject digest:
1fe96c8b156499d4c0eeffd3442c2ffe8aefb02aa4de7fc8cb524913f99bb764 - Sigstore transparency entry: 414952090
- Sigstore integration time:
-
Permalink:
lucaslopes/segimage@120fcaf45eaf7de422e9a208d7efe5ae8a15540a -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/lucaslopes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@120fcaf45eaf7de422e9a208d7efe5ae8a15540a -
Trigger Event:
push
-
Statement type:
File details
Details for the file segimage-0.0.1-py3-none-any.whl.
File metadata
- Download URL: segimage-0.0.1-py3-none-any.whl
- Upload date:
- Size: 21.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c25e1e6dab3bef1191e30c4a2e4dc0efcefd7f2c2cc7800d93293843ced2aa6
|
|
| MD5 |
ec2c988e71ca2403ef47ba3a239075a3
|
|
| BLAKE2b-256 |
6546316c0c411488f9b4996e4f1b32518f4bccbe41c1499e5ac24c66fe7b78d4
|
Provenance
The following attestation bundles were made for segimage-0.0.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on lucaslopes/segimage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
segimage-0.0.1-py3-none-any.whl -
Subject digest:
4c25e1e6dab3bef1191e30c4a2e4dc0efcefd7f2c2cc7800d93293843ced2aa6 - Sigstore transparency entry: 414952091
- Sigstore integration time:
-
Permalink:
lucaslopes/segimage@120fcaf45eaf7de422e9a208d7efe5ae8a15540a -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/lucaslopes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@120fcaf45eaf7de422e9a208d7efe5ae8a15540a -
Trigger Event:
push
-
Statement type: