Skip to content

BUG: Fix selected ImageProcessing numeric conversions and ranges - #1888

Open
jmarquisbq wants to merge 93 commits into
BlueQuartzSoftware:developfrom
jmarquisbq:fix/unsafe-numeric-conversions-1874
Open

jmarquisbq wants to merge 93 commits into
BlueQuartzSoftware:developfrom
jmarquisbq:fix/unsafe-numeric-conversions-1874

Conversation

@jmarquisbq

@jmarquisbq jmarquisbq commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Correct unsafe numeric conversions and range calculations in 18 NXImageProcessing filters. This is partial C15 coverage: 19 approved findings are addressed, and the remaining C15 work stays outside this increment.

Changes since the previous review

Gaussian preflight checks X and Y sigma. Execution checks Z sigma when the final image has more than one Z slice. Masked Otsu prepares its output for writing before reserving label buffers, including when it reuses a reopened destination. Threshold Maximum Connected Components rejects nonempty stores paired with a zero-volume geometry. Square preserves a failed 64-bit range read’s diagnostics, and smoothing and color export retain transfer warnings in order.

Manual Windows review — Mike’s signoff is open

Build from the latest head of fix/unsafe-numeric-conversions-1874 in both simplnx and SimplnxOoc. Use your normal Windows Release builds with DREAM3DNX_ENABLE_OOC=OFF and ON.

  • Confirm both applications start and load NXImageProcessing. In the OOC build, test Force In-Memory and Force Out-of-Core in Preferences. Use fresh pipelines and output directories for each mode.
  • Preflight and execute the following NXImageProcessing bookmarks with their supplied settings and inputs from Data/ImageProcessing_Examples. Save, close and reopen each result, then select and render the named arrays again.
Bookmark Inspect after reopening
08 Powder Particle Watershed Segmentation Distinct Powder Particles/Cell Data/Particle Labels align with the particle boundaries in materials/powder_particles.png.
16 Phase and Angle Field Transforms Tangent, Inverse Sine and Inverse Cosine retain fractional values and continuous gradients. Use am/calibration/phase_radians.mha and normalized_response.mha.
19 Serial-Section Stack Reconstruction Serial Sections/Cell Data/Section Intensity is 256 × 256 × 8 with spacing (0.5, 0.5, 1.0). Open all eight preview TIFFs and confirm that the input sections from io/serial_stack appear in order 000–007.
  • Open Otsu Multiple Thresholds, Threshold Maximum Connected Components and Write Image. Verify Nonfinite Input Handling is absent from all three. In Otsu, toggling Use Mask Array enables Mask Array and Excluded Label. In Write Image, check Create Color Table, Use Mask Array and Masked Color (RGB). Save and reopen the pipeline and confirm the settings persist.
  • Check the controls and results using the fixture below. Record the source SHAs, storage mode, and any discrepancy before signoff.
Eight-pixel control check using Python's standard library

Run this in a writable directory to create the two inputs:

from pathlib import Path
from struct import pack

def write_mha(name, pixel_type, payload):
    header = (f"ObjectType = Image\nNDims = 3\nBinaryData = True\nBinaryDataByteOrderMSB = False\n"
              f"CompressedData = False\nElementSpacing = 1 1 1\nDimSize = 8 1 1\n"
              f"ElementType = {pixel_type}\nElementDataFile = LOCAL\n")
    Path(name).write_bytes(header.encode("ascii") + payload)

write_mha("intensity.mha", "MET_FLOAT", pack("<8f", 0, 4, float("nan"), float("inf"), 0, 4, 0, float("-inf")))
write_mha("mask.mha", "MET_UCHAR", bytes([1, 1, 0, 0, 1, 1, 0, 0]))

Read each file with Read MHA/MetaImage File into a separate image geometry. Use the intensity array as the image input and the UInt8 array as the mask. Pixel numbers below run from 1 to 8.

