Skip to content

Dev - #7

Open
ackermanar wants to merge 18 commits into
mainfrom
dev
Open

Dev#7
ackermanar wants to merge 18 commits into
mainfrom
dev

Conversation

@ackermanar

Copy link
Copy Markdown
Collaborator

("Overhaul of threshing features and UI") changes 26 files, adding 6,347 lines and removing 663. You made the commit while I was reading. It holds exactly the set of uncommitted changes that was on dev when we started.

Pipeline (core.py)

  • Both methods in one run. mask_method now accepts "both" or a list of methods. Markers are detected once per image, and then each method segments and measures on its own. Each method writes its own results CSV and failure log, and its masks and QC images get a _threshold or _birefnet suffix. Target boxes are shared. A single-method run keeps the old file names.

  • Measuring before cleanup. With measurement_source="pre-cleanup", the run measures the raw mask after clean_raw_mask has done three things:

    • cleared a band along the target-box edge
    • kept the largest object
    • dropped any piece that touches that band or lies farther away than the stray gap

    In this mode, width and length span every remaining foreground pixel, not just the largest contour.

  • Default measurements are unchanged. clean_leaf_mask(fill_holes=True) is still the old code. segment_leaf() now returns the raw mask and the cleaned mask, and create_leaf_mask wraps it.

  • New image exports:

    • raw (pre-cleanup) masks for each method, even a method that isn't measuring
    • overlays, cutouts and measurement axes
    • target boxes and cleaned masks can now be turned off

    A failed write is now recorded as an EXPORT: warning instead of being lost silently.

  • New sidecar file. Every results CSV now gets a .meta.json file recording the measurement source, method, unit and schema. This happens on default runs too.

  • Batch return shape. New keys: methods, by_method, artifacts, preview_artifacts, measurement_source, clean_margin, stray_gap. The top-level results_path and result_rows keys now appear only on single-method runs.

  • Other behaviour changes:

    • A batch now raises an error on duplicate sample IDs (two images with the same basename).
    • The CPU-parallel BiRefNet acknowledgement is required only when execution_device == "cpu".
    • The BiRefNet checks, including the hybrid-mode one, now also apply to BiRefNet pre-cleanup exports.
    • An unknown method name raises an error. Before, anything other than threshold quietly ran BiRefNet.

New modules

Module Purpose
thresholds.py Threshold presets moved out of core (still re-exported there), plus parsing of a custom 1–255 cutoff. Standard library only
mask_settings.py Defaults and range checks for clean margin (1%, up to 10) and stray gap (0.25, up to 10). Standard library only
mask_cleanup.py Edge-margin clearing, stray-piece removal, and the speck/hole levels behind the Clean size slider. numpy and OpenCV only
app/threshold_preview.py Live threshold and Clean size sliders in the browser
app/specimen_table.py Searchable, sortable table with a View button and a Marked for Adjustment box per row
app/output_adjustment.py Re-measures a threshold specimen and overwrites its mask, CSV row and dependent images. Files are staged first and rolled back on failure; the bulk version validates every specimen before writing anything
app/pages/0_Diagnostics.py Diagnostics, now its own sidebar page

CLI (cli.py)

  • New flags:
    • --mask-method both
    • --threshold-level now also takes 1–255
    • --measure-pre-cleanup, --clean-margin, --stray-gap
    • --export {pre-cleanup,overlay,cutout,axes} (repeatable) and --pre-cleanup-methods
    • --no-target-boxes, --no-masks, --no-failure-log
  • A dependent flag used without its parent flag now exits with an error.
  • The startup banner and the end-of-run summary report each method separately.

GUI

  • Home (Home.py, about 1,700 lines changed) is reorganized into four tabs: Setup, Analyze, Adjust and Export. There is a new Go to Export button in the sidebar.
  • Setup: segmentation is now two checkboxes. The threshold level appears only while Otsu is checked, and choosing custom shows a slider.
  • Analyze: a full-width measurement table, with a separate selection for each method. The viewer shows the mask that actually produced the measurements.
  • Adjust:
    • a live threshold preview with a colour panel of the masked leaf
    • a preview-only Clean size slider and Remove flashfill
    • Overwrite this specimen and Overwrite all marked specimens (N)
  • Export: lists the files this run saved, lets you pick files for the ZIP by method, and offers direct CSV downloads.
  • compute.py and the CPU Options page read the new checkbox state.

Docs and tests

  • Docs: new CHANGELOG "Unreleased" entries, and updates to README.md, docs/cli.md, docs/faq.md, docs/gui.md, AGENTS.md and the Help page.

  • Tests: 5 new test files with 57 tests in all:

    • dual-method: 8
    • mask cleanup: 19
    • pre-cleanup exports: 14
    • threshold preview: 9
    • thresholds: 7

    test_cli_args.py and test_home_app.py also grew by 180 and 1,377 lines. I didn't run the suite.

