Git Product home page Git Product logo

beast's Introduction

mincbeast - implementation of BEaST

This is a C implementation of BEaST (Brain Extraction using non-local
Segmentation Technique).

The latest BEaST source code can be found at:
https://github.com/BIC-MNI/BEaST

mincbeast works with MINC1 and MINC2 images. However, experimental
support for the NIfTI format has been added. This has not yet been
tested thoroughly.

mincbeast needs a library of priors to work (see below).

Compiling
---------
mincbeast requires either MINC or NIfTI libraries. mincbeast has been
tested on Debian type Linux systems, such as Ubuntu.
To configure type:

ccmake CMakeLists.txt

and set the right paths. Then

make
make install

Troubleshooting:
- NIFTI_ROOT should be set to /usr if you installed NIfTI libraries
using the package libnifti-dev
- If the compiler cannot find hdf5.h you probably need to install
  libhdf5-serial-dev
- If you get the message: "Could not find module FindLIBMINC.cmake or
  a configuration file for package LIBMINC.", you must point to the
  directory containing either FindLIBMINC.cmake or
  LIBMINCConfig.cmake. If you have installed MINC Tool Kit,
  http://www.bic.mni.mcgill.ca/ServicesSoftware/ServicesSoftwareMincToolKit,
  the directory is most likely /opt/minc/lib

Library
-------
The library folder MUST contain these files:
library.masks.1mm
library.masks.2mm
library.masks.4mm
library.stx.1mm
library.stx.2mm
library.stx.4mm

mincbeast will try to access these six files.

The library.stx.* files contain filenames of the normalized images at
different voxel sizes as evident from the filename (1mm, 2mm, 4mm). It
is important that the filenames are in the same order across the
library files. mincbeast uses the line number in the files to link
images at different resolutions, as well as linking the images to the
segmentations.
Similarly, the library.masks.* files contain filenames of the "expert"
segmentations at different voxel sizes.

In addition, mincbeast will by default try to access two binary masks
named margin_mask.mnc and intersection_mask.mnc. These specify respectively
which voxels to process and which voxels are automatically included in the
output segmentation. These can be manually set using -mask and -positive
and disabled using -no_mask and -no_positive.

mincbeast assumes that all images are in the same space and have the
same origin. This is not checked at runtime and will lead to errors if
it is not fulfilled.

2mm and 4mm images can be generated from the 1mm images using simple
downsampling.

mincbeast uses a simple intensity based comparison metric. Thus, it is
very important that the intensities of the library images have been
normalized.

See README.library for how to install existing libraries.

Usage
-----
mincbeast [options] <library dir> <input> <output>

<library>: path to the library
<input>: input image
<output>: output segmentation


Examples
--------
Suppose your library resides in ~/beast/ and your normalized input
image is named t1w.mnc, this command will provide a segmentation at
1mm resolution:

mincbeast ~/beast/ t1w.mnc output.mnc -conf \\
~/beast/default.1mm.conf -fill -median

For faster, almost as accurate results, one may want to use the 2mm
configuration file:

mincbeast ~/beast/ t1w.mnc output.mnc -conf \\
~/beast/default.2mm.conf -fill -median -same_res


Explanation of options
----------------------
 -probability:      Output the probability map instead of crisp mask.
 -flip:             Flip images around the mid-sagittal plane to increase patch count.
 -load_moments:     Do not calculate moments instead use precalculated library moments. (for optimization purposes)
 -fill:             Fill holes in the binary output.
 		    Just in case we get errors inside the mask.
 -median:           Apply a median filter on the probability map.
 		    Makes the segmentation slightly more robust, but may limit the accuracy.
 -nlm_filter:       Apply an NLM filter on the probability map (experimental).
 -verbose:          Enable verbose output.
 -clobber:          Clobber output files
 -abspath:          File paths in the library are absolute (default is relative to library root).
 -voxel_size:       Specify voxel size for calculations (4, 2, or 1). Assumes no multiscale. Use configuration file for multiscale.
                Default value: 4
 -patch_size:       Specify patch size for single scale approach.
                Default value: 1
 -search_area:      Specify size of search area for single scale approach.
                Default value: 2
 -alpha:            Specify confidence level Alpha.
                Default value: 0.5
 -beta:             Specify smoothness factor Beta.
                Default value: 0.25
 -threshold:        Specify threshold for patch selection.
                Default value: 0.95
 -selection_num:    Specify number of selected images.
                Default value: 20
 -positive:         Specify mask of positive segmentation (inside mask) instead of the default mask.
 		    This will be added to the final segmentation
 -output_selection: Specify file to output selected files.
 -count:            Specify file to output the patch count.
 -configuration:    Specify configuration file.
 		    See the 'conf' folder for example configurations.
 -mask:             Specify a segmentation mask instead of the the default mask.
 -same_resolution:  Output final mask with the same resolution as input file.
 -no_mask:          Do not apply a segmentation mask. Perform the segmentation over the entire image.
 -no_positive:      Do not apply a positive mask.