Filter settings Expected result
Otsu with one threshold, two bins, Label Offset 7, mask enabled, Excluded Label 255, Valley Emphasis off [7, 8, 255, 255, 7, 8, 255, 255]. Only selected finite samples fit the histogram. Unmasked nonfinite pixels have no scientifically defined Otsu label.
Threshold Maximum Connected Components with Upper Boundary 12, Minimum Object Size 0, Inside Value 1 and Outside Value 0 Pixels 3, 4 and 8 receive Outside Value. All-nonfinite input gives an all-Outside image.
Write Image as PNG with Create Color Table, Grayscale and no mask Pixels 2 and 6 are white. The remaining pixels are black. Unmasked NaN and both infinities receive the first preset color.
Write Image again with the mask enabled and Masked Color (RGB) set to (255, 0, 255) Pixels 3, 4, 7 and 8 are magenta. Every excluded pixel receives the mask color. The other pixels retain their grayscale colors.

Tutorial 17 has a separate tracked issue with two unreadable negative-origin TIFF previews. The eight previews in bookmark 19 must open. simplnx #1914

This checklist verifies the source-built application. A shipping ZIP’s startup on a clean Windows machine remains a separate, open deployment check.

Companion merge order

Merge simplnx #1888 before SimplnxOoc #11. The disk-backed tests require the output types, parameters, and policies in the simplnx change. DREAM3DNX #1233 already merged and supplied the application revision used for the Windows tests below.

Historical review material

The October decision companion and earlier Windows review ZIPs document previous revisions. The companion includes superseded nonfinite-control proposals. Use the branch heads and checklist above for this review.

1. Math output types and integer limits

  • src/Plugins/NXImageProcessing/src/NXImageProcessing/utils/MathOutputUtilities.hpp supplies the selected output conversions.
  • Integer Acos, Asin and Tan inputs produce Float32 output. Integer Exp, ExpNegative, Log, Log10 and Sqrt inputs produce Float64 output. Floating inputs retain their existing types.
  • Square widens smaller integer outputs exactly and checks 64-bit overflow before multiplication.
  • Filter help records the precision/storage choices and migration options. Preserved fractions and nonfinite values can change later thresholds and segmentation. Integer-only consumers can reject promoted arrays.

2. Morphology and smoothing

HConvex and HMinima preserve native integer Height arithmetic and reject fractional Height for integer images. HConvex checks signed contrast overflow. CurvatureFlow and SmoothingRecursiveGaussian check terminal integer conversions, report clipping and reject nonfinite integer results. Their help records working-precision limits.

3. Segmentation, export and pipeline compatibility

ConnectedComponent checks provisional label capacity. MorphologicalWatershedFromMarkers checks marker ID conversion. Both offer Error and Warn policies, with Error as the default. OtsuMultipleThresholds fits thresholds from selected finite samples. The optional Bool/UInt8 mask assigns the Excluded Label to masked-out tuples. Labels at unmasked nonfinite pixels have no scientific interpretation. Preflight checks the mask type and component shape and rejects class-label collisions. Otsu validates the final mask tuple count during execution, so pipelines can use masks resized by an upstream filter. A final mismatch fails before either array is read.

ThresholdMaximumConnectedComponents checks Upper Boundary conversion and range arithmetic, corrects the midpoint, and retains the two-intensity-unit stopping tolerance. Its masks and downstream segmentation can change because of the corrected midpoint. Threshold assigns Outside Value to nonfinite pixels. WriteImage assigns the first preset color to unmasked nonfinite pixels during color mapping and gives excluded pixels the chosen mask color. Supported raw floating exports preserve the original values.

Review fixes also add first-sample diagnostics, validate filter options in preflight, and pass validated native integer Heights to the reconstruction engine. Connected Component help explains the route-dependent effects of legacy label wrap. Shipped bookmarks, Python variants and generated help use the matching contracts and parameters. Consumer-chain tests check supported migration paths. Includes, generated-header references and test tags follow the NXImageProcessing plugin name.

4. SDK headers and solver documentation

Install ImageProcessingOperationTypes.hpp with the public SDK so consumers can include the threshold engine. The Otsu solver documentation now states how it reports an empty threshold result.

Test plan

Verification for this review