The commit message has a typo: "threshing" should be "thresholding". If you haven't pushed yet, git commit --amend will fix it.

tyrwh and others added 15 commits July 31, 2026 09:59
First-round edits to README, prior to attempting installation
Initial README edits, edited to resolve conflicts with dev branch
Ported from main (fbb3c09) onto dev at e7904eb.

Agent instructions and docs
- AGENTS.md: public agent guide, the single source of truth; CLAUDE.md
  imports it. docs/faq.md: human FAQ, linked from the README.
- .gitignore: commit CLAUDE.md and AGENTS.md; ignore *.local.md.
- README, FAQ, AGENTS: Git LFS is an install prerequisite (a clone made
  without it yields a 134-byte pointer stub, not the model), RF-DETR arrives
  with the clone, and `mats fetch-weights` is the repair path. Repair uses
  `git lfs pull --exclude=weights/birefnet_leaf.pth`, which stays RF-DETR-only
  whether or not .lfsconfig's fetchexclude is active.
- README: reconciled with the restructure from PR #2; its headings and TOC are
  kept, and the hand-edited doctor/fetch paragraph is preserved verbatim.

Also carried over from fbb3c09 (app work, unrelated to the docs)
- src/mats/app/Home.py, branding.py, src/mats/core.py, pyproject.toml,
  tests/test_home_app.py

Known and not addressed here
- .lfsconfig has fetchexclude commented out on dev, so a clone now fetches
  BiRefNet (2.65 GB) as well as RF-DETR.
- tests/test_weights.py::test_status_missing_for_excluded_checkout_pointer
  already fails on dev before this commit (message reworded in PR #2).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

CLI validation gaps, output-collision risk, a preview race, misleading documentation, and skipped CI coverage remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 5 Medium severity · 2 Low severity

Open (8)
What changed in this PR

Overhauls thresholding, mask cleanup, dual-method analysis, exports, adjustment workflows, and related documentation.

Changes:

  • Adds configurable pre-cleanup measurement and dual Otsu/BiRefNet execution.
  • Expands CLI and Streamlit controls, previews, exports, and specimen adjustment.
  • Adds supporting tests and revises weight-delivery documentation.
File Description
.gitattributes Updates BiRefNet LFS instructions.
.lfsconfig Enables default BiRefNet exclusion.
AGENTS.md Documents new workflows and safeguards.
CHANGELOG.md Records UI and pipeline changes.
README.md Documents methods, cleanup, and exports.
deploy/​ondemand/​mats/​README.md Revises shared-weight staging.
docs/​cli.md Documents new CLI options.
docs/​faq.md Updates usage and troubleshooting.
docs/​gui.md Documents redesigned workbench.
docs/​hpc.md Revises HPC weight provisioning.
docs/​weights.md Clarifies LFS behavior.
src/​mats/​app/​compute.py Reads checkbox-based method selection.
src/​mats/​app/​output_adjustment.py Adds atomic specimen remeasurement.
src/​mats/​app/​pages/​0_Diagnostics.py Adds diagnostics page.
src/​mats/​app/​pages/​2_BiRefNet_Setup.py Updates LFS command.
src/​mats/​app/​pages/​3_CPU_Options.py Reports combined method selection.
src/​mats/​app/​pages/​5_Help.py Updates in-app guidance.
src/​mats/​app/​specimen_table.py Adds interactive specimen table.
src/​mats/​app/​threshold_preview.py Adds live threshold/cleanup preview.
src/​mats/​cli.py Adds method, cleanup, and export flags.
src/​mats/​core.py Implements dual-method processing and artifacts.
src/​mats/​mask_cleanup.py Implements raw-mask cleanup.
src/​mats/​mask_settings.py Defines cleanup validation and defaults.
src/​mats/​thresholds.py Centralizes threshold parsing.
src/​mats/​weights.py Refines checkpoint-specific LFS handling.
tests/​test_cli_args.py Expands CLI coverage.
tests/​test_dual_method.py Tests dual-method orchestration.
tests/​test_mask_cleanup.py Tests cleanup behavior.
tests/​test_pre_cleanup_exports.py Tests exports and adjustment.
tests/​test_threshold_preview.py Tests preview consistency.
tests/​test_thresholds.py Tests threshold parsing.
tests/​test_weights.py Tests checkpoint instructions and pulls.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mats/core.py
Comment thread src/mats/app/threshold_preview.py
Comment thread src/mats/cli.py Outdated
Comment thread src/mats/cli.py Outdated
Comment thread tests/test_dual_method.py
Comment thread tests/test_pre_cleanup_exports.py Outdated
Comment thread CHANGELOG.md
Comment thread src/mats/app/pages/5_Help.py Outdated
ackermanar and others added 3 commits September 25, 2026 09:15
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants