Skip to content

BUG: Produce Float64 math results for integer images - #2016

Open
jmarquisbq wants to merge 2 commits into
BlueQuartzSoftware:developfrom
jmarquisbq:fix/image-float64-math-output
Open

jmarquisbq wants to merge 2 commits into
BlueQuartzSoftware:developfrom
jmarquisbq:fix/image-float64-math-output

Conversation

@jmarquisbq

@jmarquisbq jmarquisbq commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge order. #2008 has merged. Merge this change before BlueQuartzSoftware/SimplnxOoc#61.

Summary

Exp, Exp Negative, Log, Log10 and Sqrt now produce Float64 arrays for integer input. Each filter keeps Float32 input as Float32 and Float64 input as Float64. Preflight and execution use the same element type, tuple dimensions and component dimensions.

An integer input of 2 gives approximately 0.693147 in Log and 1.414214 in Sqrt. Previously saved pipelines retain their parameter settings. An integer-only downstream filter may need an explicit conversion, and thresholds tuned to quantized values may need adjustment. A Float64 output uses eight bytes per component before storage metadata or compression. 20 files changed, including 1 binary image. Text changes total +1354 / −44 lines.

Related PRs

Design

Integer input uses Float64 for these five filters. Float64 keeps exp(100) finite and exp(-120) nonzero. Float32 rounds those values to infinity and zero, respectively. Log, Log10, and Sqrt retain the precision of their Float64 computation and share the same output type with the exponential filters. Acos, Asin, and Tan keep their existing Float32 output for integer input, which uses 4 bytes per component. These five filters use 8 bytes per component. Floating-point inputs keep their original output type in both groups.

Compute each image component in Float64, then round to its selected output type with the same helper used for Tan. This preserves fractional results on integer inputs and shares one Float32 narrowing rule. A 64-bit input beyond 2^53 in magnitude can round when converted to Float64. Exp Negative converts its input before negation, including for the minimum signed integer.

The Float32 overflow-midpoint tests and mixed-type first-transfer checks live with their first consumer in simplnx #2008. They address review items 1.6 and 5.1.

The Log guide now shows a UInt8 input beside the saved Float64 output from the actual filter. The two panels use a common grayscale scale. Domain results, including negative infinity at zero in Log and Log10 and NaN for a negative Sqrt input, follow floating-point arithmetic. Any future policy for issuing warnings about nonfinite data is tracked in simplnx #2002.

Test plan

Verified on simplnx d4f018879 with SimplnxOoc c753d9b2e and DREAM3D-NX 209d77790.

  • Linux Release passed 98 focused in-core and 119 focused OOC cases. Both runs included the shared consumer test and BUG: Preserve floating trig results for integer images #2008 conversion regressions.
  • Windows Release passed the same 98 focused in-core cases.
  • All 1,075 registered non-benchmark OOC cases passed with zero skips.
  • clang-format and clang-tidy 19.1.1 passed. The lint checks covered 12 simplnx C++ files and 5 SimplnxOoc test files.
  • Hosted CI on the published rebased head. Azure run 11074
Earlier checks and review ledger
  • On the original behavior, all 40 integer preflights returned the input element type and failed the Float64 expectation. All ten floating controls retained their type and returned the expected values. The integer baseline checks stopped at preflight.
  • A Windows Release pipeline saved UInt8 input bands of 1, 2, 3 and 4 and their Float64 natural logarithms. The output matched 0, 0.6931471805599453, 1.0986122886681098 and 1.3862943611198906. The two-panel image was rendered from those saved arrays. Its labels, common scale and panel alignment were visually checked at the final resolution.
  • On the changed filters, all 50 type probes passed. Windows Release passed 103 focused CTest registrations, including all five Float32 ITK comparison images and the ten-section resident consumer test.
  • The shipped Radiography Intensity Calibration bookmark ran with its supplied inputs. Independent calculations matched all 655,360 saved Float32 values across the five transformed arrays.
  • Both Linux Release aggregate builds passed using only the public change with merged private develop. The focused selections passed 203/203 in-core and 245/245 OOC-enabled tests. With the private companion, both builds passed and the same selection passed 203/203 in-core and 257/257 OOC-enabled registrations.
  • The full nonbenchmark Linux OOC suite passed all 1,075 registered cases. At that earlier PR head, the source differed from the tested inputs only in the Doxygen comment on a test helper.
  • The original BUG: Preserve floating trig results for integer images #2008 conversion midpoint, floating special-value and mixed-type first-transfer tests passed against the split code in both Linux Release configurations. Those three tests ran as separately identified prerequisite checks.
  • The final assertion-enabled Linux Debug build passed all 82 selected cases. These included all 40 integer promotions, floating-point type and domain controls, consumer chains, and transfer failure and cancellation cases. The recorded compile flags were -O0 -g1 with no NDEBUG.
  • The changed C++ files pass clang-format 19.1.1. No new diagnostics remained in the changed-line clang-tidy 19.1.5 checks.

Earlier review ledger