Tuning the parameters
---------------------
The main parameters are those in the configuration files. You should
always set them in the configuration file instead of at the command
line. For example, the configuration file (default.2mm.conf) looks
like this:

# voxelsize patchsize searcharea alpha beta threshold num_selected
2 1 4 0.5 0.25 0.95 20
4 1 2 0.2 0.25 0.95 20

Each line represent a scale step. Here there are two steps, 4mm and
2mm. The default.1mm.conf file contains one more line for the 1mm
scale step. BEaST only supports these three different scales, so you
cannot add e.g. 8mm or 0.5mm.

The header shows the parameter names. "voxelsize" is on of 1, 2, or 4
indicating the scale step. BEaST always starts with the largest
voxelsize and propagates the segmentation to the next scale. The
propagation is controlled by "alpha", which determine how much
information is propagated. Here alpha is 0.2 for the 4mm scale, which
means that probabilities in the range 0.2 - 0.8 are propagated, while
<0.2 are considered background and >0.8 are considered foreground
(object). If you increase "alpha", you trust your lowres segmentation
more and propagate less to the next scale. For the final scale "alpha"
is usually 0.5, because this is the threshold for the final
segmentation. You can adjust this final threshold to control
consistent over/under-segmentation.

"patchsize" is the size of the patch when comparing structures across
the library. 1 means a patch size of 3x3x3, 2 means a patch size of
5x5x5, and so on. Increasing this may give better results, but also
seriously increases the computational time.

"searcharea" is the size of the spatial neighborhood in which to look
for similar patches. This is similar to the "patchsize" in that e.g.
2 ~ 5x5x5 and 4 ~ 9x9x9.

"beta" is a smoothness parameter. Usually in the range 0-1. Larger
beta means more smooth.

"threshold" is a parameter controlling the preselection of
patches. Preselection makes sure to only include patches that have
some similarity. The range is 0-1. The higher the more strict (fewer
patches selected).

"num_selected" is the number of images to select from the library when
looking for similar structures. Usually the higher the
better. However, the improvement is asymptotic and the memory usage
quickly rises with larger N.

For the command line options, the important ones are:

-same_res which simply makes sure that the output has the same
 resolution as the input no matter the configuration file.

-median applies a median filter on the probability map before
 propagation. This also smoothes the result and should be used when
 the library is not perfect (i.e. from another population than the
 image to segment).

-fill can always be used as this just morphologically fills any holes
 in the segmentation.

The remaining command line options are not really relevant for
tuning. However, you may want to output the probability map (using
-probability) when determining the best "alpha".

Populating the library
----------------------
The best way to improve your results is to populate the library with
images/masks from the same scanner as the the images you are trying to
segment. One way to do this is to run BEaST with the default ICBM/ADNI
images and then select the best masks among the results, possibly
perform some manual corrections, and put them into the library. Then
run BEaST again. This bootstrapping method can be performed
iteratively with increasing performance improvements.

For more on populating the library, please see README.library

Reference
---------
Please cite BEaST as:

Simon F. Eskildsen, Pierrick Coupé, Vladimir Fonov, José V. Manjón,
Kelvin K. Leung, Nicolas Guizard, Shafik N. Wassef, Lasse R. Østergaard,
D. Louis Collins, and The Alzheimer's Disease Neuroimaging Initiative,
BEaST: Brain extraction based on nonlocal segmentation technique,
NeuroImage, vol. 59(3), pp. 2362-2373.
ISSN 1053-8119, 10.1016/j.neuroimage.2011.09.012.

Contact
-------
For questions and feedback, please contact
Simon Fristed Eskildsen <[email protected]> 

beast's People

Contributors

fristed avatar hazedine avatar vfonov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beast's Issues

beast_prepareADNIlib error

The minc tool kit that I install with command ('dpkg -i .deb') is located in /opt/minc/1.9.16 (1.9.16 is the version). However, in the beast_prepareADNIlib line 61, it tries to locate 'minc-toolkit-config.sh' under /opt/minc/, but couldn't find it. I can adapt it to my code, but I feel it is desirable to have a more general way to do that.

#!/bin/bash not in first line of script files

