spacr.image_quality¶
Auditable image-quality screening before segmentation, using raw intensities.
Functions¶
|
Measure focus, saturation and nonfinite pixels on unnormalized channels. |
|
Refuse exclusions that would leave previously measured fields in reports. |
|
Read the active saved exclusion policy for downstream field consumers. |
|
Remove policy-excluded fields without substituting empty label images. |
|
Validate a saved per-channel policy without inspecting any image. |
|
Save a field/channel report and return fields explicitly excluded by policy. |
Module Contents¶
- spacr.image_quality.assess_image(image, settings, channel_ids=None)[source]¶
Measure focus, saturation and nonfinite pixels on unnormalized channels.
- Parameters:
image – YX, YXC or leading-dimensions plus YXC array.
settings – image_qc_* policy, validated before use.
channel_ids – optional acquisition-channel labels for stored C planes.
- Returns:
one metric/reason record per selected channel. Focus is the best plane’s Laplacian variance in raw intensity units squared, avoiding rejection solely because a z stack includes out-of-focus planes. Saturation uses an explicit acquisition level or integer dtype ceiling; it never uses the brightest observed pixel. Object counts are not read.
- Raises:
ValueError – channels, shape or saturation calibration are unavailable.
- spacr.image_quality.ensure_no_retained_measurements(root, rejected)[source]¶
Refuse exclusions that would leave previously measured fields in reports.
Existing results are never deleted. Re-screening an analyzed project needs a fresh project if excluded fields already have measurement rows.
- Parameters:
root – project folder containing measurements/measurements.db.
rejected – rejected field filenames, also matched without extensions.
- Returns:
None if no existing measurement row matches a rejected field.
- Raises:
ValueError – a table’s file_name column contains a rejected identity.
- spacr.image_quality.excluded_fields(root)[source]¶
Read the active saved exclusion policy for downstream field consumers.
- Parameters:
root – project folder whose qc/image_quality.json is authoritative.
- Returns:
excluded NPY basenames, or an empty set when no policy is active.
- Raises:
ValueError – a saved report has an unsupported or invalid schema.
- spacr.image_quality.filter_batch(batch, filenames, settings)[source]¶
Remove policy-excluded fields without substituting empty label images.
- Parameters:
batch – normalized image batch with its original field axis.
filenames – matching basenames in batch order.
settings – current run settings carrying image_qc_excluded_fields.
- Returns:
filtered batch and matching filenames in their original order.
- spacr.image_quality.quality_policy(settings)[source]¶
Validate a saved per-channel policy without inspecting any image.
- Parameters:
settings – Mask settings containing image_qc_* options.
- Returns:
JSON-serializable policy; empty channel list means every channel.
- Raises:
ValueError – unsupported mode, invalid channel or invalid threshold.
- spacr.image_quality.screen_fields(root, settings, paths=None, channel_ids=None)[source]¶
Save a field/channel report and return fields explicitly excluded by policy.
- Parameters:
root – project folder; reports go to qc/image_quality.json and .csv.
settings – Mask settings; mode off clears a previously active policy.
paths – optional iterable of raw NPY paths; defaults to root/stack.
channel_ids – optional acquisition-channel labels for supplied arrays.
- Returns:
excluded basenames, empty in report-only or off mode. Inputs are never deleted or rewritten. Report and exact policy precede exclusion.
- Raises:
ValueError – enabled screening has no raw fields or invalid calibration.
Nested helpers¶
- _qc_network.QCNet.__init__(self)¶
Build the two convolutional trunks and the shared head.
spacr/image_quality.py:430
- _qc_network.QCNet.forward(self, tiles, thumbnail)¶
Return class logits for a batch of fields.
spacr/image_quality.py:437
- _qc_network.trunk()¶
Four 3x3 convolution stages shared in shape by both branches.
spacr/image_quality.py:417