imagej / imagej/ImageJ

Array.fourier() first value incorrectly calculated

Open
#262 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
786
Forks
267
PR merge metrics
No merged PRs in 30d

Description

The first value produced from the built-in macro function Array.fourier() is always incorrect. For each example I've tried, it appears to be incorrectly scaled by 1/sqrt(2). All subsequent values appear to be correct.

I have replicated this issue on numerous data sets (i.e., it is not a result of a specific input). Array.fourier() is implemented as a discrete Hartley transform which has factors of sqrt(2) and cos(pi/4) which I think is likely related.

A simple macro example is given below with graphs showing the input and current output (incorrect) and correct dft output.

```
new_array = newArray(1.044,1.516,2.197,2.752,3.363,3.947,4.53,5.183,5.725,6.35,7.308,8.405,9.863,11.433,13.447,15.433,17.683,20.113,22.891,26.225,30.516,36.669,45.558,58.225,75.738,99.141,129.183,165.794,208.891,257.155,308.766,361.308,411.516,456.419,493.058,518.711,531.613,530.433,515.961,488.516,450.669,405.197,354.752,302.488,251.586,203.877,161.891,125.766,96.419,73.294,55.822,43.113,34.086,27.613,23.044,19.655,16.947,14.808,12.905,11.363,10.058,9.086,8.433,7.877,7.697,7.488,7.058,6.752,6.419,5.877,5.266,4.655);
fourier_array = Array.fourier(new_array);
Array.print(fourier_array);
```

![imagej example](https://github.com/user-attachments/assets/c00ba6d9-61e1-4c3c-85cf-4551cf3f2068)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the implementation of the built-in Array.fourier() macro and inspect how its discrete Hartley transform handles the first value, especially the sqrt(2) and cos(pi/4) factors mentioned in the report. Run the supplied macro example and compare the first output with the expected DFT result; done means the first value is correctly scaled while subsequent values remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.