Body checked at: ad7051d6bdbfb59d2c9effaf45d5f3de7abf41eb

Original size: eight production/build files and 108 changed production lines, excluding documentation and tests. The full public and private changes were reviewed together. Risk comes from the output element type and its downstream consumers.

Finder tier: strongest available
Verifier: same family

Problem: #1874, ExpImageFilter#1, ExpNegativeImageFilter#1, LogImageFilter#1, Log10ImageFilter#1 and SqrtImageFilter#1. Writing an integer result lost fractional values and could require an invalid numeric conversion.

Parts and design (C2, C3): The five filters use one type map for preflight and execution. The pointwise engine already handles mixed input and output types. Each filter computes its own mathematical operation. The conversion and shared test helper are byte-identical to the named #2008 prerequisite. The grouped tests follow the values into downstream threshold and labeling filters.

Related Issue

Related to #1874

@imikejackson imikejackson 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.

Review of PR #2016: Produce Float64 math results for integer images

Reviewed commit: c1cc6ec66, one commit on develop 8c25e4251. All 22 changed files were reviewed.

Verdict: Request Changes. The code is correct and I found no wrong result. The request is for item 1.1: I want your answer on the Float32 and Float64 difference between this PR and #2008 before this merges. The rebase in item 1.2 is also needed.

Each item has a number, so you can answer "fixed 1.3, 3.1 left as is because ..." in a reply.

Labels: Blocking = must change before merge; Needs justification = needs your answer, and "it stays, because ..." is a valid answer; Optional = you may ignore it without a reply.


1. Does the PR solve the problem with good C++ practice and good design?