The results below were recorded at simplnx d6ab00543 and SimplnxOoc 77d5b65e9 using DREAM3D-NX 8e6d7403.

  • Four isolated MSVC checks passed (2,415 assertions) for ordered transfer warnings, cancellation during Otsu write preparation, reopened destination reuse and finite disk-backed histogram counts. Negative-control runs failed at the intended Otsu and Gaussian assertions.
  • On Linux, the pair passed all 22 selected Release core cases in each storage configuration and all 1,139 non-benchmark OOC Release CTest entries, with zero failures or skips. Targeted Debug passed 33/33 (22 core and 11 filter/real-store cases). The reopened-destination case ran all 2,111 assertions. Earlier behavior-equivalent Linux revisions passed 432 in-core and 518 OOC focused Release cases and the external installed-SDK check.
  • On the first Windows behavioral snapshot, 647/647 in-core and 764/764 OOC focused Release cases passed. The isolated final-source checks above provide the Windows evidence after the lint and test-only adjustments.
Earlier source and Windows archive validation

Earlier Windows review follow-up validation

The affected ImageProcessing test target built in Windows Release in both storage configurations and in in-core Debug. These results apply to the earlier simplnx 44875faf, SimplnxOoc e191adcd and desktop 8e6d7403 revisions.

  • 96/96 focused in-core Release cases and 119/119 focused out-of-core Release cases passed.
  • Both in-core Debug Otsu regressions passed. The first runs Otsu with a mask resized by an upstream filter. The second verifies that a final mismatch returns -28908 before either store is read.
  • The broader non-benchmark out-of-core run reported zero failures across 1,131 CTest entries. One existing entry with an encoding issue matched no Catch2 case. The intended HDF5 stress case passed all 22 assertions when run separately through CTest.
  • A downstream consumer compiled the threshold engine using the staged SDK headers and dependencies. The same compile reproduced the missing-header error before the fix.
  • Changed C++ passed clang-format 19.1.1. The scoped clang-tidy run found no diagnostics on the changed lines in six translation units.
    Mike’s signoff on the current source pair is tracked in the manual Windows checklist above.

Earlier review-fix validation

The previous runs used simplnx 4758c66d8bec, SimplnxOoc 397fb6fb4050 or a960d2ccf143 as noted below, and DREAM3DNX 8e6d7403df21.

  • In-core Windows Release built the affected test targets and passed 730/730 focused cases with the companion at a960d2ccf143. Its later changes are private out-of-core tests, so the in-core binaries and coverage are unaffected.
  • Out-of-core Windows Release built the coordinated sources and passed 866/866 focused cases with the companion at a960d2ccf143. After the companion test updates, the ImageProcessing target rebuilt and 615/615 focused cases and 1,131/1,131 non-benchmark out-of-core cases passed with the companion at 397fb6fb4050.
  • The updated companion C++ tests pass clang-format 19.1.1. The simplnx PR's clang_format_pr check passed.

Earlier source verification — 12 November 2026

The coordinated pair for this section was simplnx 5e080a8ec87b and SimplnxOoc 1692f37b57e8, with DREAM3DNX 2ad8cf5982d65.

  • Both coordinated Windows Release ALL_BUILD builds passed. The final shipping builds have test hooks disabled and embed the tested source revision.
  • The affected Otsu, writer and consumer selections passed 99/99 in-memory Release, 118/118 OOC Release and 99/99 in-memory Debug, with no failures or skips.
  • After the final local-name-only correction, both Release aggregate builds passed again. The Otsu selection passed 31/31 in-memory Release, 35/35 OOC Release and 31/31 in-memory Debug, with no failures or skips.
  • The complete independent closing review was clean at the 12 November revisions, across all three repositories and all seven architecture/implementation lenses.
  • Changed C++ passes clang-format 19.1.1 with the owning repository styles.
  • Focused clang-tidy at the 12 November revisions covers 57 translation units and 24 changed headers, including all six new headers. It reports zero introduced diagnostics. The final correction was analyzed freshly; 56 other results were reused only after compiler, command, configuration and physical dependency inputs matched exactly.

Two focused Gaussian declaration reports were reproduced on pinned develop for the exact parameter pairs. Whole-TU configured analysis remains non-clean and exits 1; a whole-project zero-warning result is not claimed. One earlier LLVM tool crash was preserved, then completed in an identical-input isolated retry. No analysis coverage gap remains.

