This repo contains the source code for the N4BiasCorrection functionality that is to be called from matlab as a matlab executable.
This code provides an MATLAB C++ interface to call N4BiasCorrection implemented by [SimpleITK](Source)
Building The Executable MEX
Note: The pre-compiled binary can be found here. Should you choose to compile on your own, continue reading.
-
git clone the SimpleITK project and compile following the official doc. The functionalities of this repo requires the compiled libraries from the SimpleITK project.
-
Clone this repo and in CMakeLists.txt, modify the variables
SimpleITK_DIR
andITK_DIR
.
If you built your SimpleITK using the super build example provided by their official document, these two variables should point to the
SimpleITK-build/
folder and theITK-build/
folder. You should be able to find the filesSimpleITKConfig.cmake
andITKConfig.cmake
respectively in these folders. See this tutorial on how to configure Cmake for building SimpleITK applications.
- Run cmake.
mkdir -p build
cd build/
cmake ..
Should you choose to compile with the debug mode, Run cmake with
cmake -DCMAKE_BUILD_TYPE=Debug ./
. Debug configuration example for VS Code is included in launch.json
- Compile
make
Make sure the compiled executable is in matlab's search path.
[corrected_image, log_bias_field] = N4BiasCorrection(image);
This function supports only non-conplex 2D and 3D images with data type float(single) and double.
One can also produce the bias-corrected image with:
corrected_image = image ./ exp(log_bias_field);