--- license: bsd-3-clause library_name: cellpose pipeline_tag: image-segmentation tags: - cellpose - cpsam - microscopy - instance-segmentation - crystallization --- # Crystal Detector (Cellpose cpsam) A [Cellpose](https://github.com/MouseLand/cellpose) `cpsam` model fine-tuned to segment individual crystals in microscopy images of crystallization. Given a frame, it produces an instance mask (one label per crystal), from which centroid and pixel-area measurements are derived. This checkpoint backs the `crystal_detector` component of the [crystalization](https://github.com/MarekWadinger/crystalization) research project — the deep-learning counterpart to that repo's deterministic (focus/motion) crystal annotator. ## Usage The project downloads and caches this checkpoint automatically: ```bash uv sync --group crystal-detector uv run crystal-detector-analyze image.png ``` Or directly with `huggingface_hub` + Cellpose: ```python import torch from huggingface_hub import hf_hub_download from cellpose import models ckpt = hf_hub_download("MarekWadinger/crystal-detector-cpsam", "cpsam_20260517_223507") model = models.CellposeModel(gpu=torch.cuda.is_available(), pretrained_model=ckpt) masks, flows, _ = model.eval(image, diameter=None, flow_threshold=0.9, cellprob_threshold=-2.0) ``` The inference defaults used by the project are `flow_threshold=0.9` and `cellprob_threshold=-2.0`, on images preprocessed with flat-field correction + CLAHE (see `src/crystal_detector/analyze.py`). ## Training Fine-tuned from the base Cellpose `cpsam` model in the Cellpose GUI on flat-field-corrected microscopy frames, with masks hand-corrected per image. The frame-export and training workflow is documented in the project's [component README](https://github.com/MarekWadinger/crystalization/blob/main/src/crystal_detector/README.md). ## Intended use & limitations - **Intended for** segmenting crystals in microscopy imagery from the same optical setup / preparation as the training data. - **Limitations:** trained on a small, domain-specific frame set; expect degraded performance on different magnifications, illumination, or crystal habits. Treat outputs as assistive measurements, not ground truth. No held-out quantitative benchmark is published with this checkpoint. ## License Released under BSD-3-Clause, matching the upstream Cellpose license.