Windows archive and bookmark checks — 12 November 2026

  • Both fresh CPack ZIPs passed CRC, source/runtime identity and dependency-origin checks. Runtime smoke builds use Release with tests, Python and documentation targets disabled.
  • External serial CTest ran all 18 complete affected bookmark prefixes in each storage mode: 36/36 packaged nxrunner invocations passed. Shipped parameters and distributed inputs were preserved; only file locations and an appended diagnostic writer were supplied by the local fixture.
  • 30/36 output rows passed readability, type/shape/ownership and bounded scientific comparison against the previously approved C15 results, with no numeric tolerance. Six rows reproduced the known inherited output blockers unchanged: Tutorial 17 and both copper bookmarks in both modes. These six are not output PASS. There were zero new or worsened output failures.

Launch PATH and profiles were isolated to the package and Windows. Static runtime identities match the owning final builds and configured dependencies. Core module sampling was complete in 33/36 runs; no observed module came from outside the package or Windows. Sampling does not prove every transient DLL load. The package campaign does not establish a new physical backing-file witness or a clean-VM/GUI pass. Actual disk-backed store assertions remain part of the OOC unit coverage.

The comparison baseline retains 22 retired source-path references after the plugin-folder rename. Each replacement pipeline was checked against the exact approved hash; these are recorded historical provenance gaps, not new output failures. The bounded comparator establishes compatibility, not independent mathematical correctness.

Earlier develop-integration regression evidence

Before the final mechanical/diagnostic/preflight corrections, the paired set at public eff78a69975437cfe58e0c81b57668d20c2689d9 and the unchanged companion revisions passed:

Selection In-memory build OOC build
C15 filters, engines, cache checks and consumer chains 558/558 664/664
Core, AtomicFile, DataStructure, CLI and acceptance checks 287/287 295/295
Broad OOC regression selection — 1,131/1,131

These earlier selections overlap and are not recounted as fresh final-head tests. The numerical/storage contracts outside the final corrections are unchanged. In-memory validation uses algorithm path 0; OOC uses path 1. The broad selection excluded benchmarks and ITK-named entries; the C15 selections separately ran 35 ITK-named golden cases in each build. No benchmarks were included in those earlier selections.

Separate CI and deployment checks

  • Supported-platform CI passes with the three reviewed C15 revisions selected together. Jobs that use only develop dependencies do not validate this coordinated set.
  • Track clean-machine startup separately when a shipping package is available. Mike’s checklist above uses his source build.
5 November package record

Earlier package evidence — 5 November 2026

Earlier C15 archives passed 36/36 packaged nxrunner invocations across the 18 bookmarks and two modes. Output checks passed 30/36 rows. Six rows reproduced the inherited TIFF and copper pole-figure blockers below. A physical Serial-Section output witness matched all 524,288 stored UInt8 values to the saved result. Jessica Marquis reported the representative startup and GUI checks passed in both modes.

Those results and the previous GUI signoff belong to the earlier archives. Mike’s current source-build signoff and clean-machine shipping-package validation remain open.

The 5 November report recorded the Tutorial 17 TIFF issue and a copper pole-figure tuple-shape issue. The upstream copper correction subsequently passed the packaged comparisons. TIFF issue #1914 · Copper correction #1919

Related Issue

The C15 inventory and deferred scope are documented in the HTML review companion. This is partial coverage; no C15 issue closure is requested.

Related to #1870

@jmarquisbq jmarquisbq self-assigned this Oct 27, 2026
@jmarquisbq
jmarquisbq force-pushed the fix/unsafe-numeric-conversions-1874 branch 2 times, most recently from decbffd to 549b553 Compare November 3, 2026 16:01
joeykleingers added a commit to joeykleingers/simplnx that referenced this pull request Nov 12, 2026
Replace the knowledge-base entry that let the user choose only how a
NaN input value is handled with one rule for NaN and both infinities,
decided by where the value comes from. It follows the handling in
BlueQuartzSoftware#1888:

