Skip to content

Add feature maps (fmaps) mode for sliding-kernel feature extraction#326

Open
walkerbdev wants to merge 1 commit intoPolusAI:mainfrom
walkerbdev:slide_kernel
Open

Add feature maps (fmaps) mode for sliding-kernel feature extraction#326
walkerbdev wants to merge 1 commit intoPolusAI:mainfrom
walkerbdev:slide_kernel

Conversation

@walkerbdev
Copy link
Member

@walkerbdev walkerbdev commented Mar 5, 2026

Feature Maps (fmaps) — Sliding Kernel Feature Extraction

  • Slides a K×K (or K×K×K) kernel across each parent ROI, computes features on each patch, and returns spatial feature maps
  • 2D workflow: generateChildRois() → processIntSegImagePair_fmaps() → processDataset_2D_fmaps() in new workflow_2d_fmaps.cpp
  • 3D workflow: same pattern in new workflow_3d_fmaps.cpp
  • In-memory (Python) path: processIntSegImagePairInMemory_fmaps() added to workflow_pythonapi.cpp
  • CLI dispatches to fmaps workflows when --fmaps is set via main_nyxus.cpp
  • EnvRoiSwapGuard RAII guard swaps env ROI data to child data during feature computation, restores on scope exit
  • FmapArrayResult struct holds spatial map dimensions, origin, and flat feature data array per parent ROI
  • Environment gains fmaps_mode, fmaps_kernel_radius, fmaps_kernel_size(), fmaps_prevents_arrow()

Output

  • save_features_2_fmap_arrays() — builds spatial feature maps as flat arrays stored in ResultsCache (Python/buffer path); handles both 2D and 3D via parent_zmin/parent_d parameters
  • save_features_2_csv_fmaps() — writes *_fmaps.csv with extra columns: parent_roi_label, kernel_center_x, kernel_center_y (CLI path)
  • Refactored shared helpers (get_feature_column_names, collect_feature_values, write_feature_values_csv, write_feature_header_buffer, write_feature_values_buffer) replace ~1000 lines of duplicated feature-dispatch code across all existing output paths

Python API & Bindings

  • Nyxus(features=[...], fmaps=True, fmaps_radius=2) — new constructor params with validation
  • featurize(), featurize_directory(), featurize_files() return list-of-dicts in fmaps mode, each dict containing metadata + features dict mapping feature names to numpy arrays shaped (map_h, map_w) or (map_d, map_h, map_w)
  • fmap_results_to_python() in C++ bindings converts FmapArrayResult → Python dicts with numpy arrays
  • set_fmaps_imp() binding for runtime fmaps mode toggle
  • New fmap_io.py: save_fmaps_to_tiff() and save_fmaps_to_nifti() export utilities

Binning Origin

  • New BinningOrigin enum (zero, min_based) in feature_settings.h replaces the old sign-of-n_levels hack
  • NyxSetting::BINNING_ORIGIN threaded through Fsettings to all texture features (2D and 3D)
  • TextureFeature::bin_intensities(), bin_intensities_3d(), bin_pixel() now take explicit BinningOrigin parameter — all bin counts are unsigned
  • Environment gains get/set_binning_origin() members
  • Python API passes binning_origin as a separate parameter (no more sign-encoding in coarse_gray_depth)
  • Removed duplicate free-function binning helpers from 3d_intensity.cpp

Tests

  • New test_fmaps.h — 2D fmaps unit tests
  • New test_fmaps_3d.h — 3D fmaps unit tests
  • New test_binning_origin.h — binning origin unit tests

Docs

  • README, Classes.rst, cmdline_and_examples.rst updated with fmaps usage, Python API, and CLI options

@walkerbdev walkerbdev force-pushed the slide_kernel branch 15 times, most recently from c18e43a to f4dbfcf Compare March 9, 2026 16:16
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.

1 participant