Yes. All five filters pass the same IntegerToFloat64Type map to preflight and to execute, so the created array and the written array cannot disagree. Float32 and Float64 input behave as before, and the ITK comparison tests still pass. Exp Negative negates after the conversion to Float64, so the minimum signed integer and unsigned values are safe.

  • 1.1 Needs justification [XXX, needs an answer]: integer input gives Float64 here and Float32 in #2008

    • Acos, Asin and Tan (#2008) map integer input to Float32. Exp, Exp Negative, Log, Log10 and Sqrt map integer input to Float64.
    • Effect for a user: a UInt8 volume grows 8 times through Log and 4 times through Tan. Two math filters from the same group give different output types for the same input.
    • The #1888 review settled that integer input gives floating-point output. It did not settle the width, and neither PR says why the two families differ.
    • Question: why is the output Float64 for these five filters and Float32 for the three trigonometric filters? Should the two families use the same type? If the difference stays, please state the reason in the PR description and in the help pages.
  • 1.2 Blocking for merge, not for the code: rebase after #2008 merges

    • This PR carries its own copies of the shared files of #2008. Two of them differ from the current head of #2008 (1c2f2a424), so the rebase will conflict:
      • src/simplnx/Utilities/ImageProcessing/TerminalImageConversion.hpp has an extra NOLINTNEXTLINE line here.
      • src/simplnx/Utilities/ImageProcessing/ImageProcessingConstants.hpp adds IntegerToFloat64Type at the place where #2008 adds IntegerToFloat32Type.
    • The PR description says the prerequisite files are byte-identical to #2008. That is no longer true. Please correct the description after the rebase.
    • The direct test of NarrowFloatingImageValue (test/ImageNumericContractsTest.cpp) arrives with #2008, so the merge order in the description must hold.
    • CI must be green on the rebased head before approval.
  • 1.3 Optional: the new test namespace and its lint comments

    • src/Plugins/NXImageProcessing/test/Float64MathConsumerTest.hpp:5 opens nx::core::UnitTest, and its comment says that it reopens the shared test namespace. The shared namespace on develop is nx::core::unit_test. No UnitTest namespace exists there.
    • The NOLINT on that line and the NOLINTNEXTLINE in TerminalImageConversion.hpp:9 suppress nothing: .clang-tidy on develop ignores namespace names (NamespaceIgnoredRegexp: .*).
    • Fix: declare the helper in nx::core::unit_test and remove both comments. The matching change is needed in BlueQuartzSoftware/SimplnxOoc#61.

2. Error handling and defensive programming

No findings. The change adds no failure branch, so it needs no new error code. Domain results (negative infinity for the logarithm of zero, NaN for the root of a negative value) follow IEEE arithmetic. This agrees with the knowledge base rule for element-wise results and with #2002. The Float32 narrowing uses the helper from #2008.

3. Does the PR go beyond the issue?

No. The copies of the #2008 header, CMake line and test helper are explained in the description, and the rebase removes them.

  • 3.1 Optional: location of the consumer test
    • The test of all five filters through thresholding and component labeling is in ExpNegativeImageFilterTest.cpp and has only the [ExpNegativeImageFilter] filter tag. A run that selects LogImageFilter, for example, does not include it.
    • Fix: move it to a file with a neutral name, or add the tags of all five filters.

4. Behavior change and documentation

The five help pages are updated and agree with the code. The Log figure agrees with its data: each gray level in both panels matches the 0 to 4 scale. The Radiography Intensity Calibration pipeline does use all five filters.

  • 4.1 Optional: memory use in the help pages

    • The pages do not give the memory cost of the Float64 output. One sentence is sufficient: the output uses 8 bytes for each component, which is 8 times the size of a UInt8 input. Item 1.1 can change this number.
  • 4.2 Optional: stale example in the knowledge base

    • docs/Coding_Knowledge_Base.md, entry "Write floating-point output through a saturating cast", still names ExpImageFilter and LogImageFilter as filters that cast straight to integer output. #2008 updates that sentence for TanImageFilter. After the rebase, please update it for these filters also.

Evidence

Check Result
Local build, macOS arm64 Release, full tree Passed
ctest -R "NXImageProcessing::(Exp|ExpNegative|Log|Log10|Sqrt)ImageFilter" -j 1 72 of 72 passed
Expected values in the tests Independent. I calculated the logarithm, root and exponential constants separately, and they agree.
Test fails without the fix By inspection only. develop returns the input type, and the preflight assertion requires Float64. I did not run the tests on develop.
CI on c1cc6ec66 Passed: clang-format, clang-tidy, and Azure on Linux, Windows and macOS
Out-of-core Not run by me. It needs BlueQuartzSoftware/SimplnxOoc#61.
Debug build, local clang-format and clang-tidy Not run by me

* COMP: Carry the shared conversion prerequisites from simplnx BlueQuartzSoftware#2008
* BUG: Produce Float64 math results for integer images
Document the output width and storage cost. Update the shared math
consumer test and its selection for each covered filter.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
@jmarquisbq
jmarquisbq force-pushed the fix/image-float64-math-output branch from c1cc6ec to d4f0188 Compare December 2, 2026 20:32
@jmarquisbq

Copy link
Copy Markdown
Contributor Author

@imikejackson, the review updates are published. Review

1.1 — Float64 math and Float32 trig. I kept the five filters on Float64 for integer input. For example, Float64 keeps exp(100) finite and exp(-120) nonzero. The Float32 results are infinity and zero, respectively. Log, Log10, and Sqrt keep the precision of their Float64 computation and share the output type with the exponential filters. Acos, Asin, and Tan keep the existing Float32 output for integer input, which uses 4 bytes per component. The help pages and the PR description explain the difference.

1.2 — Rebase after #2008. The public PR is rebased onto simplnx 37847704, which contains #2008. It uses the merged SDK header, install registration, and test helper. The published companion is rebased onto SimplnxOoc 85fd4883.

1.3 — Shared test namespace and lint comments. The declaration, definition, and both callers use nx::core::unit_test. The branch-added redundant suppressions are gone. clang-tidy 19.1.1 passed on the final trees.

3.1 — Consumer test selection. Both shared cases carry all five filter tags and name all five filters in their registered test names. A CTest search for any of those filter names includes the consumer case.

4.1 — Output storage. The five help pages give the Float64 cost of 8 bytes per component and the eightfold storage for UInt8 input.

4.2 — Knowledge base. The saturating-cast example now names Exp and Log as historical integer-output cases and states their current promotion, alongside Tan.

On the published pair d4f018879 and c753d9b2e, Linux Release passed 98 focused in-core and 119 focused OOC cases. The full non-benchmark OOC selection passed all 1,075 cases. Windows Release also passed the 98 focused in-core cases. Hosted CI on the rebased head

@imikejackson
imikejackson self-requested a review December 2, 2026 21:05
@imikejackson
imikejackson self-requested a review December 2, 2026 21:06

@imikejackson imikejackson 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.

Round two of PR #2016: Approve

Reviewed commit: d4f018879, the commits since round one at c1cc6ec66.

Verdict: Approve. Every item from round one is resolved. The approval holds when Azure CI on d4f018879 passes. A failing CI blocks the merge in any case.

  • 1.1 Answer accepted. Float64 keeps exp(100) finite and exp(-120) nonzero, where Float32 gives infinity and zero. Log, Log10 and Sqrt share the policy of the exponential filters. All five help pages and the description state the difference from Acos, Asin and Tan.
  • 1.2 Rebased onto develop with #2008. The copied header, CMake line and test helper are gone, and the code uses the merged image_processing helpers. The description is corrected.
  • 1.3 The helper is in nx::core::unit_test, and the unneeded suppressions are removed.
  • 3.1 The consumer test carries the names and tags of all five filters.
  • 4.1 All five help pages give the Float64 storage cost.
  • 4.2 The knowledge base example is updated.

Evidence

Check Result
Range-diff of the rebased commit against c1cc6ec66 Only the prerequisite copies removed and the namespace rename to image_processing
Review commit d4f018879 Help pages, knowledge base, test names and tags, and identifier names. No change to filter code
clang-format, clang-tidy, Azure macOS Passed
Azure Linux and Windows Running when this review was posted
Local build and tests in this round Not run by me
Out-of-core Not run by me. Needs BlueQuartzSoftware/SimplnxOoc#61

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.

2 participants