- Parameters: preflight rejects NaN, and rejects infinity unless the
  filter documentation gives it a meaning. Values stored into a
  floating-point array may be NaN or infinity.
- Values read from a file: the reader rejects nonfinite values where
  the format requires finite ones.
- Input array values that reach a comparison, range, histogram,
  threshold, color map, search, index or integer conversion: a
  Nonfinite Input Handling choice, Error (default) or Warn and
  Continue.
- Element-wise floating-point math passes IEEE results through and
  documents them.
- A computed nonfinite value for an integer output is an error naming
  the index and output type; finite out-of-range values are clipped
  with a warning, instead of NaN becoming 0.
- An undefined result for degenerate input is a documented NaN.

Update the saturating-cast and parameter-validation entries to match.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
@jmarquisbq
jmarquisbq force-pushed the fix/unsafe-numeric-conversions-1874 branch from e23107c to eff78a6 Compare November 12, 2026 19:17
@jmarquisbq
jmarquisbq marked this pull request as ready for review November 12, 2026 23:51
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

imikejackson pushed a commit to joeykleingers/simplnx that referenced this pull request Nov 13, 2026
Replace the knowledge-base entry that let the user choose only how a
NaN input value is handled with one rule for NaN and both infinities,
decided by where the value comes from. It follows the handling in
BlueQuartzSoftware#1888:

- Parameters: preflight rejects NaN, and rejects infinity unless the
  filter documentation gives it a meaning. Values stored into a
  floating-point array may be NaN or infinity.
- Values read from a file: the reader rejects nonfinite values where
  the format requires finite ones.
- Input array values that reach a comparison, range, histogram,
  threshold, color map, search, index or integer conversion: a
  Nonfinite Input Handling choice, Error (default) or Warn and
  Continue.
- Element-wise floating-point math passes IEEE results through and
  documents them.
- A computed nonfinite value for an integer output is an error naming
  the index and output type; finite out-of-range values are clipped
  with a warning, instead of NaN becoming 0.
- An undefined result for degenerate input is a documented NaN.

Update the saturating-cast and parameter-validation entries to match.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
imikejackson added a commit that referenced this pull request Nov 13, 2026
…1947)

* BUG: Reject kernel radii that morphology filters cannot represent

Kernel Radius is a UInt32 vector that preflight never checked. Execute
narrowed each component to int32, so a radius of 2147483648 or more
became negative, the structuring element came out empty and the filter
copied its input (top-hats and the gradient wrote zeros). Large radii
also overflowed the element-count and Safe Border size arithmetic.

- Add ValidateKernelRadius() and MakeCheckedStructuringElement() to
  StructuringElement.hpp: each radius must be at most 2147483646 and
  the element count must fit the offset vector. Allocation failures are
  returned as errors.
- Add ValidateMorphologyLayout() to MorphologyEngine.hpp. It checks the
  Safe Border padded extents and the signed coordinate, plane, volume
  and byte counts derived from the image and the radius. Preflight and
  every execution entry point call it before allocating.
- Use the flat-offset fold only when its offsets and staged indices fit
  int64, and clamp the packed binary word end without overflow.
- Negative radii in MakeStructuringElement() return an empty element
  before any negation, and its loops and shell arithmetic use int64.

Fixed filters: BinaryDilateImageFilter, BinaryErodeImageFilter,
BinaryMorphologicalClosingImageFilter,
BinaryMorphologicalOpeningImageFilter,
BinaryOpeningByReconstructionImageFilter, BlackTopHatImageFilter,
ClosingByReconstructionImageFilter, DilateObjectMorphologyImageFilter,
ErodeObjectMorphologyImageFilter, GrayscaleDilateImageFilter,
GrayscaleErodeImageFilter, GrayscaleMorphologicalClosingImageFilter,
GrayscaleMorphologicalOpeningImageFilter,
MorphologicalGradientImageFilter, OpeningByReconstructionImageFilter,
WhiteTopHatImageFilter.

Part of #1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>

* DOC: Decide NaN and infinity handling by where the value comes from

Replace the knowledge-base entry that let the user choose only how a
NaN input value is handled with one rule for NaN and both infinities,
decided by where the value comes from. It follows the handling in
#1888:

