Metadata-Version: 2.4
Name: twxtools
Version: 0.1.0
Summary: Interactive image and video sequence viewer
Author: Aram Danielyan
License: MIT License
        
        Copyright (c) 2026 aram-danielyan
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/aram-danielyan/twx
Project-URL: Repository, https://github.com/aram-danielyan/twx
Project-URL: Bug Tracker, https://github.com/aram-danielyan/twx/issues
Keywords: image,video,viewer,matplotlib,visualization
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Topic :: Multimedia :: Graphics :: Viewers
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: matplotlib
Dynamic: license-file

# twxtools

**twxtools** is an interactive image and video sequence viewer built on top of [matplotlib](https://matplotlib.org/). It provides a convenient `twx()` function for quickly displaying, comparing, and navigating through images and video sequences in Python.

## Features

- Display single images or compare multiple images side-by-side
- Navigate video sequences frame-by-frame with keyboard shortcuts
- Automatic intensity range detection (with optional percentile clipping)
- Support for grayscale and RGB data
- Flexible data layout modes: `HW`, `HWC`, `CHW`, `NHW`, `NHWC`, `NCHW`
- Interactive colormap switching
- Accepts NumPy arrays, lists, tuples, or dicts

## Installation

```bash
pip install twxtools
```

## Quick Start

```python
import numpy as np
from twxtools import twx

# Display a single grayscale image
img = np.random.rand(256, 256)
twx(img)

# Compare two images
img1 = np.random.rand(256, 256)
img2 = np.random.rand(256, 256)
twx([img1, img2])

# Display a grayscale video sequence (N x H x W)
video = np.random.rand(30, 256, 256)
twx(video)

# Use a dict to label images automatically
twx({'original': img1, 'processed': img2})
```

## API Reference

### `twx(data, dataRange=[], cmap='gray', mode=None, titles=None)`

**Parameters:**

| Parameter   | Type                        | Description |
|-------------|-----------------------------|-------------|
| `data`      | `ndarray`, `list`, `tuple`, or `dict` | Image(s) or video sequence(s) to display. Each item can be a NumPy array of up to 4 dimensions. |
| `dataRange` | `list`                      | Intensity range(s) for display. See details below. |
| `cmap`      | `str`                       | Colormap for grayscale data (default: `'gray'`). Ignored for RGB data. |
| `mode`      | `str` or `None`             | Dimension layout of the input data. Auto-detected if `None`. |
| `titles`    | `list` of `str` or `None`   | Labels for each input. Auto-generated as `'1'`, `'2'`, … if not provided. When `data` is a dict, keys are used as titles. |

#### `dataRange` options

- `[]` — use `[min(data), max(data)]`
- `[P]` — use `[percentile(data, P), percentile(data, 100-P)]`
- `[low, high]` — use the given fixed range

#### `mode` options

| Mode   | Shape           | Description                                 |
|--------|-----------------|---------------------------------------------|
| `'HW'`   | `H × W`         | Grayscale image                             |
| `'HWC'`  | `H × W × C`     | RGB image (channels last)                   |
| `'CHW'`  | `C × H × W`     | RGB image (channels first)                  |
| `'NHW'`  | `N × H × W`     | Grayscale video sequence                    |
| `'NHWC'` | `N × H × W × C` | RGB video sequence (channels last)          |
| `'NCHW'` | `N × C × H × W` | RGB video sequence (channels first)         |

If `mode` is not provided, it is auto-detected from the array shape.

## Keyboard Controls

| Key         | Action                                   |
|-------------|------------------------------------------|
| `1`–`9`, `0` | Switch to the corresponding input (1–10) |
| `↑` / `↓`  | Previous / next frame in a video         |
| `a`         | Toggle colorbar                          |
| `m`         | Cycle through colormaps                  |

## Requirements

- Python ≥ 3.8
- [numpy](https://numpy.org/)
- [matplotlib](https://matplotlib.org/)

## License

[MIT](LICENSE)
