MIST: Merging Instance Segmentation Tiler
A Command Line Interface (CLI) application and Python package for running the Merging Instance Segmentation Tiler (MIST) with Machine Learning (ML) computer vision models. MIST creates tiles from a large image, runs inference on each tile, and combines, or merges, instances of the same class together using the instance segmentation results from inference. Non-maximum suppression (NMS) is not used to determine overlap. Instead, each instance of a class is logically "anded" into a binary mask. The individual instances within a class are identified as contours through OpenCV's connectivity algorithm. In this manner, large instances that span multiple tiles are combined, or merged, into a single instance and small instances within the overlap region between two or more tiles are automatically filtered and reduced to a single instance. Only a single "pass" per class is required.
MIST is inspired by the Slicing Aided Hyper Inference (SAHI), YOLO
Patch-Based Inference (YPBI), and dask_relabeling packages. The SAHI tiler
does not merge large instances spanning multiple tiles and uses NMS for
instance reduction in overlap regions. The YPBI tiler does instance
segmentations but does not merge large instances, and it performs multiple NMS
iterations for both bounding boxes and segmentations. The dask_relabeling
package does instance segmentations and merging large instances, but it does not
work with YOLO models and GPU-powered inference.
Prerequisites
All of the prerequisites may already be installed and configured by the superuser, a.k.a. root, of the computer. The prerequisites only need to be installed and configured once per machine.
Python
The Python programming language is needed to run the mist Command Line
Interface (CLI) application and/or use the mist package in other Python
scripts or Jupyter notebooks. Both macOS and Linux have the Python programming
language installed, but it is generally reserved for the operating system (OS)
to use and is an older version. It is best practice to install a newer version
that is separate from the system-provided Python version.
Ubuntu
MIST was developed and tested on Ubuntu 22.04 Linux. The following steps are for Ubuntu Linux, but any Linux distribution can be used. The commands will be similar but different for other Linux distributions.
-
Add the "deadsnakes" Ubuntu Personal Package Archives (PPA).
sudo add-apt-repository ppa:deadsnakes/ppa
-
Obtain the latest packages from the PPA.
sudo apt update
-
Install Python v3.11 or newer.
sudo apt install -y python3.11
-
Install the
venvpackage.sudo apt install -y python3.11-venv
macOS
MIST has been deployed and tested on a Macbook Pro laptop with a M3 Apple Silicon processor.
-
Install Homebrew if it is not already installed.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install Python v3.11 or newer.
brew install python@3.11
pipx
The pipx utility enables distribution of Python-based CLI applications, like
mist, to be installed for all users with all of the appropriate dependencies
within an isolated environment. It is the recommended installation for the
mist application.
Ubuntu
-
Create a virtual environment for
pipxand Python v3.11 or newer.sudo python3.11 -m venv --upgrade-deps /opt/pipx
-
Install
pipxfor all users.sudo /opt/pipx/bin/pip install pipx
-
Ensure the
pipxcommand is available to all users.sudo ln -s /opt/pipx/bin/pipx /usr/local/bin/pipx
-
Add
pipxto thePATHenvironment variable.pipx ensurepath -
Add
pipxfor all users.sudo pipx ensurepath --global
Post-installation, the pipx application can be upgraded with the following
command:
sudo /opt/pipx/bin/pip install --upgrade pipx
macOS
-
Install
pipxusing Homebrew.brew install pipx
-
Add
pipxto thePATHenvironment variable.pipx ensurepath -
Add
pipxfor all users.sudo pipx ensurepath --global
Post-installation, the pipx application can be upgraded with the following
command:
brew update && brew upgrade pipx
Installation
pipx (recommended)
-
Ensure
pipxis installed. See the Prerequisites.$ pipx --version 1.7.1
-
Install
mistcommand globally for all users.sudo pipx install --global --python python3.11 "tsmist[cli]"
-
Verify
mistcommand is available.$ mist --version mist 0.1.0
Source
-
Clone this repository.
git clone https://github.com/Theia-Scientific/mist.git && cd mist
-
Create a virtual environment.
python3 -m venv .venv
-
Activate the virtual environment.
source .venv/bin/activate
or if direnv is installed:
cp .envrc.example .envrc
followed by:
direnv allow -
Upgrade
pipto the latest version.python3 -m pip install --upgrade pip
-
Locally install the package, utility, and its dependencies. This will create the
mistcommand within the virtual environment.python3 -m pip install -e ".[cli]"
Upgrade
pipx (recommended)
-
Upgrade the
mistapplication viapipx.sudo pipx install --global --python python3.11 --force tsmist
-
Verify new version.
$ mist --version mist 0.1.0
Source
-
Navigate to the root of the source tree.
cd ~/Code/mist
-
Activate the virtual environment.
source .venv/bin/activate
or if direnv is installed, the virtual environment will automatically be activated.
-
Pull the latest changes on
main.git pull -
Upgrade the
mistapplication within the virtual environment.python -m pip install --upgrade -e .
-
Verify new version.
$ mist --version mist 0.1.0
Usage
Terminal
Using the Ultralytics YOLOv8 model:
mist yolov8n-seg.pt example1.jpg example2.jpg /path/to/images/dir
For running on macOS:
mist --device=mps yolov8n-seg.pt example1.jpg example2.jpg /path/to/images/dir
Python
Using an Ultralytics YOLO segmentation model and defaults.
import numpy as np
import numpy.typing as npt
import supervision as sv
from mist import detecting
from pathlib import Path
from ultralytics.models import YOLO
model = YOLO("yolo26n-seg.pt")
def predict(image: npt.NDArray[np.uint8]) -> sv.Detections:
return sv.Detections.from_ultralytics(
list(
model(
image,
agnostic_nms=False,
device="cuda:0",
classes=None,
conf=0.35,
imgsz=640,
iou=0.7,
max_det=1000,
retina_masks=True,
verbose=False
)
)[0]
)
result = detecting.run(
np.zeros((3, 4096, 4096), dtype=np.uint8),
predict,
class_names=[name for _, name in sorted(model.names.items())],
)
print(results)
Using a custom model.
import numpy as np
import numpy.typing as npt
import supervision as sv
from mist import detecting
from pathlib import Path
model = CustomModel(weights_file)
def predict(image: npt.NDArray[np.uint8]) -> sv.Detections:
return sv.Detections.from_inference(model(image))
results = detecting.run(
np.zeros((3, 4096, 4096), dtype=np.uint8),
predict,
class_names=["object"]
)
print(results)
Contributing
-
Clone this repository.
git clone https://github.com/Theia-Scientific/mist.git && cd mist
-
Create a virtual environment.
python3 -m venv .venv
-
Activate the virtual environment.
source .venv/bin/activate
or if direnv is installed:
cp .envrc.example .envrc
followed by:
direnv allow -
Install the package, utility, the required dependencies, and the development dependencies.
pip install -e ".[cli,dev]"
-
Create a local branch.
git checkout -b feature-awesome-new-feature
-
Modify the code.
-
Run the tests.
pytest --color=yes
-
Commit changes to your local branch.
git add -A && git commit -m "Add new feature"
-
Push your local branch to GitHub to create a Pull Request (PR).
git push origin feature-awesome-new-feature
-
Create a Pull Request (PR) in GitHub.
-
Wait for CI to complete.
-
Add comment to PR that it is ready to review.
License
Acknowledgments
This material is based upon work supported by the U.S. Department of Energy, Office of Science and Office of Nuclear Energy under Awards: DE-SC0021529 and DE-SC0021936, respectively.
Metadata
Release files for tsmist 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tsmist-1.0.0.tar.gz | 162.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tsmist-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 178.3 kB
Release files / tsmist-1.0.0.tar.gz
| Download URL | tsmist-1.0.0.tar.gz |
|---|---|
| Size | 162.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30cfeee70cf00354115b72f12005bfdcbd73fe186e95ea8a53a69c018055699e
|
|
BLAKE2b-256 checksum How to use checksums |
4076ae84fe278d867ea8d1ca89d590a83687211f479dae81b7ecdc7e30e8d9c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.
Transparency logRelease files / tsmist-1.0.0-py3-none-any.whl
| Download URL | tsmist-1.0.0-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b392cd4ecc7f6c29278fee9a9093dfd8310879970209dc59e462da1c7447b1d
|
|
BLAKE2b-256 checksum How to use checksums |
c55af8569c0ca5d583675b2dc637b5ec2f9c657b4208bf29f116d8ed387d6618
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.
Transparency log