- Parameters: preflight rejects NaN, and rejects infinity unless the
  filter documentation gives it a meaning. Values stored into a
  floating-point array may be NaN or infinity.
- Values read from a file: the reader rejects nonfinite values where
  the format requires finite ones.
- Input array values that reach a comparison, range, histogram,
  threshold, color map, search, index or integer conversion: a
  Nonfinite Input Handling choice, Error (default) or Warn and
  Continue.
- Element-wise floating-point math passes IEEE results through and
  documents them.
- A computed nonfinite value for an integer output is an error naming
  the index and output type; finite out-of-range values are clipped
  with a warning, instead of NaN becoming 0.
- An undefined result for degenerate input is a documented NaN.

Update the saturating-cast and parameter-validation entries to match.

Part of #1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>

* BUG: Clip adaptive histogram equalization neighbors to the image

The Radius of AdaptiveHistogramEqualizationImageFilter is a UInt32
vector, and every neighbor loop walked the whole -r..r box and skipped
the neighbors outside the image. A radius near UINT32_MAX made each
voxel run billions of empty iterations, so the filter did not finish.

Each of the four neighbor loops (the generic and lookup-table plane
bodies and the generic and lookup-table 2D block bodies) now computes
its bounds clipped to the image before it iterates. The skipped
iterations are exactly the ones that were skipped before, in the same
order, so the accumulated sum, the in-bounds count and every output
value are unchanged. The linear uint8 paths already bounded their
traversal and are unchanged.

Part of #1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>

* REV: Restore the nonfinite skip rule and clear new clang-tidy findings

- Coding knowledge base: Warn and Continue excludes nonfinite values
  from the contributing samples and counts of reductions and
  neighborhood operations. The nonfinite-handling rules apply to new
  filters and to filters a change already fixes; bringing an existing
  filter's output type or failure behavior in line is a breaking change
  that its pull request names.
- Adaptive histogram equalization: rename the signed coordinates xi
  and yi to signedX and signedY.
- Morphology and structuring-element guards: camelCase local
  constants, checked std::array access, a kernel parameter name in the
  two new layout helpers, an explicit int64 slice product and
  parentheses in the bounding-box extents.

No behavior change.

* REV: Check kernel radii only in preflight

Filter preflight is the one place a filter's inputs are checked; the
shared morphology helpers do not repeat those checks.

- MakeCheckedStructuringElement() and ValidateMorphologyLayout() no
  longer re-run ValidateKernelRadius(); they document a validated radius
  as a precondition. The structuring element still converts allocation
  failures to an error, and the layout checks on the final geometry
  dimensions still run in preflight and execute.
- The kernel-radius tests also execute each filter with an invalid
  radius and check that it fails with the preflight code, creates no
  output and leaves the input unchanged. The test that called the
  helper directly with an invalid radius is removed.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>

* TEST: Use the NXImageProcessing plugin names after the rebase

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>

---------

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
Co-authored-by: Michael Jackson <mike.jackson@bluequartz.net>
@jmarquisbq
jmarquisbq requested review from imikejackson and joeykleingers and removed request for imikejackson and joeykleingers November 13, 2026 16:38
@joeykleingers
joeykleingers self-requested a review November 13, 2026 20:47
@imikejackson
imikejackson force-pushed the fix/unsafe-numeric-conversions-1874 branch from 5e080a8 to 4652ca7 Compare November 13, 2026 21:14
@imikejackson

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@jmarquisbq

jmarquisbq commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Review feedback checklist

Tracks all 16 items from Joey’s November 13 review, posted against 5e080a8. The priorities below are from the review.

High priority

  • 1. Decide how Otsu Warn mode handles NaN and infinity. Counting nonfinite samples in the endpoint bins can shift the fitted thresholds and change downstream phase fractions. Joey proposed excluding those samples from the histogram, assigning a documented label, reporting the count, and updating help and tests. If the previously approved behavior stays, document the exception in the coding knowledge base. Review thread