I just built BEaST and noticed that the #!/bin/bash line is not at the correct (first line) position in the beast_normalize and beast_prepareADNIlib files (I'm running the fish shell in my terminals - that's why I noticed this issue).

mincbeast segmentation fault with newer gcc

When compiling with 9.1.1 (Fedora) the tests fail with a segmentation fault. This does not occur with older versions of gcc (4.8.5 Centos7). It also does not occur when compiling in debug mode. I started doing some digging, and I believe the error occurs during argument parsing, due to this issue.

BeAST doesn't exit with error code on file write failure

Running in a script with "set -e" to stop immediately on error:

Writing a binary volume...
Error creating HDF file '/tmp/tmp.wdSGm0Jpu9/beastmask0.mnc' with mode '2', result -1
HDF5-DIAG: Error detected in HDF5 (1.8.15-patch1) thread 0:
  #000: /opt/quarantine/minc-toolkit/1.9.11/src/build/HDF5/src/H5F.c line 522 in H5Fcreate(): unable to create file
    major: File accessibilty
    minor: Unable to open file
  #001: /opt/quarantine/minc-toolkit/1.9.11/src/build/HDF5/src/H5Fint.c line 1001 in H5F_open(): unable to open file: time = Thu Dec  1 16:45:32 2016
, name = '/tmp/tmp.wdSGm0Jpu9/beastmask0.mnc', tent_flags = 13
    major: File accessibilty
    minor: Unable to open file
  #002: /opt/quarantine/minc-toolkit/1.9.11/src/build/HDF5/src/H5FD.c line 993 in H5FD_open(): open failed
    major: Virtual File Layer
    minor: Unable to initialize object
  #003: /opt/quarantine/minc-toolkit/1.9.11/src/build/HDF5/src/H5FDsec2.c line 343 in H5FD_sec2_open(): unable to open file: name = '/tmp/tmp.wdSGm0Jpu9/beastmask0.mnc', errno = 13, error message = 'Permission denied', flags = 13, o_flags = 242
    major: File accessibilty
    minor: Unable to open file
(from micreate): Unable to create file '/tmp/tmp.wdSGm0Jpu9/beastmask0.mnc'
Error: opening MINC file "/tmp/tmp.wdSGm0Jpu9/beastmask0.mnc".

Script continued to run.

minc/minc-toolkit-v2/BEaST/nlmsegFuzzy.c(271): error: invalid parallel pragma

I got a pragma error on beast while compiling beast with the minc toolkit v2

On fedora 23

icpc --version
icpc (ICC) 15.0.3 20150407
Copyright (C) 1985-2015 Intel Corporation. All rights reserved.

minc/minc-toolkit-v2/BEaST/nlmsegFuzzy.c(271): error: invalid parallel pragma
        #pragma parallel for reduction(+:count)

... And just commented the line.

beast_normalize error: No points were chosen by the specified criteria

head.mnc.zip

I am having trouble running beast_normalize on my dataset. I am using minc-toolkit-v2 1.9.16 installed with the supplied singularity container. The command I am running is:

singularity exec ~/singularity/minc-toolkit-1.9.16.simg \
  beast_normalize head.mnc head_mni.mnc tmp/anat2mni.xfm \
  -modeldir /opt/minc/share/icbm152_model_09c

After the "Transforming slices..." step, it exits with the message:

No points were chosen by the specified criteria
resample_labels: crashed while running extracttag (termination status=256)
nu_estimate_np_and_em: crashed while running resample_labels (termination status=256)
nu_correct: crashed while running nu_estimate_np_and_em (termination status=256)

I have attached an example image file that I am using; the scan is derived from a scan in the public domain: TCIA-GBM collection (subject TCGA-12-3650).

How can I debug? Given that it happens with all scans in my database, this must either be a problem with my install or the dataset I am using but I am at a loss as to progress further. I would be grateful for any advice.

MT_USE_OPENMP needs to be undefined if OpenMP is not found

If OpenMP isn't found, a warning is emitted:
https://github.com/BIC-MNI/BEaST/blob/develop/CMakeLists.txt#L97-L106

But there are ifdefs everywhere which will still compile-in openmp calls.

This is my remaining bug for 32bit Centos6, where OpenMP is either broken or cmake can't find it properly:

  35781 -- Could NOT find OpenMP_C (missing: OpenMP_pthread_LIBRARY) (found version "3.1")
  35782 -- Could NOT find OpenMP_CXX (missing: OpenMP_pthread_LIBRARY) (found version "3.1")
  35783 -- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
  35784 CMake Warning at CMakeLists.txt:104 (message):
  35785   OpenMP NOT found

