Skip to content

Commit

Permalink
https://github.com/rordenlab/niimath/issues
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Jan 27, 2020
1 parent b20747e commit 4b8690a
Show file tree
Hide file tree
Showing 25 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ It is said that `imitation is the sincerest form of flattery`. This project emul
7. While the code is completely reverse engineered, the FSL team has been gracious to allow us to copy their error messages and help information. This allows true plug in compatibility. They have also provided pseudo code for poorly documented routines. This will allow the community to better understand the actual algorithms.
8. This project provides an open-source foundation to introduce new features that fill gaps with the current FSL tools (e.g. unsharp, sobel, resize functions). For future releases, Bob Cox has graciously provided permission to use code from [AFNI's](https://afni.nimh.nih.gov) 3dTshift and 3dBandpass tools that provide performance unavailable within [FSL](https://neurostars.org/t/bandpass-filtering-different-outputs-from-fsl-and-nipype-custom-function/824). Including them in this project ensures they work in a familiar manner to other FSL tools (and leverage the same environment variables).

The Reason to use fslmaths instead of niimath:

1. niimath is new and largely untested software. There may be unknown corner cases where produces poor results. fslmaths has been used for years and therefore has been battle tested. In the few instances where fslmaths generates results that bear no resemblance to its own documentation (as described below), one could argue it is the `correct` result (with comparison to itself). An example of this is `-dilD`, where fslmaths generates a blurred and spatially shifted image, which is not what the documentation describes. However, many tools may have been developed to assume this loss of high frequency signal and these tools may not perform well when provided with the result specified in the documentation.

## Installation

You can get niimath using three methods:
Expand All @@ -26,7 +30,14 @@ You can get niimath using three methods:

## Compilation

Assuming you have a C compiler installed, you can compile the software by running the terminal command `make` from the projects folder.
The easiest way to build niimath on a Unix computer is to use cmake:

```
git clone https://github.com/rordenlab/niimath.git
cd niimath; mkdir build; cd build; cmake ..
make
```
Alternatively, you can compile the software by running the terminal command `make` from the project's `src` folder.

Advanced users may want to run `CF=1 OMP=1 make -j` to make a version that uses OpenMP (parallel processing) and the CloudFlare accelerated compression library. You may need to edit the `Makefile` for your compiler name. On MacOS, the default C compiler is Clang, which has [poor OpenMP](https://github.com/neurolabusc/simd) support. Therefore, MacOS users may want to install the gcc compiler `brew install gcc@9`.

Expand Down Expand Up @@ -83,6 +94,7 @@ Some operations do generate known meaningfully different results. These are list
9. The fslmaths function `-rem` returns the **integer** modulus remainder. This is unexected, e.g. in Python `2.7 % 2` is 0.7, as is Matlab's `mod(2.7, 2)`, as is standard C `fmod`. niimath clones the fslmaths idiosyncratic behavior, but perhaps a new function (e.g. `-mod`) could be introduced.
10. Be aware that fslmaths takes account of whether the image has a negative determinant or not (flipping the first dimension). However, fslstats does not do this, so fslstats coordinates are often misleading. For example, consider an image in RAS orientation, where the command `fslstats tfRAS -x` will give coordinates that are incompatible with fslmath's `tfceS` function. niimath attempts to emulate the behavior of fslmaths for the relevant functions (-index -roi, -tfceS).
11. Neither `-subsamp2` nor `-subsamp2offc` handle anti-aliasing. Be aware thgat `-subsamp2offc` can exhibit odd edge effects. The problem is simple to describe, for slices in the middle of a volume, and output slice is weighted 50% with the center slice, and 25% for the slice below and the slice above. This makes sense. However, bottom slices (as well as first rows, first columns, last rows, last columns, last slices) the filter weights 75% on the central slice and just 25% on the slice above it. Signal from this 2nd slice is heavily diluted. A better mixture would be 66% edge slice and 33% 2nd slice. This latter solution is used by niimath.
12. fslmaths is unable to process files where the string ".nii" appears in a folder name. For example, consider the folder "test.niim", the command `fslmaths ~/test.niim/RAS -add 0 tst` will [generate an exception](https://github.com/FCP-INDI/C-PAC/issues/976). niimath will recognize that this is a folder name and not a file extension and work correctly.

Finally, it is possible that there are some edge cases where niimath fails to replicate fslmath. This is new software, and many of the operations applied by fslmaths are undocumented. If users detect any problems, they are encouraged to generate a Github issue to report the error.

Expand Down
Binary file added niimath
Binary file not shown.
Empty file modified src/CMakeLists.txt
100755 → 100644
Empty file.
6 changes: 4 additions & 2 deletions src/Makefile
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ CNAME=gcc
#linker flags
LFLAGS=-lm -lz
#c flags
CFLAGS=-O3 -DHAVE_ZLIB
#CFLAGS=-O3 -DHAVE_ZLIB
# Westmere required for fast gz https://github.com/tikv/tikv/issues/4843
CFLAGS=-O3 -DHAVE_ZLIB -march=westmere

#run "OMP=1 make -j" for both OpenMP and CloudFlare
ifeq "$(OMP)" "1"
Expand All @@ -12,5 +14,5 @@ ifeq "$(OMP)" "1"
endif

all:
$(CNAME) $(CFLAGS) $(CFLAGS) -o niimath niimath.c core.c tensor.c core32.c core64.c niftilib/nifti2_io.c znzlib/znzlib.c -I./niftilib -I./znzlib $(LFLAGS)
$(CNAME) $(CFLAGS) -o niimath niimath.c core.c tensor.c core32.c core64.c niftilib/nifti2_io.c znzlib/znzlib.c -I./niftilib -I./znzlib $(LFLAGS)

4 changes: 4 additions & 0 deletions src/core.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <immintrin.h>
#include <limits.h>

#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif

int nifti_save(nifti_image * nim, const char *postfix) {
char extnii[5] = ".nii"; /* modifiable, for possible uppercase */
char exthdr[5] = ".hdr";
Expand Down
Empty file modified src/core.h
100755 → 100644
Empty file.
Empty file modified src/core32.c
100755 → 100644
Empty file.
Empty file modified src/core32.h
100755 → 100644
Empty file.
Empty file modified src/core64.c
100755 → 100644
Empty file.
Empty file modified src/core64.h
100755 → 100644
Empty file.
Empty file modified src/license.txt
100755 → 100644
Empty file.
Empty file modified src/niftilib/nifti1.h
100755 → 100644
Empty file.
Empty file modified src/niftilib/nifti2.h
100755 → 100644
Empty file.
Empty file modified src/niftilib/nifti2_io.c
100755 → 100644
Empty file.
Empty file modified src/niftilib/nifti2_io.h
100755 → 100644
Empty file.
Empty file modified src/niimath.c
100755 → 100644
Empty file.
Empty file modified src/tensor.c
100755 → 100644
Empty file.
Empty file modified src/tensor.h
100755 → 100644
Empty file.
Binary file added src/tst.nii
Binary file not shown.
Empty file modified src/ucm.cmake
100755 → 100644
Empty file.
Empty file modified src/znzlib/CMakeLists.txt
100755 → 100644
Empty file.
Empty file modified src/znzlib/Makefile
100755 → 100644
Empty file.
Empty file modified src/znzlib/config.h
100755 → 100644
Empty file.
Empty file modified src/znzlib/znzlib.c
100755 → 100644
Empty file.
Empty file modified src/znzlib/znzlib.h
100755 → 100644
Empty file.

0 comments on commit 4b8690a

Please sign in to comment.