Low priority

  • 2. Identify the first offending sample in nonfinite errors. Include the input array path, flat tuple index, and what the alternative policy does in Otsu -28654 and Threshold Maximum Connected Components -28611. Use Write Image -27027 as a model. Review thread
  • 3. Align the nonfinite control labels with the knowledge base. Otsu, Threshold Maximum Connected Components, and Write Image use Nonfinite Input Handling with Error / Warn and Continue. Adopt the knowledge-base labels or update the convention to cover infinity explicitly. Review thread
  • 4. Replace raw policy indexes with named choices. Use a typed policy and named values in those three filters in place of comparisons such as == 1 and policy == 0. Review thread
  • 5. Share validation between preflight and the engines. Use common validators and named error codes for Otsu’s label range and mask tuple count, and for Threshold Maximum Connected Components’ NaN Upper Boundary. Review thread
  • 6. Give new error codes named, filter-specific ranges. Replace issue-number-based literals in Square, HConvex, HMinima, and the shared helper. Consolidate scattered Otsu codes and give Otsu and Threshold Maximum Connected Components separate 100-code ranges. Review thread
  • 7. Validate exact integer Height at the morphology engine entry. With integer input and exact Height enabled, reject nonfinite, negative, or fractional Height before converting to uint64. Reuse the validator in HConvex and HMinima preflight. Review thread
  • 8. Preserve Write Image warnings in raw mode. Merge warnings from file creation, encoding, and commit in Direct and Scanline. Carry each slice’s warnings into the raw write result. Review thread
  • 9. Remove unnecessary UnitTest::LoadPlugins() calls. Joey flagged 191 new calls. Remove them from tests that construct filters or call engines directly. Keep them where a pipeline load or UUID lookup requires the registry. Review thread
  • 10. Decide how Connected Component handles wrapped label zero. Legacy Warn mode can produce different labels in the scanline and tiled routes after overflow. Joey proposed making both routes handle zero consistently or dropping legacy continuation beyond the ID limit. Review thread
  • 11. Document the two terminal-conversion contracts. Update the coding knowledge base to say when to use ConvertTerminalImageValue, which reports clipping and rejects nonfinite integer output, and when to use SaturateCastFromDouble. Review thread
  • 12. Use generic names for shared conversion state and diagnostics. Joey also asked for a follow-up issue to retire the unchecked engine path that can discard transfer warnings. Review thread
  • 13. Simplify the filter help. Keep Write Image, Watershed from Markers, Recursive Gaussian Smoothing, and Connected Component focused on what each choice does, its default, and how older pipelines behave. Track the shared cancellation warning loss separately. Review thread

Nits

  • 14. Restore spacing in the Threshold Maximum Connected Components help. Fix Inside0/Outside1, threshold0, Outside0, threshold1, and midpoint101. Review thread
  • 15. Match existing member naming. Use the surrounding camelCase style for the new Write Image, exact Height, label limit, and marker conversion members. Review thread
  • 16. Use the Result API for value construction. Replace direct m_Expected assignments in OtsuImageEngine.hpp, HistogramEngine.hpp, and ConnectedComponentEngine.hpp. Review thread

joeykleingers
joeykleingers previously approved these changes Nov 16, 2026

@joeykleingers joeykleingers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The review fixes are in 860e902. The companion revision is BlueQuartzSoftware/SimplnxOoc#11 at 42c38a9.

Manual test on macOS (Release, out-of-core with visualization): the checklist passed in Force In-Memory and Force Out-of-Core. This includes bookmarks 16, 08 and 19, save and reopen, the Otsu Multiple Thresholds and Write Image controls, and the removal of the Connected Component legacy option. The out-of-core results were bit-identical to the in-memory results. The Windows package checks were not run.

@joeykleingers
joeykleingers force-pushed the fix/unsafe-numeric-conversions-1874 branch from 860e902 to f2b6042 Compare November 16, 2026 21:10
@joeykleingers

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Use the actual batch length to select serial labeling through 512 pixels, including a short final batch. Release measurements with one, two, four and eight thresholds on Intel and AMD CPUs established the cutoff. Check every output label across the boundary.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Compute the inverse bin width once for each nonconstant histogram. Use it for both sample batches and compact integer frequencies. Construct the coordinate diagnostic only when the bin would be invalid.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
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