And then a linking error because the omp_thread calls were still in the code:

  36035 [ 94%] Building CXX object CMakeFiles/mincbeast.dir/mincbeast.o
  36036 [100%] Linking CXX executable mincbeast
  36037 CMakeFiles/mincbeast.dir/mincbeast.o: In function `main':
  36038 mincbeast.cpp:(.text.startup+0x30): undefined reference to `omp_get_max_threads'
  36039 libbeast.a(beast_lib.o): In function `median_filter(float*, int*, int)':
  36040 beast_lib.cpp:(.text+0x126): undefined reference to `omp_get_max_threads'
  36041 beast_lib.cpp:(.text+0x141): undefined reference to `omp_get_max_threads'
  36042 beast_lib.cpp:(.text+0x1b2): undefined reference to `omp_get_thread_num'
  36043 beast_lib.cpp:(.text+0x409): undefined reference to `omp_get_max_threads'
  36044 libbeast.a(nlmsegFuzzy.o): In function `nlmsegFuzzy4D(float const*, float const*, float const*, float const*, float const*, float const*, int, int, float, float, int const*, int, float*, float*)':
  36045 nlmsegFuzzy.cpp:(.text+0x14): undefined reference to `omp_get_max_threads'
  36046 nlmsegFuzzy.cpp:(.text+0x2b): undefined reference to `omp_get_max_threads'
  36047 nlmsegFuzzy.cpp:(.text+0x42): undefined reference to `omp_get_max_threads'
  36048 nlmsegFuzzy.cpp:(.text+0x13d): undefined reference to `omp_get_max_threads'
  36049 libbeast.a(nlmsegFuzzy.o):nlmsegFuzzy.cpp:(.text+0x362): more undefined references to `omp_get_max_threads' follow
  36050 libbeast.a(nlmsegFuzzy.o): In function `nlmsegFuzzy4D(float const*, float const*, float const*, float const*, float const*, float const*, int, int, float, float, int const*, int, float*, float*)':
  36051 nlmsegFuzzy.cpp:(.text+0x3b3): undefined reference to `omp_get_thread_num'
  36052 nlmsegFuzzy.cpp:(.text+0x3bf): undefined reference to `omp_get_num_threads'
  36053 nlmsegFuzzy.cpp:(.text+0x3ec): undefined reference to `omp_get_thread_num'
  36054 nlmsegFuzzy.cpp:(.text+0x3ff): undefined reference to `omp_get_thread_num'
  36055 nlmsegFuzzy.cpp:(.text+0x412): undefined reference to `omp_get_thread_num'
  36056 nlmsegFuzzy.cpp:(.text+0xb9b): undefined reference to `omp_get_max_threads'
  36057 nlmsegFuzzy.cpp:(.text+0xc8b): undefined reference to `omp_get_max_threads'
  36058 libbeast.a(nlmsegFuzzy.o): In function `nlmsegFuzzy4D_double(float const*, float const*, float const*, float const*, float const*, float const*, int, int, double, double, int const*, int, float*, float*)':
  36059 nlmsegFuzzy.cpp:(.text+0xd8d): undefined reference to `omp_get_max_threads'
  36060 nlmsegFuzzy.cpp:(.text+0xda4): undefined reference to `omp_get_max_threads'
  36061 nlmsegFuzzy.cpp:(.text+0xdbb): undefined reference to `omp_get_max_threads'
  36062 libbeast.a(nlmsegFuzzy.o):nlmsegFuzzy.cpp:(.text+0xeb3): more undefined references to `omp_get_max_threads' follow
  36063 libbeast.a(nlmsegFuzzy.o): In function `nlmsegFuzzy4D_double(float const*, float const*, float const*, float const*, float const*, float const*, int, int, double, double, int const*, int, float*, float*)':
  36064 nlmsegFuzzy.cpp:(.text+0x1129): undefined reference to `omp_get_thread_num'
  36065 nlmsegFuzzy.cpp:(.text+0x1135): undefined reference to `omp_get_num_threads'
  36066 nlmsegFuzzy.cpp:(.text+0x1162): undefined reference to `omp_get_thread_num'
  36067 nlmsegFuzzy.cpp:(.text+0x1178): undefined reference to `omp_get_thread_num'
  36068 nlmsegFuzzy.cpp:(.text+0x118b): undefined reference to `omp_get_thread_num'
  36069 nlmsegFuzzy.cpp:(.text+0x1927): undefined reference to `omp_get_max_threads'
  36070 nlmsegFuzzy.cpp:(.text+0x1a14): undefined reference to `omp_get_max_threads'
  36071 collect2: error: ld returned 1 exit status

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.