├── .circleci └── config.yml ├── .gitignore ├── CHANGELOG ├── LICENSE.rst ├── README.rst ├── THANKS.rst ├── colormap ├── group_colors │ ├── label_graph.png │ ├── label_subgraph1.png │ ├── label_subgraph2.png │ ├── label_subgraph3.png │ ├── label_subgraph4.png │ ├── label_subgraph5.png │ └── label_subgraph6.png ├── label_adjacency_matrix.csv ├── label_colormap.csv ├── label_colormap.json ├── label_colormap.png ├── label_colormap.xml └── no_groups │ ├── label_colormap.csv │ ├── label_colormap.json │ ├── label_colormap.png │ ├── label_colormap_original.png │ ├── label_graph.png │ └── label_subgraph1.png ├── colors_script ├── calc_colormap.py └── convert_to_mipav_lut.py ├── docs ├── Makefile ├── _templates │ └── layout.html ├── api │ ├── info.rst │ ├── mindboggle.evaluate.rst │ ├── mindboggle.features.rst │ ├── mindboggle.guts.rst │ ├── mindboggle.mio.rst │ ├── mindboggle.rst │ ├── mindboggle.shapes.rst │ ├── mindboggle.shapes.zernike.rst │ ├── mindboggle.thirdparty.rst │ ├── modules.rst │ └── setup.rst ├── api_build.sh ├── conf.py ├── faq.rst ├── faq │ ├── citing_mindboggle.rst │ ├── run_time.rst │ ├── singularity.rst │ ├── why_license.rst │ ├── why_mindboggle.rst │ └── why_python.rst ├── images │ └── mindboggle_logo_200px_600dpi.jpg ├── index.rst ├── labels.rst ├── license.rst ├── mindboggle_tutorial.ipynb └── requirements.txt ├── info.py ├── install ├── Dockerfile ├── Singularity └── neurodocker.sh ├── mindboggle ├── __init__.py ├── data │ ├── OASIS-30_Atropos_template_to_MNI152_affine.txt │ ├── OASIS-TRT-20_jointfusion_DKT31_CMA_labels_in_MNI152_v2.nii.gz │ ├── __init__.py │ └── data.py ├── evaluate │ ├── __init__.py │ ├── evaluate_features.py │ ├── evaluate_labels.py │ └── evaluate_shapes.py ├── features │ ├── __init__.py │ ├── folds.py │ ├── fundi.py │ └── sulci.py ├── guts │ ├── __init__.py │ ├── compute.py │ ├── graph.py │ ├── kernels.py │ ├── mesh.py │ ├── paths.py │ ├── rebound.py │ ├── relabel.py │ ├── segment.py │ └── utilities.py ├── mindboggle ├── mindboggle123 ├── mio │ ├── __init__.py │ ├── colors.py │ ├── convert_volumes.py │ ├── copy_final_tables │ ├── fetch_data.py │ ├── labels.py │ ├── plots.py │ ├── tables.py │ └── vtks.py ├── shapes │ ├── __init__.py │ ├── laplace_beltrami.py │ ├── likelihood.py │ ├── surface_shapes.py │ ├── volume_shapes.py │ └── zernike │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── helpers.py │ │ ├── pipelines.py │ │ └── zernike.py ├── thirdparty │ ├── FreeSurferColorLUT.py │ ├── __init__.py │ ├── ants.py │ └── vtkviewer.py ├── version.py └── x │ ├── boundary_realignment.py │ ├── developer_notes │ ├── propagate_fundus_lines.py │ ├── reprozip_container.sh │ └── test_zernike │ ├── __init__.py │ ├── compat │ ├── D_CV_orig_m.py │ ├── D_SG_orig_m.py │ ├── D_SG_orig_part_m.py │ ├── Dabc_orig_m.py │ ├── Qklnu_m.py │ ├── Yljm_m.py │ ├── __init__.py │ ├── factorial_precalc_m.py │ ├── feature_extraction_m.py │ ├── geometric_moments_orig_m.py │ ├── mon_comb_m.py │ ├── reformat_zernike_m.py │ ├── test.py │ ├── trinomial_m.py │ ├── trinomial_matrix_m.py │ ├── zernike_m.py │ └── zk_demo_m.py │ └── multiproc │ ├── D_CV_orig_m.py │ ├── D_SG_orig_m.py │ ├── D_SG_orig_part_m.py │ ├── Dabc_orig_m.py │ ├── Qklnu_m.py │ ├── Yljm_m.py │ ├── __init__.py │ ├── factorial_precalc_m.py │ ├── feature_extraction_m.py │ ├── geometric_moments_orig_m.py │ ├── mon_comb_m.py │ ├── reformat_zernike_m.py │ ├── test.py │ ├── trinomial_m.py │ ├── trinomial_matrix_m.py │ ├── zernike_m.py │ └── zk_demo_m.py ├── setup.py ├── terms └── terms.ttl └── vtk_cpp_tools ├── CMakeLists.txt ├── FsSurfaceReader.cpp ├── FsSurfaceReader.h ├── GradientComputer.cpp ├── GradientComputer.h ├── LICENSE ├── MeshAnalyser.cpp ├── MeshAnalyser.h ├── Overlap.cpp ├── Overlap.h ├── PointAreaComputer.cpp ├── PointAreaComputer.h ├── TravelDepth.cpp ├── TravelDepth.h ├── VtkFileEditor.cpp ├── VtkFileEditor.h ├── area ├── CMakeLists.txt └── PointAreaMain.cpp ├── colormap.xml ├── curvature ├── CMakeLists.txt └── CurvatureMain.cpp ├── geodesic_depth ├── CMakeLists.txt └── GeodesicDepthMain.cpp ├── gradient ├── CMakeLists.txt └── GradientMain.cpp ├── medial_surfaces ├── CMakeLists.txt ├── CMakeLists.txt.user ├── MedialSurfaceComputer.cpp ├── MedialSurfaceComputer.h └── MedialSurfaceMain.cpp ├── surface_overlap ├── CMakeLists.txt └── SurfaceOverlapMain.cpp └── travel_depth ├── CMakeLists.txt └── TravelDepthMain.cpp /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: continuumio/miniconda3:4.5.4 6 | environment: 7 | ENV_NAME: mindboggle-env 8 | vtk_cpp_tools: /src/mindboggle/vtk_cpp_tools/bin 9 | working_directory: /src/mindboggle 10 | steps: 11 | - checkout 12 | - run: 13 | name: Install mindboggle 14 | command: | 15 | set -eu 16 | apt-get update -qq && apt-get install -yq \ 17 | build-essential \ 18 | libgl1-mesa-dev \ 19 | libglu1-mesa-dev \ 20 | libsm-dev \ 21 | libx11-dev \ 22 | libxt-dev \ 23 | libxext-dev 24 | ln -sv /usr/lib/x86_64-linux-gnu /usr/lib64 25 | conda config --set show_channel_urls yes --set always_yes yes 26 | conda config --add channels conda-forge 27 | conda create -n $ENV_NAME python=3.6 pip 28 | source activate $ENV_NAME 29 | conda install -y cmake mesalib vtk pandas matplotlib \ 30 | colormath nipype tbb-devel nose etelemetry 31 | conda info --envs 32 | python setup.py install 33 | mkdir $vtk_cpp_tools && cd $vtk_cpp_tools && cmake ../ && make 34 | - run: 35 | name: Test mindboggle 36 | command: | 37 | source activate $ENV_NAME 38 | export MB=/opt/conda/envs/${ENV_NAME}/lib/python3.6/site-packages/mindboggle 39 | export PATH=$PATH:$vtk_cpp_tools 40 | python -m "nose" --with-doctest ${MB}/thirdparty/ 41 | python -m "nose" --with-doctest ${MB}/mio/ 42 | python -m "nose" --with-doctest ${MB}/guts/ 43 | python -m "nose" --with-doctest ${MB}/shapes/ 44 | python -m "nose" --with-doctest ${MB}/features/ 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /docs/_build 2 | doctrees 3 | mindboggle.egg-info 4 | vtk_cpp_tools/bin 5 | 6 | build 7 | CMakeCache.txt 8 | CMakeFiles 9 | crash-* 10 | 11 | ._* 12 | .#* 13 | .del-* 14 | .DS_Store* 15 | .idea 16 | .project 17 | .pydevproject 18 | .settings 19 | 20 | #* 21 | ,* 22 | _$* 23 | 24 | *~ 25 | *$ 26 | 27 | *.a 28 | *.bak 29 | *.BAK 30 | *.cache* 31 | *.elc 32 | *.exe 33 | *.gz 34 | *.ln 35 | *.o 36 | *.olb 37 | *.old 38 | *.obj 39 | *.orig 40 | *.pyc 41 | *.rej 42 | *.so 43 | *.tar 44 | *.tar.gz 45 | *.Z 46 | *.zip 47 | 48 | MANIFEST -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | 3 | This document is an excerpt from Mindboggle's Docker Hub Updates: 4 | https://cloud.docker.com/u/nipy/repository/docker/nipy/mindboggle/general 5 | 6 | November 4, 2019 (v1.3.8): 7 | - Fix issue #190 in v1.3.7, an error caused by a unicode character within docstrings 8 | - Introduce Singularity recipe in neurodocker.sh 9 | 10 | September 24, 2019 (v1.3.7): 11 | Satrajit Ghosh added etelemetry capabilities. 12 | 13 | June 11, 2019 (v1.3.4): 14 | Conda installed a version of vtk that broke the C++ code 15 | (https://github.com/nipy/mindboggle/issues/171). 16 | - updated neurodocker.sh to install VTK 8.2 17 | Nipype is breaking with when it tries to generate reports 18 | - added "encoding='utf-8'" in nipype files in the docker image to resolve issue #175 19 | Zernike moments stopped working because scipy.misc was deprecated. 20 | - replaced with scipy.special 21 | Non-default (Gaussian, min, max) curvature file names were incomplete. 22 | - fixed the names so that they have the same filestem as the mean curvature file 23 | Image links broken in docs and in the Jupyter notebook tutorial. 24 | - moved images to a new GitHub repository "nipy/mindboggle-assets" 25 | 26 | September 14, 2018: 27 | neurodocker.sh updated to remove __macosx files to allow for Singularity builds. 28 | 29 | August 26, 2018: 30 | neurodocker.sh replaces the earlier Dockerfile-creating scripts. 31 | 32 | March 8, 2018: 33 | mindboggle123 script revised to run antsCorticalThickness.sh with "-u 0" flag, 34 | which turns off a default setting in ANTs that introduces a stochastic element 35 | in the Atropos segmentation algorithm. -------------------------------------------------------------------------------- /LICENSE.rst: -------------------------------------------------------------------------------- 1 | License 2 | ------- 3 | 4 | Software License 5 | ................ 6 | Except where otherwise noted, all Mindboggle software is licensed under the 7 | `Apache v2.0 `_ license. 8 | 9 | The usual disclaimer: 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR 15 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 16 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 17 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 18 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 19 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 20 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | 22 | Documentation License 23 | ..................... 24 | Except where otherwise noted, all Mindboggle documentation is licensed under a 25 | `Creative Commons Attribution 3.0 License `_. 26 | 27 | All code fragments in the documentation are licensed under our software license. 28 | -------------------------------------------------------------------------------- /THANKS.rst: -------------------------------------------------------------------------------- 1 | ============================================================================== 2 | Thanks 3 | ============================================================================== 4 | 5 | Mindboggle is an open source project for brain image analysis using Python. 6 | 7 | It is a community project with a growing number of contributors. 8 | 9 | Please see `people `_ for an updated list. 10 | -------------------------------------------------------------------------------- /colormap/group_colors/label_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/group_colors/label_graph.png -------------------------------------------------------------------------------- /colormap/group_colors/label_subgraph1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/group_colors/label_subgraph1.png -------------------------------------------------------------------------------- /colormap/group_colors/label_subgraph2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/group_colors/label_subgraph2.png -------------------------------------------------------------------------------- /colormap/group_colors/label_subgraph3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/group_colors/label_subgraph3.png -------------------------------------------------------------------------------- /colormap/group_colors/label_subgraph4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/group_colors/label_subgraph4.png -------------------------------------------------------------------------------- /colormap/group_colors/label_subgraph5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/group_colors/label_subgraph5.png -------------------------------------------------------------------------------- /colormap/group_colors/label_subgraph6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/group_colors/label_subgraph6.png -------------------------------------------------------------------------------- /colormap/label_adjacency_matrix.csv: -------------------------------------------------------------------------------- 1 | ID,group,name,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,34,35 2 | 2,6,caudal anterior cingulate,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1,0,0,0,0,0 3 | 3,1,caudal middle frontal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,1,0,0,0,0,0 4 | 5,4,cuneus,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0 5 | 6,6,entorhinal,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 6 | 7,3,fusiform,0,0,0,0,0,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 7 | 8,5,inferior parietal,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 8 | 9,3,inferior temporal,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 9 | 10,6,isthmus cingulate,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0 10 | 11,4,lateral occipital,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0 11 | 12,1,lateral orbitofrontal,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,1,0,0,1 12 | 13,4,lingual,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0 13 | 14,1,medial orbitofrontal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0 14 | 15,3,middle temporal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 15 | 16,6,parahippocampal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 16 | 17,2,paracentral,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0,0,0,0 17 | 18,1,pars opercularis,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,1 18 | 19,1,pars orbitalis,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1 19 | 20,1,pars triangularis,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1 20 | 21,5,pericalcarine,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0 21 | 22,5,postcentral,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,1,0,1 22 | 23,6,posterior cingulate,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0 23 | 24,1,precentral,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1 24 | 25,5,precuneus,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 25 | 26,6,rostral anterior cingulate,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0 26 | 27,1,rostral middle frontal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0 27 | 28,1,superior frontal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 28 | 29,5,superior parietal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 29 | 30,3,superior temporal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1 30 | 31,5,supramarginal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 31 | 34,3,transverse temporal,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 32 | 35,1,insula,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 33 | -------------------------------------------------------------------------------- /colormap/label_colormap.csv: -------------------------------------------------------------------------------- 1 | 7.586206896551723755e-01,2.068965517241379282e-01,0.000000000000000000e+00 2 | 4.827586206896551380e-01,4.482758620689655249e-01,4.827586206896551380e-01 3 | 3.448275862068965747e-01,3.103448275862069061e-01,3.448275862068965469e-02 4 | 0.000000000000000000e+00,3.103448275862069061e-01,2.413793103448275690e-01 5 | 1.000000000000000000e+00,6.896551724137931494e-01,4.827586206896551380e-01 6 | 3.448275862068965469e-02,2.413793103448275690e-01,5.862068965517240882e-01 7 | 6.206896551724138122e-01,6.551724137931034253e-01,1.000000000000000000e+00 8 | 5.172413793103448620e-01,8.275862068965517127e-01,1.000000000000000000e+00 9 | 3.448275862068965747e-01,3.793103448275861878e-01,3.448275862068965747e-01 10 | 6.206896551724138122e-01,6.896551724137930939e-02,1.000000000000000000e+00 11 | 6.206896551724138122e-01,4.827586206896551380e-01,3.448275862068965747e-01 12 | 0.000000000000000000e+00,3.103448275862069061e-01,2.413793103448275690e-01 13 | 6.206896551724138122e-01,6.551724137931034253e-01,1.000000000000000000e+00 14 | 4.827586206896551380e-01,4.482758620689655249e-01,4.827586206896551380e-01 15 | 7.241379310344827624e-01,1.000000000000000000e+00,1.034482758620689641e-01 16 | 0.000000000000000000e+00,8.620689655172413257e-01,7.931034482758620996e-01 17 | 5.172413793103448620e-01,8.275862068965517127e-01,1.000000000000000000e+00 18 | 4.482758620689655249e-01,3.448275862068965469e-02,2.413793103448275690e-01 19 | 1.034482758620689641e-01,8.965517241379310498e-01,3.793103448275861878e-01 20 | 1.000000000000000000e+00,9.310344827586206629e-01,5.862068965517240882e-01 21 | 5.172413793103448620e-01,5.862068965517240882e-01,5.172413793103448620e-01 22 | 1.034482758620689641e-01,8.965517241379310498e-01,3.793103448275861878e-01 23 | 0.000000000000000000e+00,5.517241379310344751e-01,5.172413793103448620e-01 24 | 9.310344827586206629e-01,7.931034482758620996e-01,1.000000000000000000e+00 25 | 7.586206896551723755e-01,0.000000000000000000e+00,5.172413793103448620e-01 26 | 3.448275862068965747e-01,3.793103448275861878e-01,3.448275862068965747e-01 27 | 0.000000000000000000e+00,5.517241379310344751e-01,5.172413793103448620e-01 28 | 5.172413793103448620e-01,6.551724137931034253e-01,0.000000000000000000e+00 29 | 2.758620689655172376e-01,4.137931034482758563e-01,1.000000000000000000e+00 30 | 3.793103448275861878e-01,2.758620689655172376e-01,4.827586206896551380e-01 31 | 7.931034482758620996e-01,9.655172413793102759e-01,7.931034482758620996e-01 32 | -------------------------------------------------------------------------------- /colormap/label_colormap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DKT31colormap", 3 | "description": "Colormap for DKT31 human brain cortical labels", 4 | "colormap": [ 5 | {"ID": "2", "name": "caudal anterior cingulate", "red": "0.7586206896551724", "green": "0.20689655172413793", "blue": "0.0"}, 6 | {"ID": "3", "name": "caudal middle frontal", "red": "0.48275862068965514", "green": "0.4482758620689655", "blue": "0.48275862068965514"}, 7 | {"ID": "5", "name": "cuneus", "red": "0.3448275862068966", "green": "0.3103448275862069", "blue": "0.034482758620689655"}, 8 | {"ID": "6", "name": "entorhinal", "red": "0.0", "green": "0.3103448275862069", "blue": "0.24137931034482757"}, 9 | {"ID": "7", "name": "fusiform", "red": "1.0", "green": "0.6896551724137931", "blue": "0.48275862068965514"}, 10 | {"ID": "8", "name": "inferior parietal", "red": "0.034482758620689655", "green": "0.24137931034482757", "blue": "0.5862068965517241"}, 11 | {"ID": "9", "name": "inferior temporal", "red": "0.6206896551724138", "green": "0.6551724137931034", "blue": "1.0"}, 12 | {"ID": "10", "name": "isthmus cingulate", "red": "0.5172413793103449", "green": "0.8275862068965517", "blue": "1.0"}, 13 | {"ID": "11", "name": "lateral occipital", "red": "0.3448275862068966", "green": "0.3793103448275862", "blue": "0.3448275862068966"}, 14 | {"ID": "12", "name": "lateral orbitofrontal", "red": "0.6206896551724138", "green": "0.06896551724137931", "blue": "1.0"}, 15 | {"ID": "13", "name": "lingual", "red": "0.6206896551724138", "green": "0.48275862068965514", "blue": "0.3448275862068966"}, 16 | {"ID": "14", "name": "medial orbitofrontal", "red": "0.0", "green": "0.3103448275862069", "blue": "0.24137931034482757"}, 17 | {"ID": "15", "name": "middle temporal", "red": "0.6206896551724138", "green": "0.6551724137931034", "blue": "1.0"}, 18 | {"ID": "16", "name": "parahippocampal", "red": "0.48275862068965514", "green": "0.4482758620689655", "blue": "0.48275862068965514"}, 19 | {"ID": "17", "name": "paracentral", "red": "0.7241379310344828", "green": "1.0", "blue": "0.10344827586206896"}, 20 | {"ID": "18", "name": "pars opercularis", "red": "0.0", "green": "0.8620689655172413", "blue": "0.7931034482758621"}, 21 | {"ID": "19", "name": "pars orbitalis", "red": "0.5172413793103449", "green": "0.8275862068965517", "blue": "1.0"}, 22 | {"ID": "20", "name": "pars triangularis", "red": "0.4482758620689655", "green": "0.034482758620689655", "blue": "0.24137931034482757"}, 23 | {"ID": "21", "name": "pericalcarine", "red": "0.10344827586206896", "green": "0.896551724137931", "blue": "0.3793103448275862"}, 24 | {"ID": "22", "name": "postcentral", "red": "1.0", "green": "0.9310344827586207", "blue": "0.5862068965517241"}, 25 | {"ID": "23", "name": "posterior cingulate", "red": "0.5172413793103449", "green": "0.5862068965517241", "blue": "0.5172413793103449"}, 26 | {"ID": "24", "name": "precentral", "red": "0.10344827586206896", "green": "0.896551724137931", "blue": "0.3793103448275862"}, 27 | {"ID": "25", "name": "precuneus", "red": "0.0", "green": "0.5517241379310345", "blue": "0.5172413793103449"}, 28 | {"ID": "26", "name": "rostral anterior cingulate", "red": "0.9310344827586207", "green": "0.7931034482758621", "blue": "1.0"}, 29 | {"ID": "27", "name": "rostral middle frontal", "red": "0.7586206896551724", "green": "0.0", "blue": "0.5172413793103449"}, 30 | {"ID": "28", "name": "superior frontal", "red": "0.3448275862068966", "green": "0.3793103448275862", "blue": "0.3448275862068966"}, 31 | {"ID": "29", "name": "superior parietal", "red": "0.0", "green": "0.5517241379310345", "blue": "0.5172413793103449"}, 32 | {"ID": "30", "name": "superior temporal", "red": "0.5172413793103449", "green": "0.6551724137931034", "blue": "0.0"}, 33 | {"ID": "31", "name": "supramarginal", "red": "0.27586206896551724", "green": "0.41379310344827586", "blue": "1.0"}, 34 | {"ID": "34", "name": "transverse temporal", "red": "0.3793103448275862", "green": "0.27586206896551724", "blue": "0.48275862068965514"}, 35 | {"ID": "35", "name": "insula", "red": "0.7931034482758621", "green": "0.9655172413793103", "blue": "0.7931034482758621"} 36 | ]} -------------------------------------------------------------------------------- /colormap/label_colormap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/label_colormap.png -------------------------------------------------------------------------------- /colormap/label_colormap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /colormap/no_groups/label_colormap.csv: -------------------------------------------------------------------------------- 1 | 5.172413793103448620e-01,8.275862068965517127e-01,1.000000000000000000e+00 2 | 1.379310344827586188e-01,0.000000000000000000e+00,2.413793103448275690e-01 3 | 3.793103448275861878e-01,2.758620689655172376e-01,4.827586206896551380e-01 4 | 4.827586206896551380e-01,4.482758620689655249e-01,4.827586206896551380e-01 5 | 0.000000000000000000e+00,5.862068965517240882e-01,0.000000000000000000e+00 6 | 7.586206896551723755e-01,2.068965517241379282e-01,0.000000000000000000e+00 7 | 2.758620689655172376e-01,1.379310344827586188e-01,0.000000000000000000e+00 8 | 0.000000000000000000e+00,8.620689655172413257e-01,7.931034482758620996e-01 9 | 5.172413793103448620e-01,6.551724137931034253e-01,0.000000000000000000e+00 10 | 3.448275862068965469e-02,2.413793103448275690e-01,5.862068965517240882e-01 11 | 1.034482758620689641e-01,8.965517241379310498e-01,3.793103448275861878e-01 12 | 7.931034482758620996e-01,9.655172413793102759e-01,7.931034482758620996e-01 13 | 2.758620689655172376e-01,4.137931034482758563e-01,1.000000000000000000e+00 14 | 4.482758620689655249e-01,3.448275862068965469e-02,2.413793103448275690e-01 15 | 6.896551724137931494e-01,5.862068965517240882e-01,0.000000000000000000e+00 16 | 1.000000000000000000e+00,6.896551724137931494e-01,4.827586206896551380e-01 17 | 1.379310344827586188e-01,1.724137931034482873e-01,0.000000000000000000e+00 18 | 3.448275862068965469e-02,5.172413793103448620e-01,7.241379310344827624e-01 19 | 5.172413793103448620e-01,5.862068965517240882e-01,5.172413793103448620e-01 20 | 3.448275862068965747e-01,3.793103448275861878e-01,3.448275862068965747e-01 21 | 0.000000000000000000e+00,5.517241379310344751e-01,5.172413793103448620e-01 22 | 9.655172413793102759e-01,4.827586206896551380e-01,6.551724137931034253e-01 23 | 7.586206896551723755e-01,0.000000000000000000e+00,5.172413793103448620e-01 24 | 9.310344827586206629e-01,7.931034482758620996e-01,1.000000000000000000e+00 25 | 0.000000000000000000e+00,3.103448275862069061e-01,2.413793103448275690e-01 26 | 6.206896551724138122e-01,6.896551724137930939e-02,1.000000000000000000e+00 27 | 7.241379310344827624e-01,1.000000000000000000e+00,1.034482758620689641e-01 28 | 3.448275862068965747e-01,3.103448275862069061e-01,3.448275862068965469e-02 29 | 1.000000000000000000e+00,9.310344827586206629e-01,5.862068965517240882e-01 30 | 6.206896551724138122e-01,6.551724137931034253e-01,1.000000000000000000e+00 31 | 6.206896551724138122e-01,4.827586206896551380e-01,3.448275862068965747e-01 32 | -------------------------------------------------------------------------------- /colormap/no_groups/label_colormap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/no_groups/label_colormap.png -------------------------------------------------------------------------------- /colormap/no_groups/label_colormap_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/no_groups/label_colormap_original.png -------------------------------------------------------------------------------- /colormap/no_groups/label_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/no_groups/label_graph.png -------------------------------------------------------------------------------- /colormap/no_groups/label_subgraph1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/colormap/no_groups/label_subgraph1.png -------------------------------------------------------------------------------- /colors_script/calc_colormap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | 5 | import os 6 | import argparse 7 | import numpy as np 8 | 9 | from mindboggle.mio.colors import distinguishable_colors, label_adjacency_matrix 10 | 11 | 12 | if __name__ == "__main__": 13 | 14 | description = ('calculate colormap for labeled image;' 15 | 'calculated result is stored in output_dirname/colors.npy') 16 | parser = argparse.ArgumentParser(description=description) 17 | parser.add_argument('label_filename', help='path to the label image') 18 | parser.add_argument('output_dirname', help='path to the folder storing ' 19 | 'temporary files and result') 20 | parser.add_argument('-v', '--verbose', action='store_true', default=False) 21 | args = parser.parse_args() 22 | 23 | if not os.path.isdir(args.output_dirname): 24 | os.makedirs(args.output_dirname) 25 | 26 | matrix_filename = os.path.join(args.output_dirname, 'matrix.npy') 27 | colormap_filename = os.path.join(args.output_dirname, 'colormap.npy') 28 | labels_filename = os.path.join(args.output_dirname, 'labels.npy') 29 | colors_filename = os.path.join(args.output_dirname, 'colors.npy') 30 | 31 | if args.verbose: 32 | print('finding adjacency maps...') 33 | 34 | if not os.path.isfile(matrix_filename) or \ 35 | not os.path.isfile(labels_filename): 36 | labels, matrix = label_adjacency_matrix(args.label_filename, 37 | out_dir=args.output_dirname)[:2] 38 | matrix = matrix.as_matrix()[:, 1:] 39 | np.save(matrix_filename, matrix) 40 | np.save(labels_filename, labels) 41 | else: 42 | labels = np.load(labels_filename) 43 | matrix = np.load(matrix_filename) 44 | 45 | if args.verbose: 46 | print('finding colormap...') 47 | 48 | if not os.path.isfile(colormap_filename): 49 | num_colors = len(labels) 50 | colormap = distinguishable_colors(ncolors=num_colors, 51 | plot_colormap=False, 52 | save_csv=False, 53 | out_dir=args.output_dirname) 54 | np.save(colormap_filename, colormap) 55 | else: 56 | colormap = np.load(colormap_filename) 57 | 58 | if args.verbose: 59 | print('finding label colors') 60 | 61 | if not os.path.isfile(colors_filename): 62 | label_colors = colors.group_colors(colormap, 63 | args.label_filename, 64 | IDs=labels, 65 | adjacency_matrix=matrix, 66 | out_dir=args.output_dirname, 67 | plot_colors=False, 68 | plot_graphs=False) 69 | np.save(colors_filename, label_colors) 70 | -------------------------------------------------------------------------------- /colors_script/convert_to_mipav_lut.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import numpy as np 5 | import argparse 6 | 7 | def parse_inputs(): 8 | des = 'convert colormap to mipav lut file.' 9 | parser = argparse.ArgumentParser(description=des) 10 | parser.add_argument('colormap_filename') 11 | parser.add_argument('ids_filename') 12 | parser.add_argument('output_filename') 13 | args = parser.parse_args() 14 | return args 15 | 16 | def main(args): 17 | 18 | labels = np.load(args.ids_filename) 19 | colors = np.load(args.colormap_filename) * 255 20 | 21 | contents = list() 22 | contents.append('') 23 | contents.append('256\t# Size of LUT Arrays') 24 | 25 | for i in range(256): 26 | if i in labels: 27 | idx = np.where(labels == i)[0][0] 28 | c = colors[idx].tolist() 29 | else: 30 | c = [0.0, 0.0, 0.0] 31 | c_str = [str(cc) for cc in c] 32 | line = '\t'.join([str(i), '1.0', *c_str]) 33 | contents.append(line) 34 | 35 | with open(args.output_filename, 'w') as file: 36 | file.write('\n'.join(contents)) 37 | 38 | 39 | if __name__ == "__main__": 40 | args = parse_inputs() 41 | main(args) 42 | -------------------------------------------------------------------------------- /docs/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | {% set title = 'Mindboggle' %} 3 | 4 | {% block rootrellink %} 5 | {% endblock %} 6 | 7 | {% block relbar1 %}{% endblock %} 8 | {% block relbar2 %}{% endblock %} 9 | 10 | {% block extrahead %} 11 | Mindboggle 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | {% endblock %} 27 | 28 | {% block header %} 29 |
30 | 31 | 32 | 38 | 66 | 67 |
33 | 34 | 35 | small mindboggle logo 36 | 37 | 39 | 40 | 41 | Mindboggle 43 | 44 | 45 | 46 | 47 | 51 | 55 | 59 | 63 | 64 |
48 | Software 50 | 52 | Data 54 | 56 | Papers 58 | 60 | People 62 |
65 |
68 |
69 | {% endblock %} 70 | 71 | 72 | 73 | {# This block gets put at the top of the sidebar #} 74 | {% block sidebarlogo %} 75 | 76 | 77 | 87 | 88 | {%- endblock %} 89 | 90 | {# I had to copy the whole search block just to change the rendered text, 91 | so it doesn't mention modules or classes #} 92 | {%- block sidebarsearch %} 93 | {%- if pagename != "search" %} 94 | 95 | 106 | 107 | {%- endif %} 108 | 109 | {# The sidebarsearch block is the last one available in the default sidebar() 110 | macro, so the only way to add something to the bottom of the sidebar is to 111 | put it here, at the end of the sidebarsearch block (before it closes). 112 | #} 113 | 114 | {% endblock %} 115 | 116 | 117 | {% block footer %} 118 | 119 | 123 | 129 | {% endblock %} 130 | -------------------------------------------------------------------------------- /docs/api/info.rst: -------------------------------------------------------------------------------- 1 | info module 2 | =========== 3 | 4 | .. automodule:: info 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/api/mindboggle.evaluate.rst: -------------------------------------------------------------------------------- 1 | mindboggle.evaluate package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | mindboggle.evaluate.evaluate_features module 8 | -------------------------------------------- 9 | 10 | .. automodule:: mindboggle.evaluate.evaluate_features 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | mindboggle.evaluate.evaluate_labels module 16 | ------------------------------------------ 17 | 18 | .. automodule:: mindboggle.evaluate.evaluate_labels 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | 24 | Module contents 25 | --------------- 26 | 27 | .. automodule:: mindboggle.evaluate 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | -------------------------------------------------------------------------------- /docs/api/mindboggle.features.rst: -------------------------------------------------------------------------------- 1 | mindboggle.features package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | mindboggle.features.folds module 8 | -------------------------------- 9 | 10 | .. automodule:: mindboggle.features.folds 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | mindboggle.features.fundi module 16 | -------------------------------- 17 | 18 | .. automodule:: mindboggle.features.fundi 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | mindboggle.features.sulci module 24 | -------------------------------- 25 | 26 | .. automodule:: mindboggle.features.sulci 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | 32 | Module contents 33 | --------------- 34 | 35 | .. automodule:: mindboggle.features 36 | :members: 37 | :undoc-members: 38 | :show-inheritance: 39 | -------------------------------------------------------------------------------- /docs/api/mindboggle.guts.rst: -------------------------------------------------------------------------------- 1 | mindboggle.guts package 2 | ======================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | mindboggle.guts.compute module 8 | ------------------------------ 9 | 10 | .. automodule:: mindboggle.guts.compute 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | mindboggle.guts.graph module 16 | ---------------------------- 17 | 18 | .. automodule:: mindboggle.guts.graph 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | mindboggle.guts.kernels module 24 | ------------------------------ 25 | 26 | .. automodule:: mindboggle.guts.kernels 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | mindboggle.guts.mesh module 32 | --------------------------- 33 | 34 | .. automodule:: mindboggle.guts.mesh 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | mindboggle.guts.morph module 40 | ---------------------------- 41 | 42 | .. automodule:: mindboggle.guts.morph 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | mindboggle.guts.paths module 48 | ---------------------------- 49 | 50 | .. automodule:: mindboggle.guts.paths 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | mindboggle.guts.rebound module 56 | ------------------------------ 57 | 58 | .. automodule:: mindboggle.guts.rebound 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | mindboggle.guts.relabel module 64 | ------------------------------ 65 | 66 | .. automodule:: mindboggle.guts.relabel 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | 71 | mindboggle.guts.segment module 72 | ------------------------------ 73 | 74 | .. automodule:: mindboggle.guts.segment 75 | :members: 76 | :undoc-members: 77 | :show-inheritance: 78 | 79 | mindboggle.guts.utilities module 80 | -------------------------------- 81 | 82 | .. automodule:: mindboggle.guts.utilities 83 | :members: 84 | :undoc-members: 85 | :show-inheritance: 86 | 87 | 88 | Module contents 89 | --------------- 90 | 91 | .. automodule:: mindboggle.guts 92 | :members: 93 | :undoc-members: 94 | :show-inheritance: 95 | -------------------------------------------------------------------------------- /docs/api/mindboggle.mio.rst: -------------------------------------------------------------------------------- 1 | mindboggle.mio package 2 | ====================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | mindboggle.mio.convert_volumes module 8 | ------------------------------------- 9 | 10 | .. automodule:: mindboggle.mio.convert_volumes 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | mindboggle.mio.fetch_data module 16 | -------------------------------- 17 | 18 | .. automodule:: mindboggle.mio.fetch_data 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | mindboggle.mio.labels module 24 | ---------------------------- 25 | 26 | .. automodule:: mindboggle.mio.labels 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | mindboggle.mio.plots module 32 | --------------------------- 33 | 34 | .. automodule:: mindboggle.mio.plots 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | mindboggle.mio.tables module 40 | ---------------------------- 41 | 42 | .. automodule:: mindboggle.mio.tables 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | mindboggle.mio.vtks module 48 | -------------------------- 49 | 50 | .. automodule:: mindboggle.mio.vtks 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | 56 | Module contents 57 | --------------- 58 | 59 | .. automodule:: mindboggle.mio 60 | :members: 61 | :undoc-members: 62 | :show-inheritance: 63 | -------------------------------------------------------------------------------- /docs/api/mindboggle.rst: -------------------------------------------------------------------------------- 1 | mindboggle package 2 | ================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | 9 | mindboggle.evaluate 10 | mindboggle.features 11 | mindboggle.guts 12 | mindboggle.mio 13 | mindboggle.shapes 14 | mindboggle.thirdparty 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: mindboggle 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /docs/api/mindboggle.shapes.rst: -------------------------------------------------------------------------------- 1 | mindboggle.shapes package 2 | ========================= 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | 9 | mindboggle.shapes.zernike 10 | 11 | Submodules 12 | ---------- 13 | 14 | mindboggle.shapes.laplace_beltrami module 15 | ----------------------------------------- 16 | 17 | .. automodule:: mindboggle.shapes.laplace_beltrami 18 | :members: 19 | :undoc-members: 20 | :show-inheritance: 21 | 22 | mindboggle.shapes.likelihood module 23 | ----------------------------------- 24 | 25 | .. automodule:: mindboggle.shapes.likelihood 26 | :members: 27 | :undoc-members: 28 | :show-inheritance: 29 | 30 | mindboggle.shapes.surface_shapes module 31 | --------------------------------------- 32 | 33 | .. automodule:: mindboggle.shapes.surface_shapes 34 | :members: 35 | :undoc-members: 36 | :show-inheritance: 37 | 38 | mindboggle.shapes.volume_shapes module 39 | -------------------------------------- 40 | 41 | .. automodule:: mindboggle.shapes.volume_shapes 42 | :members: 43 | :undoc-members: 44 | :show-inheritance: 45 | 46 | 47 | Module contents 48 | --------------- 49 | 50 | .. automodule:: mindboggle.shapes 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | -------------------------------------------------------------------------------- /docs/api/mindboggle.shapes.zernike.rst: -------------------------------------------------------------------------------- 1 | mindboggle.shapes.zernike package 2 | ================================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | mindboggle.shapes.zernike.helpers module 8 | ---------------------------------------- 9 | 10 | .. automodule:: mindboggle.shapes.zernike.helpers 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | mindboggle.shapes.zernike.pipelines module 16 | ------------------------------------------ 17 | 18 | .. automodule:: mindboggle.shapes.zernike.pipelines 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | mindboggle.shapes.zernike.zernike module 24 | ---------------------------------------- 25 | 26 | .. automodule:: mindboggle.shapes.zernike.zernike 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | 32 | Module contents 33 | --------------- 34 | 35 | .. automodule:: mindboggle.shapes.zernike 36 | :members: 37 | :undoc-members: 38 | :show-inheritance: 39 | -------------------------------------------------------------------------------- /docs/api/mindboggle.thirdparty.rst: -------------------------------------------------------------------------------- 1 | mindboggle.thirdparty package 2 | ============================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | mindboggle.thirdparty.FreeSurferColorLUT module 8 | ----------------------------------------------- 9 | 10 | .. automodule:: mindboggle.thirdparty.FreeSurferColorLUT 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | mindboggle.thirdparty.ants module 16 | --------------------------------- 17 | 18 | .. automodule:: mindboggle.thirdparty.ants 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | mindboggle.thirdparty.vtkviewer module 24 | -------------------------------------- 25 | 26 | .. automodule:: mindboggle.thirdparty.vtkviewer 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | 32 | Module contents 33 | --------------- 34 | 35 | .. automodule:: mindboggle.thirdparty 36 | :members: 37 | :undoc-members: 38 | :show-inheritance: 39 | -------------------------------------------------------------------------------- /docs/api/modules.rst: -------------------------------------------------------------------------------- 1 | mindboggle 2 | ========== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | info 8 | mindboggle 9 | setup 10 | -------------------------------------------------------------------------------- /docs/api/setup.rst: -------------------------------------------------------------------------------- 1 | setup module 2 | ============ 3 | 4 | .. automodule:: setup 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/api_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | sphinx-apidoc -f -o api .. 4 | -------------------------------------------------------------------------------- /docs/faq.rst: -------------------------------------------------------------------------------- 1 | ============================================================================== 2 | Frequently asked questions about Mindboggle 3 | ============================================================================== 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | 8 | faq/why_mindboggle 9 | faq/why_license 10 | faq/why_python 11 | faq/citing_mindboggle 12 | faq/run_time 13 | labels 14 | faq/singularity 15 | -------------------------------------------------------------------------------- /docs/faq/citing_mindboggle.rst: -------------------------------------------------------------------------------- 1 | .. _citing_mindboggle: 2 | 3 | ------------------------------------------------------------------------------ 4 | How do we cite Mindboggle? 5 | ------------------------------------------------------------------------------ 6 | 7 | For Mindboggle-related articles, visit `mindboggle.info/papers.html `_. 8 | When using Mindboggle please cite the primary reference: 9 | 10 | A Klein, SS Ghosh, FS Bao, J Giard, Y Hame, E Stavsky, N Lee, B Rossa, M Reuter, EC Neto, A Keshavan. 2017. 11 | **Mindboggling morphometry of human brains**. 12 | *PLoS Computational Biology* 13(3): e1005350. `doi:10.1371/journal.pcbi.1005350 `_ 13 | 14 | Contributors are listed on Mindboggle's `team page `_. 15 | 16 | -------------------------------------------------------------------------------- /docs/faq/run_time.rst: -------------------------------------------------------------------------------- 1 | .. _run_time: 2 | 3 | ------------------------------------------------------------------------------ 4 | How long does it take to run Mindboggle? 5 | ------------------------------------------------------------------------------ 6 | 7 | We have tested the software most extensively with Python 3.5.1 on Ubuntu Linux 14.04. 8 | Running Mindboggle on the Docker installation on a Macbook Pro (2.6 GHz Intel Core i7 9 | with 16 GB memory; macOS 10.12) took about 100 minutes, of which 20 minutes were spent 10 | optionally computing Laplace-Beltrami spectra and Zernike moments. 11 | 12 | When only the surface shapes of gyrus labels were computed, 13 | without Laplace-Beltrami spectra or Zernike moments, 14 | Mindboggle took less than 7 minutes using the following command:: 15 | 16 | mindboggle $FREESURFER_SUBJECT --out $MINDBOGGLED \ 17 | --no_volumes --no_sulci --no_moments --no_spectra 18 | -------------------------------------------------------------------------------- /docs/faq/singularity.rst: -------------------------------------------------------------------------------- 1 | .. _singularity: 2 | 3 | ------------------------------------------------------------------------------ 4 | How do I create and use a Singularity image rather than Docker? 5 | ------------------------------------------------------------------------------ 6 | 7 | To convert the Mindboggle Docker image to a Singularity image, run:: 8 | 9 | singularity pull mindboggle.img docker://nipy/mindboggle 10 | 11 | After the conversion, you'll need 3 mounts (data, working directory, and 12 | home directory) for it to work. Here is an example of the full command 13 | together with some of the optional arguments (thanks, Satra!), using the same 14 | environment variables as in the `README `_:: 15 | 16 | singularity run \ 17 | -B $HOST:$DOCK:ro \ 18 | -B $PWD:$DOCK \ 19 | -B $PWD/jovyan:/home/jovyan \ 20 | -e mindboggle.img \ 21 | $DOCK/example_mri_data/T1.nii.gz \ 22 | --id arno \ 23 | --fs_T2image $DOCK/example_mri_data/T2.nii.gz \ 24 | --plugin MultiProc --plugin_args "dict(n_procs=2)" \ 25 | --fs_openmp 5 --ants_num_threads 5 --mb_num_threads 10 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/faq/why_license.rst: -------------------------------------------------------------------------------- 1 | .. _why_license: 2 | 3 | ------------------------------------------------------------------------------ 4 | Why Apache? 5 | ------------------------------------------------------------------------------ 6 | 7 | We have chosen the Apache v2.0 license because it is liberal and 8 | supports broad use and modification of the software. 9 | The Apache license allows other projects with virtually any license, 10 | including GPL, to use our code, and makes it more likely that we will 11 | attract support from companies, including open-source software 12 | companies, such as `Continuum Analytics`_, Enthought_, and Kitware_. 13 | 14 | 15 | .. _`Continuum Analytics`: https://www.continuum.io/ 16 | .. _Enthought: http://www.enthought.com 17 | .. _Kitware: http://www.kitware.com 18 | -------------------------------------------------------------------------------- /docs/faq/why_mindboggle.rst: -------------------------------------------------------------------------------- 1 | .. _why_mindboggle: 2 | 3 | ------------------------------------------------------------------------------ 4 | Why Mindboggle? 5 | ------------------------------------------------------------------------------ 6 | 7 | Purpose 8 | ....... 9 | 10 | The purpose of Mindboggle is to improve the accuracy, precision, and 11 | consistency of labeling and morphometry of brain imaging data, 12 | and to promote open science by making all data, software, and documentation 13 | freely and openly available. 14 | 15 | Motivation 16 | .......... 17 | 18 | There is a strong tendency for neuroscientists who are not software developers 19 | to assume that questions of brain image "preprocessing", including registration 20 | and labeling, have been satisfactorily resolved or are not even worthy of mention 21 | [carp2012]_. We believe that conventional methods do not establish 22 | reasonable correspondences across brain images and threaten to undermine the 23 | credibility of the science and the scientists who use them in the service of 24 | answering the neuroscientific and clinical questions that interest them. 25 | 26 | .. [carp2012] 27 | Carp, J. (2012) *The secret lives of experiments: 28 | Methods reporting in the fMRI literature*. NeuroImage, 63(1), 289–300. 29 | doi:10.1016/j.neuroimage.2012.07.004 30 | 31 | History 32 | ....... 33 | 34 | Back in 1998, `Arno Klein `_ 35 | left Caltech to visit Cornell Medical School for a summer, 36 | to learn a bit about human brain imaging. Within a day of arriving in New York, 37 | he witnessed two medical students arguing over what regions of a patient's brain 38 | were active according to fMRI BOLD data printed on some sheets of paper. 39 | To do this, they compared locations of BOLD signal in the young man's 40 | brain with what appeared to them to be corresponding topographical locations 41 | in the 2-D slices of a dead, 60-year French woman's half cerebrum from 20 years prior, 42 | the venerable Talairach atlas. That clinched it. 43 | Arno stayed on to create the initial Mindboggle software package in Matlab 44 | as part of his doctoral dissertation. 45 | 46 | In 2007, Arno was invited to join the faculty at Columbia University 47 | to continue its development, whereupon he started writing proposals. 48 | 49 | In 2009, with generous funding from the National Institute of Mental Health 50 | (3-year NIMH R01 #MH084029), he assembled a team to tackle the problem anew. 51 | People who contributed to the codebase during this period include: 52 | 53 | - `Forrest Bao `_ 54 | - `Satrajit Ghosh `_ 55 | - Joachim Giard 56 | - Yrjö Häme 57 | - Eliezer Stavsky 58 | 59 | In 2012, the NIMH funded a 1-year U01 supplement to expand Mindboggle's 60 | capabilities, and to apply Mindboggle's structural shape analysis to multiple 61 | imaging modalities such as fMRI, dMRI, and genetic data. 62 | Tank Think Labs joined this U01 effort: 63 | 64 | - `Satrajit Ghosh `_ 65 | - Nolan Nichols 66 | - Brian Rossa 67 | - Oliver Hinds 68 | 69 | In 2013, Arno, Rich Stoner, and Jason Bohland teamed up at the Human Brain 70 | Mapping conference to win a hackathon challenge, having coded up an online 71 | interactive visualization of Allen Brain Institute human brain data 72 | in two days. Pointing to a cortical region displaying Mindboggle shape 73 | information revealed corresponding genetic expression data. 74 | 75 | In 2015, Mindboggle was used to process ADNI and AddNeuroMed data for 76 | an international `Alzheimer's disease challenge `_. 77 | Teams performed statistical analyses on Mindboggle shape measures to 78 | try and determine which brains had Alzheimer's, mild cognitive impairment, or 79 | were healthy, and to try and estimate a cognitive measure 80 | (mini-mental state exam score). 81 | 82 | In 2016, Arno prepared Mindboggle for broader public use: 83 | 84 | - moved its GitHub repository to the nipy.org community's GitHub account 85 | - ported Mindboggle from Python 2 to Python 3 86 | - moved its documentation to readthedocs.org (generated every time a commit is made to the GitHub repository) 87 | - wrote docstring tests for almost every function 88 | - set up continuous testing on circleci.com (tests are run every time a commit is made to the GitHub repository) 89 | 90 | Please see our updated Mindboggle `team page `_. 91 | 92 | -------------------------------------------------------------------------------- /docs/faq/why_python.rst: -------------------------------------------------------------------------------- 1 | .. _why_python: 2 | 3 | ------------------------------------------------------------------------------ 4 | Why Python? 5 | ------------------------------------------------------------------------------ 6 | 7 | From Nipy's documentation: 8 | 9 | The choice of programming language has many scientific and practical 10 | consequences. Matlab is an example of a high-level language. Languages 11 | are considered high level if they are able to express a large amount 12 | of functionality per line of code; other examples of high level 13 | languages are Python, Ruby, Octave, and R. In contrast, C is a 14 | low-level language. Low level languages can achieve higher execution 15 | speed, but at the cost of code that is considerably more difficult to 16 | read. C++ and Java occupy the middle ground sharing the advantages and 17 | the disadvantages of both levels. 18 | 19 | Low level languages are a particularly ill-suited for exploratory 20 | scientific computing, because they present a high barrier to access by 21 | scientists that are not specialist programmers. Low-level code is 22 | difficult to read and write, which slows development 23 | ([Prechelt2000ECS]_, [boehm1981]_, [Walston1977MPM]_) and makes it more 24 | difficult to understand the implementation of analysis 25 | algorithms. Ultimately this makes it less likely that scientists will 26 | use these languages for development, as their time for learning a new 27 | language or code base is at a premium. Low level languages do not 28 | usually offer an interactive command line, making data exploration 29 | much more rigid. Finally, applications written in low level languages 30 | tend to have more bugs, as bugs per line of code is approximately 31 | constant across many languages [brooks78]. 32 | 33 | In contrast, interpreted, high-level languages tend to have 34 | easy-to-read syntax and the native ability to interact with data 35 | structures and objects with a wide range of built-in 36 | functionality. High level code is designed to be closer to the level 37 | of the ideas we are trying to implement, so the developer spends more 38 | time thinking about what the code does rather than how to write 39 | it. This is particularly important as it is researchers and scientists 40 | who will serve as the main developers of scientific analysis 41 | software. The fast development time of high-level programs makes it 42 | much easier to test new ideas with prototypes. Their interactive 43 | nature allows researchers flexible ways to explore their data. 44 | 45 | .. [boehm1981] 46 | Boehm, Barry W. (1981) *Software Engineering Economics*. Englewood 47 | Cliffs, NJ: Prentice-Hall. 48 | 49 | .. [Prechelt2000ECS] 50 | Prechelt, Lutz. 2000. An Empirical Comparison of Seven Programming 51 | Languages. *IEEE Computer* 33, 23--29. 52 | 53 | .. [Walston1977MPM] 54 | Walston, C E, and C P Felix. 1977. A Method of Programming 55 | Measurement and Estimation. *IBM Syst J* 16, 54-73. 56 | -------------------------------------------------------------------------------- /docs/images/mindboggle_logo_200px_600dpi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/docs/images/mindboggle_logo_200px_600dpi.jpg -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. _readme: 2 | 3 | 4 | .. include:: ../README.rst 5 | -------------------------------------------------------------------------------- /docs/license.rst: -------------------------------------------------------------------------------- 1 | .. _license: 2 | 3 | .. include:: ../LICENSE.rst 4 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # Read the Docs requirements file 2 | # http://docs.readthedocs.org/en/latest/ 3 | 4 | #sphinxcontrib-napoleon 5 | #numpydoc 6 | -------------------------------------------------------------------------------- /info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | This file contains parameters for Mindboggle to fill settings in setup.py, 4 | the Mindboggle top-level docstring, and for building the docs. 5 | In setup.py we execute this file, so it cannot import mindboggle. 6 | """ 7 | 8 | # Format expected by setup.py and doc/source/conf.py: string of form "X.Y.Z" 9 | from mindboggle.version import __version__ as __version__ 10 | 11 | CLASSIFIERS = ["Development Status :: Beta", 12 | "Environment :: Console", 13 | "Intended Audience :: Science/Research", 14 | "License :: OSI Approved :: Apache v2.0", 15 | "Operating System :: Linux", 16 | "Programming Language :: Python 3", 17 | "Topic :: Scientific/Engineering"] 18 | 19 | description = ("Automated human brain image feature extraction, labeling, " 20 | "and shape analysis") 21 | 22 | # Note: this long_description is actually a copy/paste from the top-level 23 | # README.rst, so that it shows up nicely on PyPI. So please remember to edit 24 | # it only in one place and sync it correctly. 25 | long_description = """ 26 | ========== 27 | Mindboggle 28 | ========== 29 | 30 | Mindboggle is a software package for automated feature extraction, anatomical 31 | labeling, and morphometry of human brain magnetic resonance images, 32 | licensed under the terms of the Apache v2.0 license. 33 | Current information can always be found at the Mindboggle website, 34 | http://mindboggle.info, and on the Github main repository, 35 | http://github.com/nipy/mindboggle 36 | 37 | """ 38 | 39 | # Main setup parameters 40 | NAME = 'Mindboggle' 41 | MAINTAINER = "Arno Klein" 42 | MAINTAINER_EMAIL = "arno@childmind.org" 43 | DESCRIPTION = description 44 | LONG_DESCRIPTION = long_description 45 | URL = "http://mindboggle.info/" 46 | DOWNLOAD_URL = "http://mindboggle.info/" 47 | LICENSE = "Apache v2.0" 48 | CLASSIFIERS = CLASSIFIERS 49 | AUTHOR = "Arno Klein" 50 | AUTHOR_EMAIL = "arno@childmind.org" 51 | PLATFORMS = "Linux" 52 | VERSION = __version__ 53 | PROVIDES = ["mindboggle"] 54 | REQUIRES = ["nipype", "matplotlib", "colormath", "pandas", 55 | "etelemetry"] 56 | 57 | -------------------------------------------------------------------------------- /mindboggle/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | #from .info import (LONG_DESCRIPTION as __doc__, 4 | # __version__) 5 | #__doc__ += """ 6 | #""" 7 | 8 | # Set up package information function 9 | try: 10 | from .pkg_info import get_pkg_info as _get_pkg_info 11 | except: 12 | get_info = lambda: "" 13 | else: 14 | get_info = lambda : _get_pkg_info(os.path.dirname(__file__)) 15 | 16 | # module imports 17 | #from . import blah as blah 18 | # object imports 19 | #from .blah import blah, blah 20 | 21 | INIT_MSG = "Running {packname} version {version} (latest: {latest})".format 22 | latest = {"version": 'Unknown'} 23 | try: 24 | from .version import __version__ 25 | import etelemetry 26 | latest = etelemetry.get_project("nipy/mindboggle") 27 | except Exception as e: 28 | print("Could not check for version updates: ", e) 29 | finally: 30 | print(INIT_MSG(packname='mindboggle', 31 | version=__version__, 32 | latest=latest["version"])) 33 | 34 | -------------------------------------------------------------------------------- /mindboggle/data/OASIS-30_Atropos_template_to_MNI152_affine.txt: -------------------------------------------------------------------------------- 1 | #Insight Transform File V1.0 2 | #Transform 0 3 | Transform: MatrixOffsetTransformBase_double_3_3 4 | Parameters: 0.923633641884771 0.007304481142718668 -0.0002102248850247082 -0.005552222846200372 0.9462106492619754 0.057714677072304994 -0.0052838319667065595 -0.07235281624560219 0.863449903229525 110.54370605449894 136.3445770776469 -129.0634703851478 5 | FixedParameters: -0.6093604490279011 21.159315392104062 10.61478816947021 6 | -------------------------------------------------------------------------------- /mindboggle/data/OASIS-TRT-20_jointfusion_DKT31_CMA_labels_in_MNI152_v2.nii.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/mindboggle/data/OASIS-TRT-20_jointfusion_DKT31_CMA_labels_in_MNI152_v2.nii.gz -------------------------------------------------------------------------------- /mindboggle/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/mindboggle/data/__init__.py -------------------------------------------------------------------------------- /mindboggle/data/data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Functions for fetching information related to Mindboggle data. 4 | 5 | Authors: 6 | - Arno Klein, 2017 (arno@mindboggle.info) http://binarybottle.com 7 | 8 | Copyright 2017, Mindboggle team (http://mindboggle.info), Apache v2.0 License 9 | 10 | """ 11 | 12 | def fetch_file_path(file_name): 13 | """ 14 | Return the path to files in the data directory in Mindboggle. 15 | 16 | Parameters 17 | ---------- 18 | file_name : str 19 | name of the file whose full path is to be returned 20 | 21 | Returns 22 | ------- 23 | file_path : str 24 | full path to file 25 | 26 | """ 27 | import os 28 | 29 | file_path = os.path.join(os.path.dirname(__file__), file_name) 30 | 31 | return file_path 32 | -------------------------------------------------------------------------------- /mindboggle/evaluate/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /mindboggle/features/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /mindboggle/guts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/mindboggle/guts/__init__.py -------------------------------------------------------------------------------- /mindboggle/guts/kernels.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Kernels. 4 | 5 | Authors: 6 | - Eliezer Stavsky, 2012 (eli.stavsky@gmail.com) 7 | - Arno Klein, 2016 (arno@mindboggle.info) 8 | 9 | Copyright 2016, Mindboggle team (http://mindboggle.info), Apache v2.0 License 10 | 11 | """ 12 | 13 | 14 | def rbf_kernel(x1, x2, sigma): 15 | """ 16 | Compute normalized and unnormalized graph Laplacians. 17 | 18 | Parameters 19 | ---------- 20 | x1 : Nx1 numpy array 21 | x2 : Nx1 numpy array 22 | sigma : float 23 | 24 | Returns 25 | ------- 26 | rbf : float 27 | 28 | Examples 29 | -------- 30 | >>> import numpy as np 31 | >>> from mindboggle.guts.kernels import rbf_kernel 32 | >>> x1 = np.array([0.1,0.2,0.4,0]) 33 | >>> x2 = np.array([0.1,0.3,0.5,0]) 34 | >>> sigma = 0.5 35 | >>> rbf = rbf_kernel(x1, x2, sigma) 36 | >>> print('{0:0.5f}'.format(rbf)) 37 | 0.96079 38 | 39 | """ 40 | import numpy as np 41 | 42 | return np.exp(-np.linalg.norm(x1 - x2) ** 2 / (2 * sigma ** 2)) 43 | 44 | 45 | # def cotangent_kernel(Nodes, Meshes): 46 | # """ 47 | # This function constructs weighted edges of a graph. 48 | # 49 | # Parameters 50 | # ---------- 51 | # Nodes : numpy array 52 | # Meshes : numpy array 53 | # 54 | # Returns 55 | # ------- 56 | # W : N x N matrix 57 | # weight matrix 58 | # 59 | # Examples 60 | # -------- 61 | # >>> import numpy as np 62 | # >>> from mindboggle.guts.kernels import cotangent_kernel 63 | # >>> Nodes = np.array([0,1,2,3,4]) 64 | # >>> Meshes = np.array([[1,2,3],[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,3,4]]) 65 | # >>> cotangent_kernel(Nodes, Meshes) 66 | # ValueError: 'axisa' out of bounds 67 | # 68 | # """ 69 | # import numpy as np 70 | # from scipy.sparse import lil_matrix 71 | # 72 | # num_nodes = Nodes.shape[0] 73 | # W = lil_matrix((num_nodes, num_nodes)) 74 | # #print('Constructing sparse affinity matrix...') 75 | # for c in Meshes: 76 | # # Obtain vertices which comprise face 77 | # v0, v1, v2 = Nodes[c[0]], Nodes[c[1]], Nodes[c[2]] 78 | # 79 | # # Obtain cotangents of angles 80 | # cot0 = np.dot(v1-v0, v2-v0) / np.linalg.norm(np.cross(v1-v0, v2-v0)) 81 | # cot1 = np.dot(v2-v1, v0-v1) / np.linalg.norm(np.cross(v2-v1, v0-v1)) 82 | # cot2 = np.dot(v0-v2, v1-v2) / np.linalg.norm(np.cross(v0-v2, v1-v2)) 83 | # 84 | # # Update weight matrix accordingly 85 | # W[c[1], c[2]] += cot0 86 | # W[c[2], c[1]] += cot0 87 | # W[c[0], c[2]] += cot1 88 | # W[c[2], c[0]] += cot1 89 | # W[c[0], c[1]] += cot2 90 | # W[c[1], c[0]] += cot2 91 | # 92 | # return W 93 | 94 | 95 | def inverse_distance(x1, x2, epsilon): 96 | """ 97 | This function constructs weighted edges of a graph, 98 | where the weight is the inverse of the distance between two nodes. 99 | 100 | Parameters 101 | ---------- 102 | x1 : Nx1 numpy array 103 | x2 : Nx1 numpy array 104 | epsilon : float 105 | 106 | Returns 107 | ------- 108 | d : float 109 | 110 | Examples 111 | -------- 112 | >>> import numpy as np 113 | >>> from mindboggle.guts.kernels import inverse_distance 114 | >>> x1 = np.array([0.1,0.2,0.4,0]) 115 | >>> x2 = np.array([0.1,0.3,0.5,0]) 116 | >>> epsilon = 0.05 117 | >>> d = inverse_distance(x1, x2, epsilon) 118 | >>> print('{0:0.5f}'.format(d)) 119 | 5.22408 120 | 121 | """ 122 | import numpy as np 123 | 124 | return 1.0/(np.linalg.norm(x1 - x2) + epsilon) 125 | 126 | 127 | # ============================================================================ 128 | # Doctests 129 | # ============================================================================ 130 | if __name__ == "__main__": 131 | import doctest 132 | doctest.testmod(verbose=True) # py.test --doctest-modules -------------------------------------------------------------------------------- /mindboggle/guts/utilities.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Utility functions. 4 | 5 | Authors: 6 | - Arno Klein, 2012-2016 (arno@mindboggle.info) http://binarybottle.com 7 | 8 | Copyright 2016, Mindboggle team (http://mindboggle.info), Apache v2.0 License 9 | 10 | """ 11 | 12 | 13 | def execute(cmd, type='os'): 14 | """ 15 | Execute command by either subprocess.call or os.system. 16 | 17 | Parameters 18 | ---------- 19 | cmd : sequence (string also permitted if type=='os') 20 | command with arguments 21 | type : string 22 | how to execute {os, subprocess} 23 | 24 | Examples 25 | -------- 26 | >>> from mindboggle.guts.utilities import execute # doctest: +SKIP 27 | >>> cmd = ['date', '-r', '0'] # doctest: +SKIP 28 | >>> type = 'subprocess' # doctest: +SKIP 29 | >>> execute(cmd, type) # doctest: +SKIP 30 | Wed Dec 31 19:00:00 EST 1969 31 | >>> type = 'os' # doctest: +SKIP 32 | >>> execute(cmd, type) # doctest: +SKIP 33 | Wed Dec 31 19:00:00 EST 1969 34 | >>> cmd = 'date -r 0' # doctest: +SKIP 35 | >>> execute(cmd) # doctest: +SKIP 36 | Wed Dec 31 19:00:00 EST 1969 37 | 38 | """ 39 | from subprocess import call 40 | 41 | verbose = False 42 | if verbose: 43 | if isinstance(cmd, str): 44 | print(cmd) 45 | else: 46 | print(' '.join(cmd)) 47 | 48 | # Use subprocess.call: 49 | if type == 'subprocess': 50 | try: 51 | retcode = call(cmd) 52 | if retcode < 0: 53 | raise IOError("Child terminated by signal: retcode {0}". 54 | format(retcode)) 55 | except OSError as e: 56 | raise OSError("Execution failed: {0}".format(e)) 57 | 58 | # Use os.system: 59 | elif type == 'os': 60 | from os import system 61 | 62 | if isinstance(cmd, str): 63 | pass 64 | else: 65 | cmd = ' '.join(cmd) 66 | try: 67 | system(cmd) 68 | except OSError as e: 69 | raise OSError("Execution failed: {0}".format(e)) 70 | 71 | else: 72 | raise IOError('Select either "subprocess" or "os" for execution type.') 73 | 74 | 75 | def list_strings(string1='', string2='', string3='', string4=''): 76 | """ 77 | Put strings in a list. 78 | 79 | Parameters 80 | ---------- 81 | string1 : string 82 | string2 : string 83 | string3 : string 84 | string4 : string 85 | 86 | Returns 87 | ------- 88 | string_list : list of strings 89 | 90 | Examples 91 | -------- 92 | >>> from mindboggle.guts.utilities import list_strings 93 | >>> string1 = 'a b c' 94 | >>> string2 = 'd e f' 95 | >>> string3 = '' 96 | >>> string4 = 'j k l' 97 | >>> string_list = list_strings(string1, string2, string3, string4) 98 | >>> string_list 99 | ['a b c', 'd e f', 'j k l'] 100 | 101 | """ 102 | 103 | string_list = [] 104 | if string1 and isinstance(string1, str): 105 | string_list.append(string1) 106 | if string2 and isinstance(string1, str): 107 | string_list.append(string2) 108 | if string3 and isinstance(string1, str): 109 | string_list.append(string3) 110 | if string4 and isinstance(string1, str): 111 | string_list.append(string4) 112 | 113 | return string_list 114 | 115 | 116 | # ============================================================================ 117 | # Doctests 118 | # ============================================================================ 119 | if __name__ == "__main__": 120 | import doctest 121 | doctest.testmod(verbose=True) # py.test --doctest-modules -------------------------------------------------------------------------------- /mindboggle/mio/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/mindboggle/mio/__init__.py -------------------------------------------------------------------------------- /mindboggle/mio/convert_volumes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Functions for reading and writing nifti volume files. 4 | 5 | 6 | Authors: 7 | - Arno Klein, 2012-2016 (arno@mindboggle.info) http://binarybottle.com 8 | 9 | Copyright 2016, Mindboggle team (http://mindboggle.info), Apache v2.0 License 10 | 11 | """ 12 | 13 | 14 | def convert2nii(input_file, reference_file, output_file='', interp='continuous'): 15 | """ 16 | Convert volume from the input file format to the output file format. 17 | 18 | If output_file is empty, reslice to nifti format using nibabel and 19 | scipy.ndimage.affine_transform, after nilearn.image.resample_img:: 20 | 21 | from nilearn.image import resample_img 22 | resliced = resample_img(input_file, target_affine=xfm2, 23 | target_shape=dim2, 24 | interpolation=interp).get_data() 25 | 26 | Example use: Convert FreeSurfer 'unconformed' .mgz file to nifti. 27 | 28 | Parameters 29 | ---------- 30 | input_file : string 31 | input file name 32 | reference_file : string 33 | target file name 34 | output_file : string 35 | name of output file 36 | interp : string 37 | interpolation method: 'continuous' (default) or 'nearest' 38 | 39 | Returns 40 | ------- 41 | output_file : string 42 | name of output file 43 | 44 | Examples 45 | -------- 46 | >>> from mindboggle.mio.convert_volumes import convert2nii 47 | >>> from mindboggle.mio.fetch_data import prep_tests 48 | >>> urls, fetch_data = prep_tests() 49 | >>> input_file = fetch_data(urls['freesurfer_orig_mgz'], '', '.mgz') 50 | >>> reference_file = fetch_data(urls['freesurfer_segmentation'], '', '.nii.gz') 51 | >>> output_file = 'convert2nii.nii.gz' 52 | >>> interp = 'nearest' 53 | >>> output_file = convert2nii(input_file, reference_file, output_file, 54 | ... interp) 55 | 56 | View nifti file (skip test): 57 | 58 | >>> from mindboggle.mio.plots import plot_volumes 59 | >>> plot_volumes(output_file) # doctest: +SKIP 60 | 61 | """ 62 | import os 63 | import numpy as np 64 | import nibabel as nb 65 | from scipy import ndimage, linalg 66 | 67 | if not os.path.exists(input_file): 68 | raise IOError("Input file " + input_file + " not found") 69 | if not os.path.exists(reference_file): 70 | raise IOError("Reference file " + reference_file + " not found.") 71 | if not output_file: 72 | output_file = os.path.join(os.getcwd(), 73 | os.path.basename(input_file) + '.nii.gz') 74 | # ------------------------------------------------------------------------ 75 | # Load reference image: 76 | # ------------------------------------------------------------------------ 77 | vol2 = nb.load(reference_file) 78 | xfm2 = vol2.affine 79 | dim2 = vol2.shape 80 | # ------------------------------------------------------------------------ 81 | # Resample the source image according to the reference image: 82 | # ------------------------------------------------------------------------ 83 | vol1 = nb.load(input_file) 84 | dat1 = vol1.get_data() 85 | xfm1 = vol1.affine 86 | if np.all(xfm2 == xfm1): 87 | transform_affine = np.eye(4) 88 | else: 89 | transform_affine = np.dot(linalg.inv(xfm1), xfm2) 90 | A = transform_affine[0:3, 0:3] 91 | b = transform_affine[0:3, 3] 92 | A_inv = linalg.inv(A) 93 | # If A is diagonal, affine_transform uses a better algorithm. 94 | if np.all(np.diag(np.diag(A)) == A): 95 | A = np.diag(A) 96 | else: 97 | b = np.dot(A, b) 98 | 99 | # order of the spline interpolation: 100 | if interp == 'nearest': 101 | interpolation_order = 0 102 | else: 103 | interpolation_order = 3 104 | resliced = ndimage.affine_transform(dat1, A, 105 | offset=np.dot(A_inv, b), 106 | output_shape=dim2, 107 | order=interpolation_order) 108 | 109 | # ------------------------------------------------------------------------ 110 | # Save the image with the reference affine transform: 111 | # ------------------------------------------------------------------------ 112 | img = nb.Nifti1Image(resliced, xfm2) 113 | img.to_filename(output_file) 114 | 115 | return output_file 116 | 117 | 118 | def xyz2nii(input_xyz_file, output_nii_file='', origin=[], pad=10): 119 | """ 120 | Convert [x,y,z] coordinate file to nifti (nii.gz) volume file. 121 | 122 | Parameters 123 | ---------- 124 | input_xyz_file : string 125 | input [x,y,z] coordinate text file 126 | output_nii_file : string 127 | output nifti (nii.gz) volume file 128 | origin : list of floats 129 | [x,y,z] coordinates for origin 130 | pad : integer 131 | number of voxels to pad input coordinates in x, y, and z directions 132 | 133 | Returns 134 | ------- 135 | output_nii_file : string 136 | output nifti (nii.gz) volume file 137 | 138 | Examples 139 | -------- 140 | >>> from mindboggle.mio.convert_volumes import xyz2nii 141 | >>> input_xyz_file = 'face.xyz.txt' # doctest: +SKIP 142 | >>> origin = [] 143 | >>> pad = 10 144 | >>> output_nii_file = 'xyz2nii.nii.gz' 145 | >>> xyz2nii(input_xyz_file) # doctest: +SKIP 146 | 147 | View nifti file (skip test): 148 | 149 | >>> from mindboggle.mio.plots import plot_volumes 150 | >>> plot_volumes('xyz.nii.gz') # doctest: +SKIP 151 | 152 | """ 153 | import os 154 | import numpy as np 155 | import nibabel as nb 156 | 157 | # Load coordinates and scalars: 158 | XYZscalars = np.loadtxt(input_xyz_file) 159 | XYZ = np.round(XYZscalars[:, 0:3]) 160 | #scalars = XYZscalars[:, 3::] 161 | 162 | if origin: 163 | XYZ -= origin 164 | 165 | XYZ += np.abs(np.min(XYZ, axis=0)) + [pad, pad, pad] 166 | XYZ = np.round(XYZ) 167 | dims = np.max(XYZ, axis=0) + [pad, pad, pad] 168 | data = np.zeros(dims) 169 | 170 | # Loop through rows or array and write 1s in image volume: 171 | for irow, xyz in enumerate(XYZ): 172 | data[xyz[0], xyz[1], xyz[2]] = 1 173 | 174 | # Write output image volume: 175 | if not output_nii_file: 176 | output_nii_file = os.path.join(os.getcwd(), 'xyz.nii.gz') 177 | img = nb.Nifti1Image(data, affine=np.eye(4,4)) 178 | img.to_filename(output_nii_file) 179 | 180 | return output_nii_file 181 | 182 | 183 | # ============================================================================ 184 | # Doctests 185 | # ============================================================================ 186 | if __name__ == "__main__": 187 | import doctest 188 | doctest.testmod(verbose=True) # py.test --doctest-modules -------------------------------------------------------------------------------- /mindboggle/mio/copy_final_tables: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Copy tables directories generated by Mindboggle. 4 | 5 | Run: 6 | $ copy_final_tables ~/mindboggled --out ~/tables 7 | 8 | Authors: 9 | - Arno Klein, 2014-2016 (arno@mindboggle.info) http://binarybottle.com 10 | 11 | Copyright 2016, Mindboggle team (http://mindboggle.info), Apache v2.0 License 12 | 13 | """ 14 | import os 15 | import argparse 16 | 17 | # ---------------------------------------------------------------------------- 18 | # Command-line arguments: 19 | # ---------------------------------------------------------------------------- 20 | parser = argparse.ArgumentParser(description=""" 21 | Copy tables directories generated by Mindboggle.""", 22 | formatter_class = lambda prog: 23 | argparse.HelpFormatter(prog, max_help_position=40)) 24 | # "positional arguments": 25 | parser.add_argument("IN_DIR", 26 | help=('directory containing mindboggle output')) 27 | # "optional arguments": 28 | parser.add_argument("--out", help="output directory", 29 | default='mindboggled_tables', metavar='STR') 30 | args = parser.parse_args() 31 | in_dir = args.IN_DIR 32 | out = args.out 33 | 34 | # ---------------------------------------------------------------------------- 35 | # Copy files: 36 | # ---------------------------------------------------------------------------- 37 | if not os.path.exists(out): 38 | os.makedirs(out) 39 | 40 | dirs = os.listdir(in_dir) 41 | for dir in dirs: 42 | 43 | in_tables = os.path.join(in_dir, dir, 'tables') 44 | out_tables = os.path.join(out, dir) 45 | if not os.path.exists(out_tables): 46 | os.makedirs(out_tables) 47 | 48 | cmd = 'cp -R {0} {1}'.format(in_tables, out_tables) 49 | 50 | os.system(cmd) 51 | -------------------------------------------------------------------------------- /mindboggle/shapes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/mindboggle/shapes/__init__.py -------------------------------------------------------------------------------- /mindboggle/shapes/zernike/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/mindboggle/shapes/zernike/__init__.py -------------------------------------------------------------------------------- /mindboggle/shapes/zernike/__main__.py: -------------------------------------------------------------------------------- 1 | from . import zernike 2 | #from .test.multiproc import MultiprocPipeline 3 | from mindboggle.mio.vtks import read_vtk 4 | import numpy as np 5 | 6 | import argparse 7 | import logging 8 | #import profilehooks 9 | 10 | def example1(): 11 | # >>> # Example 1: simple cube (decimation results in a Segmentation Fault): 12 | # >>> from mindboggle.shapes.zernike import zernike_moments 13 | # >>> points = [[0,0,0], [1,0,0], [0,0,1], [0,1,1], [1,0,1], [0,1,0], [1,1,1], [1,1,0]] 14 | # >>> faces = [[0,2,4], [0,1,4], [2,3,4], [3,4,5], [3,5,6], [0,1,7]] 15 | # >>> order = 3 16 | # >>> scale_input = True 17 | # >>> zernike_moments(points, faces, order, scale_input) 18 | # [0.0918881492369654, 19 | # 0.09357431096617608, 20 | # 0.04309029164656885, 21 | # 0.06466432586854755, 22 | # 0.03820155248327533, 23 | # 0.04138011726544602] 24 | 25 | print("Example 1: Simple cube") 26 | points = np.array([[0,0,0], [1,0,0], [0,0,1], [0,1,1], [1,0,1], [0,1,0], [1,1,1], [1,1,0]]) 27 | faces = np.array([[0,2,4], [0,1,4], [2,3,4], [3,4,5], [3,5,6], [0,1,7]]) 28 | result = zernike(points, faces, order=3, scale_input=True) 29 | assert np.allclose(result, np.array([0.0918881492369654, 0.09357431096617608, 0.04309029164656885, 30 | 0.06466432586854755, 0.03820155248327533, 0.04138011726544602])) 31 | 32 | def main(): 33 | zernike_fn = zernike 34 | 35 | parser = argparse.ArgumentParser() 36 | parser.add_argument('--debug', nargs='?', default=None, const='debug', choices=['debug', 'info', 'warning', 'error', 'critical']) 37 | parser.add_argument('vtk_file', nargs='?', default=None) 38 | parser.add_argument('-o', '--order', type=int, default=3) 39 | parser.add_argument('-p', '--profile', nargs='?', default=None, const='stdout') 40 | parser.add_argument('-t', '--timecall', default=False, action='store_true') 41 | parser.add_argument('-v', '--validate', default=False, action='store_true') 42 | ns = parser.parse_args() 43 | 44 | if ns.debug is not None: 45 | logging.basicConfig(level=getattr(logging, ns.debug.upper())) 46 | 47 | # if ns.profile is not None: 48 | # filename = ns.profile 49 | # if ns.profile == 'stdout': 50 | # filename = None 51 | # zernike_fn = profilehooks.profile(zernike_fn, immediate=False, filename=filename) 52 | 53 | # if ns.timecall: 54 | # zernike_fn = profilehooks.timecall(zernike_fn) 55 | 56 | if ns.vtk_file is not None: 57 | points, indices, lines, faces, depths, scalar_names, npoints, \ 58 | input_vtk = read_vtk(ns.vtk_file) 59 | print('{0} {1}'.format(len(faces), len(points))) 60 | X = zernike_fn(points, faces, order=ns.order, scale_input=True) 61 | if ns.validate: 62 | Y = zernike_fn(points, faces, order=ns.order, scale_input=True, pl_cls=MultiprocPipeline) 63 | assert np.allclose(X, Y) 64 | else: 65 | example1() 66 | 67 | 68 | if __name__ == '__main__': 69 | main() 70 | -------------------------------------------------------------------------------- /mindboggle/shapes/zernike/helpers.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def nested_loop(stack, args): 4 | if len(stack) != 0: 5 | fn = stack.pop() 6 | for i in fn(*args): 7 | for j in nested_loop(stack, args+[i]): 8 | yield (i,)+j 9 | stack.append(fn) 10 | else: 11 | yield tuple() 12 | 13 | def nest(*_stack): 14 | return nested_loop(list(reversed(_stack)), []) 15 | 16 | def autocat(arrs, **dargs): 17 | axis = dargs.pop('axis', None) 18 | if axis is None: 19 | return np.concatenate(arrs, **dargs) 20 | ndim = arrs[0].ndim 21 | assert all([ a.ndim == ndim for a in arrs]) 22 | if axis >= ndim: 23 | arrs = tuple([ np.expand_dims(a,axis) for a in arrs ]) 24 | return np.concatenate(arrs, axis=axis) 25 | 26 | def main(): 27 | 28 | def zero(): return list(range(0, 3)) 29 | def one(_x): return list(range(0, _x)) 30 | def two(_x, _y): return list(range(0, _y)) 31 | 32 | for i in nest(zero, one, two): 33 | print('{0} {1}'.format('#'*5, i)) 34 | 35 | if __name__ == '__main__': 36 | main() 37 | -------------------------------------------------------------------------------- /mindboggle/thirdparty/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'arno' 2 | -------------------------------------------------------------------------------- /mindboggle/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '1.3.8' 2 | -------------------------------------------------------------------------------- /mindboggle/x/developer_notes: -------------------------------------------------------------------------------- 1 | # Internal notes to aid Mindboggle development: 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Printing floats/arrays in docstring tests: 5 | # ---------------------------------------------------------------------------- 6 | # float: 7 | >>> np.float("{0:.{1}f}".format(depth_threshold, 5)) 8 | 0.21345 9 | # array of floats: 10 | >>> [np.float("{0:.{1}f}".format(x, 5)) for x in means[0:5]] 11 | [-1.1793, -1.21405, -2.49318, -3.58116, -3.34987] 12 | # array of floats with condition: 13 | >>> [np.float("{0:.{1}f}".format(x, 5))
... for x in [y for y in volumes if y > 0][0:5]]
 14 | # ndarray of floats: 15 | >>> print(np.array_str(np.array(vector_distances), 16 | ... precision=5, suppress_small=True)) 17 | [[ 0. 0.8165 0.89753 0.74536] 18 | [ 0. 0. 0.16667 1.52753] 19 | [ 0. 0. 0. 1.60728] 20 | [ 0. 0. 0. 0. ]] 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /mindboggle/x/reprozip_container.sh: -------------------------------------------------------------------------------- 1 | # Reduce the size of the mindboggle docker container. 2 | # NOTE: The reprozip command is still under construction! 3 | #----------------------------------------------------------------------------- 4 | # First build the docker image: 5 | # docker build -t mindboggle -f Dockerfile.mindboggle.complete . 6 | # 7 | # Then run the docker container: 8 | # docker run --rm -ti -v /Users/arno:/home/jovyan/work -p 8888:8888 -p 5000:5000 mindboggle bash 9 | # 10 | # In this script, use reprozip to reduce the mindboggle docker container 11 | # to just the necessary components. 12 | # 13 | # (c) 2017 by Arno Klein (CC-BY license) 14 | #----------------------------------------------------------------------------- 15 | 16 | #----------------------------------------------------------------------------- 17 | # Retain only those portions of the docker container that are required 18 | #----------------------------------------------------------------------------- 19 | DATA=/home/jovyan/work/Data 20 | T1=$DATA/example_mri_data/T1.nii.gz 21 | T2=$DATA/example_mri_data/T2.nii.gz 22 | SUBJECT=arno 23 | TEMPLATE=$DATA/OASIS-30_Atropos_template 24 | FREESURFER_SUBJECTS=$DATA/freesurfer_subjects 25 | FREESURFER_SUBJECT=$FREESURFER_SUBJECTS/$SUBJECT 26 | ANTS_SUBJECT=$DATA/ants_subjects/$SUBJECT 27 | #FREESURFER_SUBJECT=$DATA/mindboggle_input_example/freesurfer/subjects/arno 28 | #ANTS_SUBJECT=$DATA/mindboggle_input_example/ants/subjects/arno 29 | MINDBOGGLED=$DATA/mindboggled 30 | 31 | #----------------------------------------------------------------------------- 32 | # Retain only those portions of the docker container that are required 33 | #----------------------------------------------------------------------------- 34 | mkdir $ANTS_SUBJECT 35 | reprozip trace -d mindboggle \ 36 | recon-all -all -i $T1 -T2 $T2 -s $SUBJECT -sd $FREESURFER_SUBJECTS -cw256 && \ 37 | antsCorticalThickness.sh -d 3 -a $T1 -o $ANTS_SUBJECT/ants \ 38 | -e $TEMPLATE/T_template0.nii.gz \ 39 | -t $TEMPLATE/T_template0_BrainCerebellum.nii.gz \ 40 | -m $TEMPLATE/T_template0_BrainCerebellumProbabilityMask.nii.gz \ 41 | -f $TEMPLATE/T_template0_BrainCerebellumExtractionMask.nii.gz \ 42 | -p $TEMPLATE/Priors2/priors%d.nii.gz && \ 43 | mindboggle $FREESURFER_SUBJECT --cpus 8 \ 44 | --ants $ANTS_SUBJECT/antsBrainSegmentation.nii.gz \ 45 | --out $MINDBOGGLED \ 46 | --fundi \ 47 | --moments 10 \ 48 | --spectra 10 \ 49 | --graph hier \ 50 | --roygbiv 51 | #--no_volumes \ 52 | #--no_surfaces \ 53 | #--no_labels \ 54 | #--no_shapes \ 55 | #--no_sulci \ 56 | #--no_points \ 57 | #--no_moments \ 58 | #--no_spectra \ 59 | #--no_thickness \ 60 | #--help --version \ 61 | #--my_atlas --my_atlases --my_graywhite --my_transform \ 62 | #--plugin --plugin_args \ 63 | 64 | #reprozip pack -d mindboggle-trace mindboggle.rpz 65 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nipy/mindboggle/bc10812979d42e94b8a01ad8f98b4ceae33169e5/mindboggle/x/test_zernike/__init__.py -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/D_CV_orig_m.py: -------------------------------------------------------------------------------- 1 | def D_CV_orig(cfg,facet,num_vertices,N,X,K,tri_matrix) : #function [C,Vol] = D_CV_orig(facet,num_vertices,N,X,K,tri_matrix) 2 | # 3 | C = cfg.zeros(num_vertices,N+1,N+1,N+1) #C=zeros(num_vertices,N+1,N+1,N+1); 4 | # 5 | # % Vertex 1 6 | # % Monomial combinations for each vertex in a given facet 7 | vertex_1=X[K[facet-1,0],:] #! facet is 1-indexed # vertex_1=X(K(facet,1),:); 8 | # % Vertex 9 | vx = vertex_1[0] #! # vx=vertex_1(1); 10 | vy = vertex_1[1] #! # vy=vertex_1(2); 11 | vz = vertex_1[2] #! # vz=vertex_1(3); 12 | C[0,:,:,:]=cfg.mon_comb(tri_matrix,[vx,vy,vz],N) #! # C(1,:,:,:)=mon_comb(tri_matrix,[vx vy vz],N); 13 | # 14 | # % Vertex 2 15 | # % Monomial combinations for each vertex in a given facet 16 | vertex_2=X[K[facet-1,1],:] #! # vertex_2=X(K(facet,2),:); 17 | # % Vertex 18 | vx=vertex_2[0] #! # vx=vertex_2(1); 19 | vy=vertex_2[1] #! # vy=vertex_2(2); 20 | vz=vertex_2[2] #! # vz=vertex_2(3); 21 | C[1,:,:,:]=cfg.mon_comb(tri_matrix,[vx,vy,vz],N) #! # C(2,:,:,:)=mon_comb(tri_matrix,[vx vy vz],N); 22 | # 23 | # % Vertex 1 24 | # % Monomial combinations for each vertex in a given facet 25 | vertex_3=X[K[facet-1,2],:] #! # vertex_3=X(K(facet,3),:); 26 | # % Vertex 27 | vx=vertex_3[0] #! # vx=vertex_3(1); 28 | vy=vertex_3[1] #! # vy=vertex_3(2); 29 | vz=vertex_3[2] #! # vz=vertex_3(3); 30 | C[2,:,:,:]=cfg.mon_comb(tri_matrix,[vx,vy,vz],N) #! # C(3,:,:,:)=mon_comb(tri_matrix,[vx vy vz],N); 31 | # %Calculate Volume 32 | Vol=cfg.det(cfg.cat(1,vertex_1,vertex_2,vertex_3)) #!axis # Vol=det(cat(2,vertex_1',vertex_2',vertex_3')); 33 | return C,Vol 34 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/D_SG_orig_m.py: -------------------------------------------------------------------------------- 1 | def D_SG_orig(cfg,num_facets,i,N,C,D,Vol,F) : #function G = D_SG_orig(num_facets,i,N,C,D,Vol,F) 2 | # 3 | G=cfg.zeros(N+1,N+1) #G=zeros(N+1,N+1); 4 | S=cfg.zeros(num_facets,N+1,N+1,N+1) #S=zeros(num_facets,N+1,N+1,N+1); 5 | # 6 | for j in cfg.rng(0,N-i) : #for j=0:(N-i) 7 | for k in cfg.rng(0,N-i-j) : # for k=0:(N-i-j) 8 | # 9 | S = cfg.D_SG_orig_part(num_facets,i,j,k,C,D,S,Vol,F) # S = D_SG_orig_part(num_facets,i,j,k,C,D,S,Vol,F); 10 | # % Geometric moments after summing through all facets 11 | G[j,k]=cfg.sum(S[:,i,j,k]) #! # G(j+1,k+1)=sum(S(:,i+1,j+1,k+1)); 12 | # end 13 | #end 14 | return G 15 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/D_SG_orig_part_m.py: -------------------------------------------------------------------------------- 1 | def D_SG_orig_part(cfg,num_facets,i,j,k,C,D,S,Vol,F) : #function S = D_SG_orig_part(num_facets,i,j,k,C,D,S,Vol,F) 2 | # 3 | for facet in cfg.rng(0,num_facets-1) : #! #for facet=1:num_facets 4 | # % Sijk for a given facet 5 | # 6 | # 7 | # %aux_1 = factorial(i)*factorial(j)*factorial(k); 8 | # %aux_2 = factorial(i+j+k+2); 9 | # 10 | aux_1 = F[i]*F[j]*F[k] #! # aux_1 = F(i + 1)*F(j + 1)*F(k + 1); 11 | aux_2 = F[i+j+k+2] #! # aux_2 = F(i+j+k+2 + 1); 12 | aux = aux_1/aux_2 # aux=aux_1/aux_2; 13 | # 14 | tmp=0 # tmp=0; 15 | for i1 in cfg.rng(0,i) : # for i1=0:i 16 | for j1 in cfg.rng(0,j) : # for j1=0:j 17 | for k1 in cfg.rng(0,k) : # for k1=0:k 18 | tmp = tmp + (C[facet,i1,j1,k1]*D[facet,i-i1,j-j1,k-k1]) #! # tmp=tmp+(C(facet,i1+1,j1+1,k1+1)*D(facet,i-i1+1,j-j1+1,k-k1+1)); 19 | # end 20 | # end 21 | # end 22 | tmp = tmp*aux # tmp=tmp*aux; 23 | # 24 | S[facet,i,j,k]=(Vol[facet]*tmp)/(i+j+k+3) #! # S(facet,i+1,j+1,k+1)=(Vol(facet)*tmp)/(i+j+k+3); 25 | #end 26 | return S 27 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/Dabc_orig_m.py: -------------------------------------------------------------------------------- 1 | def Dabc_orig(cfg,C,N) : #function D=Dabc_orig(C,N) 2 | #% Pre-computes the values for D 3 | #% and store them in matrix form 4 | #% to be used for Geometric Moments 5 | # 6 | D = cfg.zeros(N+1,N+1,N+1) #D = zeros(N+1,N+1,N+1); 7 | for a in cfg.rng(0,N) : #for a=0:N 8 | for b in cfg.rng(0,N) : # for b=0:N 9 | for c in cfg.rng(0,N) : # for c=0:N 10 | temp = 0 # temp=0; 11 | for i2 in cfg.rng(0,a) : # for i2=0:a 12 | for j2 in cfg.rng(0,b) : # for j2=0:b 13 | for k2 in cfg.rng(0,c) : # for k2=0:c 14 | temp = temp+C[1,i2,j2,k2]*C[2,a-i2,b-j2,c-k2] #! # temp=temp+C(2,i2+1,j2+1,k2+1)*C(3,a-i2+1,b-j2+1,c-k2+1); 15 | # end 16 | # end 17 | # end 18 | D[a,b,c] = temp #! # D(a+1,b+1,c+1)=temp; 19 | # end 20 | # end 21 | #end 22 | return D 23 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/Qklnu_m.py: -------------------------------------------------------------------------------- 1 | def Qklnu(cfg,k,l,nu) : #function q=Qklnu(k,l,nu) 2 | # 3 | #% Computes Q, neccesary constant#% Computes Q, neccesary constant 4 | #% for the moments computation#% for the moments computation 5 | # 6 | aux_1=cfg.power(-1,k+nu)/cfg.power(4.0,k) #aux_1=power(-1,k+nu)/power(4,k) 7 | aux_2=cfg.sqrt((2*l+4*k+3)/3.0) #aux_2=sqrt((2*l+4*k+3)/3) 8 | aux_3=cfg.trinomial(nu,k-nu,l+nu+1)*cfg.nchoosek(2*(l+nu+1+k),l+nu+1+k) #aux_3=trinomial(nu,k-nu,l+nu+1)*nchoosek(2*(l+nu+1+k),l+nu+1+k) 9 | aux_4=cfg.nchoosek(2.0*(l+nu+1),l+nu+1) #aux_4=nchoosek(2*(l+nu+1),l+nu+1) 10 | q=(aux_1*aux_2*aux_3)/aux_4 #q=(aux_1*aux_2*aux_3)/aux_4 11 | return q 12 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/Yljm_m.py: -------------------------------------------------------------------------------- 1 | def Yljm(cfg,l,j,m) : #function y=Yljm(l,j,m) 2 | # 3 | #% Computes a constant used in Zernike moments 4 | # 5 | aux_1=cfg.power(-1,j)*(cfg.sqrt(2*l+1)/cfg.power(2,l)) #aux_1=power(-1,j)*(sqrt(2*l+1)/power(2,l)); 6 | aux_2=cfg.trinomial(m,j,l-m-2*j)*cfg.nchoosek(2*(l-j),l-j) #aux_2=trinomial(m,j,l-m-2*j)*nchoosek(2*(l-j),l-j); 7 | aux_3=cfg.sqrt(cfg.trinomial(m,m,l-m)) #aux_3=sqrt(trinomial(m,m,l-m)); 8 | y=(aux_1*aux_2)/aux_3 #y=(aux_1*aux_2)/aux_3; 9 | return y 10 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/__init__.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import numpy.linalg 3 | import scipy 4 | import scipy.special 5 | import time 6 | #import profilehooks 7 | 8 | from .Dabc_orig_m import Dabc_orig 9 | from .D_CV_orig_m import D_CV_orig 10 | #from .D_CV_orig_m import D_CV_orig as D_new 11 | from .D_SG_orig_m import D_SG_orig 12 | from .D_SG_orig_part_m import D_SG_orig_part 13 | from .factorial_precalc_m import factorial_precalc 14 | from .feature_extraction_m import feature_extraction 15 | #from .feature_extraction_m import feature_extraction as f_new 16 | from .geometric_moments_orig_m import geometric_moments_orig 17 | from .mon_comb_m import mon_comb 18 | from .Qklnu_m import Qklnu 19 | from .reformat_zernike_m import reformat_zernike 20 | from .trinomial_matrix_m import trinomial_matrix 21 | from .trinomial_m import trinomial 22 | from .Yljm_m import Yljm 23 | from .zernike_m import zernike 24 | from .zk_demo_m import zk_demo 25 | 26 | #from ..naive.feature_extraction_m import feature_extraction as f_old 27 | #from ..naive.D_CV_orig_m import D_CV_orig as D_old 28 | 29 | class CompatPipeline(object) : 30 | geometric_moments_orig = geometric_moments_orig 31 | trinomial_matrix = trinomial_matrix 32 | trinomial = trinomial 33 | D_CV_orig = D_CV_orig 34 | mon_comb = mon_comb 35 | Dabc_orig = Dabc_orig 36 | D_SG_orig = D_SG_orig 37 | D_SG_orig_part = D_SG_orig_part 38 | factorial_precalc = factorial_precalc 39 | Yljm = Yljm 40 | Qklnu = Qklnu 41 | zernike = zernike 42 | feature_extraction = feature_extraction 43 | 44 | pi = numpy.pi 45 | NaN = numpy.NaN 46 | 47 | def __init__(self) : 48 | self.tic_time = None 49 | 50 | #def feature_extraction(self,*args,**dargs) : 51 | # #return f_old(*args,**dargs) 52 | # return f_new(self,*args,**dargs) 53 | #def D_CV_orig(self,*args,**dargs) : 54 | # #return D_old(*args,**dargs) 55 | # return D_new(self,*args,**dargs) 56 | def display(self,astring,*args) : 57 | if len(args) > 0 : astring = astring.format(*args) 58 | print astring 59 | def zeros(self,*args,**dargs) : return numpy.zeros(args,**dargs) 60 | def rng(self,*args) : 61 | if len(args) == 1 : return range(args[0]+1) 62 | elif len(args) == 2 : return range(args[0],args[1]+1) 63 | elif len(args) == 3 : return range(args[0],args[1]+1,args[2]) 64 | else : raise Exception() 65 | def factorial(self,*args,**dargs) : return scipy.special.factorial(*args,**dargs) 66 | def tic(self) : 67 | self.tic_time = time.time() 68 | def toc(self) : 69 | if self.tic_time is None : raise Exception() 70 | t = self.tic_time 71 | self.tic_time = None 72 | return time.time() - t 73 | def mod(self,*args,**dargs) : return numpy.mod(*args,**dargs) 74 | # def array(self,obj,**dargs) : return numpy.array(obj,**dargs) 75 | def power(self,*args,**dargs) : return numpy.power(*args,**dargs) 76 | def det(self,*args,**dargs) : return numpy.linalg.det(*args,**dargs) 77 | def cat(self,axis,*args) : 78 | assert len(args) >= 2 79 | ndim = args[0].ndim 80 | assert all([ a.ndim == ndim for a in args]) 81 | if axis >= ndim : args = tuple([ numpy.expand_dims(a,axis) for a in args ]) 82 | return numpy.concatenate(args,axis=axis) 83 | def sqrt(self,*args,**dargs) : return scipy.sqrt(*args,**dargs) 84 | def nchoosek(self,*args,**dargs) : return scipy.special.comb(*args,**dargs) 85 | def floor(self,*args,**dargs) : return numpy.floor(*args,**dargs).astype(int) 86 | def conj(self,*args,**dargs) : return numpy.conj(*args,**dargs) 87 | def sum(self,*args,**dargs) : return numpy.sum(*args,**dargs) 88 | def real(self,*args,**dargs) : return numpy.real(*args,**dargs) 89 | def imag(self,*args,**dargs) : return numpy.imag(*args,**dargs) 90 | def norm(self,arr,ord=None) : 91 | if ord is not None : return numpy.linalg.norm(arr,ord=ord) 92 | return numpy.linalg.norm(arr) 93 | def rot90(self,arr,k) : 94 | if len(arr.shape) == 1 and k == 2 : return numpy.flipud(arr) 95 | else : raise NotImplementedError() 96 | def find(self,bool_arr) : return bool_arr 97 | def size(self,arr,dim=None) : 98 | if dim is None : return arr.shape 99 | else : return arr.shape[dim] 100 | # @profilehooks.profile(filename='demo.prfl') 101 | def demo(self,V,F,ZMvtk) : return zk_demo(self,V,F,ZMvtk) 102 | 103 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/factorial_precalc_m.py: -------------------------------------------------------------------------------- 1 | def factorial_precalc(cfg,N) : #function F = factorial_precalc(N) 2 | # 3 | F = cfg.zeros(N+3) 4 | for i in cfg.rng(1,N) : #for i = 1:N 5 | # 6 | for j in cfg.rng(0,N-i) : # for j=0:(N-i) 7 | for k in cfg.rng(0,N-i-j) : # for k=0:(N-i-j) 8 | # 9 | F[i] = cfg.factorial(i) #! # F(i + 1) = factorial(i); 10 | F[j] = cfg.factorial(j) #! # F(j + 1) = factorial(j); 11 | F[k] = cfg.factorial(k) #! # F(k + 1) = factorial(k); 12 | F[i+j+k+2] = cfg.factorial(i+j+k+2) #! # F(i+j+k+2 + 1) = factorial(i+j+k+2); 13 | # 14 | # end 15 | # end 16 | #end 17 | return F 18 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/feature_extraction_m.py: -------------------------------------------------------------------------------- 1 | def feature_extraction(cfg,Z,N) : #function Descriptors=feature_extraction(Z,N) 2 | # 3 | #% The features are the magnitude of the Zernike moments. 4 | #% Collect the moments into (2*l+1)-dimensional vectors 5 | #% and define the rotationally invariant 3D Zernike descriptors 6 | #% Fnl as norms of vectors Znl. 7 | # 8 | F=cfg.zeros(N+1,N+1)+cfg.NaN #F=zeros(N+1,N+1)+NaN; 9 | #% Calcuate the magnitude 10 | for n in cfg.rng(0,N) : #for n=0:N 11 | for l in cfg.rng(0,n) : # for l=0:n 12 | if cfg.mod(n-l,2)==0 : # if mod(n-l,2)==0 13 | aux_1=Z[n,l,0:(l+1)] #! # aux_1=Z(n+1,l+1,1:l+1); 14 | #! matlab col-major; no need to transpose # aux_1=aux_1(:)'; 15 | if l > 0 : # if l>0 16 | # % Taking the values for m<0 17 | aux_2=cfg.conj(aux_1[1:(l+1)]) #! # aux_2=conj(aux_1(2:(l+1))); 18 | for m in cfg.rng(1,l) : # for m=1:l 19 | aux_2[m-1]=aux_2[m-1]*cfg.power(-1,m) #! # aux_2(m)=aux_2(m)*power(-1,m); 20 | # end 21 | # % Sorting the vector 22 | aux_2=cfg.rot90(aux_2,2) # aux_2=rot90(aux_2,2); 23 | aux_1=cfg.cat(0,aux_2,aux_1) #! axis # aux_1=cat(2,aux_2,aux_1); 24 | # end 25 | F[n,l] = cfg.norm(aux_1,2) #! # F(n+1,l+1)=norm(aux_1,2); 26 | # end 27 | # end 28 | #end 29 | #% Generate vector of Zernike descriptors 30 | #% Column vector that store the magnitude 31 | #% of the Zernike moments for n,l. 32 | F = F.transpose() #! matlab indexin is col-wise. tranpose does not affect the values, just their ordering 33 | idx=cfg.find(F>=0) #idx=find(F>=0); 34 | Descriptors = F[idx] #Descriptors=F(idx); 35 | return Descriptors 36 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/geometric_moments_orig_m.py: -------------------------------------------------------------------------------- 1 | def geometric_moments_orig(cfg,X,K,N,num_facets,num_vertices) : #function G=geometric_moments_orig(X,K,N,num_facets,num_vertices) 2 | #% Computes the geometric moments 3 | #% of the volumetric object given 4 | # 5 | #% PRE-COMPUTATIONS 6 | cfg.display('Trinomial') #display('Trinomial') 7 | #% Matrix to store the pre-computed trinomial 8 | tri_matrix=cfg.trinomial_matrix(N) #tri_matrix=trinomial_matrix(N); 9 | #% Volume of each tetrahedra 10 | Vol=cfg.zeros(num_facets,1) #Vol=zeros(num_facets,1); 11 | #% Matrix that stored the monomial combinations 12 | C_temp=cfg.zeros(num_vertices,N+1,N+1,N+1) #%C_temp=zeros(num_vertices,N+1,N+1,N+1); 13 | #%keyboard 14 | #%size(C) 15 | # 16 | cfg.display('Dabc_orig') #display('Dabc_orig') 17 | #%matlabpool close 18 | #%matlabpool local 8 19 | D=cfg.zeros(num_facets,N+1,N+1,N+1) #D=zeros(num_facets,N+1,N+1,N+1); 20 | C1=cfg.zeros(num_facets,N+1,N+1,N+1) #C1=zeros(num_facets,N+1,N+1,N+1); 21 | for facet in cfg.rng(1,num_facets) : #for facet=1:num_facets 22 | # % pre-compute D 23 | cfg.tic() # tic 24 | if cfg.mod(facet,1000) == 0 : # if mod(facet,1000) == 0 25 | cfg.display('Facet: {} of {}',facet,num_facets) # display(['Facet: ' num2str(facet) ' of ' num2str(num_facets)]) 26 | # end 27 | C_temp, Vol_temp = cfg.D_CV_orig(facet,num_vertices,N,X,K,tri_matrix) # [C_temp Vol_temp] = D_CV_orig(facet,num_vertices,N,X,K,tri_matrix); 28 | D[facet-1,:,:,:] = cfg.Dabc_orig(C_temp,N) #! # D(facet,:,:,:)=Dabc_orig(C_temp,N); 29 | C1[facet-1,:,:,:] = C_temp[0,:,:,:] #! # C1(facet,:,:,:) = C_temp(1,:,:,:); 30 | Vol[facet-1,0] = Vol_temp #! # Vol(facet,1) = Vol_temp; 31 | if cfg.mod(facet,1000) == 0 : # if mod(facet,1000) == 0 32 | cfg.display('Computed facet: {} in {} seconds',facet,cfg.toc()) # display(['Computed facet: ' num2str(facet) ' in ' num2str(toc) 'seconds']) 33 | # end 34 | #end 35 | #clear C_temp Vol_temp 36 | # 37 | cfg.display('D_SG_orig') #display('D_SG_orig') 38 | #%matlabpool close 39 | #%matlabpool local 8 40 | #% GEOMETRIC MOMENTS; 41 | F = cfg.factorial_precalc(N) #F = factorial_precalc(N); 42 | G = cfg.zeros(N+1,N+1,N+1) #G=zeros(N+1,N+1,N+1); 43 | for i in cfg.rng(0,N) : #for i=0:N 44 | cfg.tic() # tic 45 | cfg.display('Order: {} of {}',i,N) # display(['Order: ' num2str(i) ' of ' num2str(N)]) 46 | G[i,:,:] = cfg.D_SG_orig(num_facets,i,N,C1,D,Vol,F) #! # G(i+1,:,:)=D_SG_orig(num_facets,i,N,C1,D,Vol,F); 47 | cfg.display('Computed Order {} in {} seconds',i,cfg.toc()) # display(['Computed Order ' num2str(i) ' in ' num2str(toc) 'seconds']) 48 | #end 49 | return G 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/mon_comb_m.py: -------------------------------------------------------------------------------- 1 | def mon_comb(cfg,tri_matrix,vertex,N) : #function c=mon_comb(tri_matrix,vertex,N) 2 | #% Computes the value for a specified monomial 3 | #% combination for a given vertex 4 | # 5 | #% Vertex coordinates 6 | x = vertex[0] #! #x=vertex(1); 7 | y = vertex[1] #! #y=vertex(2); 8 | z = vertex[2] #! #z=vertex(3); 9 | #% Computation 10 | c=cfg.zeros(N+1,N+1,N+1) #c=zeros(N+1,N+1,N+1); 11 | for i in cfg.rng(0,N) : #for i=0:N 12 | for j in cfg.rng(0,N-i) : # for j=0:(N-i) 13 | for k in cfg.rng(0,N-i-j) : # for k=0:(N-i-j) 14 | mon=cfg.power(x,i)*cfg.power(y,j)*cfg.power(z,k) # mon=power(x,i)*power(y,j)*power(z,k); 15 | c[i,j,k] = tri_matrix[i,j,k]*mon #! # c(i+1,j+1,k+1)=tri_matrix(i+1,j+1,k+1)*mon; 16 | # end 17 | # end 18 | #end 19 | return c 20 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/reformat_zernike_m.py: -------------------------------------------------------------------------------- 1 | def reformat_zernike(cfg,Z,N) : #function ZM = reformat_zernike(Z,N) 2 | # 3 | coord = cfg.load_coord() #load coord; 4 | # 5 | ZM = [] #ZM = []; 6 | for c in cfg.rng(coord,1) : #for c = 1:size(coord,1); 7 | # 8 | # 9 | if coord[c,1]+1 <= N+1 : # if coord(c,1)+1 <= N+1; 10 | ZM[c,1] = Z[coord[c,1]+1,coord[c,2]+1,coord[c,3]+1] # ZM(c,1) = Z(coord(c,1)+1,coord(c,2)+1,coord(c,3)+1); 11 | else : # else 12 | break # break 13 | # end 14 | #end 15 | return ZM 16 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/test.py: -------------------------------------------------------------------------------- 1 | import mindboggle.guts 2 | import numpy 3 | import os.path 4 | import scipy.io 5 | import glob 6 | import functools 7 | 8 | from . import CompatPipeline 9 | 10 | def read_vtk(filename): 11 | points, indices, lines, faces, depths, scalar_names, npoints, \ 12 | input_vtk = mindboggle.mio.vtks.read_vtk(filename) 13 | return numpy.array(points), numpy.array(faces) 14 | 15 | head,tail = os.path.split(__file__) 16 | DATA_DIR = os.path.join(head,'test_data') 17 | ALLOWED_ERROR = 1e-8 18 | 19 | FNS_AND_ARGS = [ #('D_CV_orig', ('facet','num_vertices','N','X','K','tri_matrix',), ('C','Vol',) ), 20 | #('trinomial', ('i','j','k',), ('t',) ), 21 | #('trinomial_matrix', ('N',), ('tri_matrix',) ), 22 | #('mon_comb', ('tri_matrix','vertex','N',), ('c',) ), 23 | #('D_SG_orig_part', ('num_facets','i','j','k','C','D','S','Vol','F',), ('S',) ), 24 | #('D_SG_orig', ('num_facets','i','N','C','D','Vol','F',), ('G',) ), 25 | ('Dabc_orig', ('C','N',), ('D',) ), #slow 26 | #('factorial_precalc', ('N',), ('F',) ), 27 | #('Yljm', ('l','j','m',), ('y',) ), 28 | #('Qklnu', ('k','l','nu',), ('q',) ), 29 | #('zernike', ('G','N',), ('Z',) ), 30 | #('feature_extraction', ('Z','N',), ('Descriptors',) ), 31 | #('geometric_moments_orig', ('X','K','N','num_facets','num_vertices',), ('G',) ), #slow 32 | #('demo', ('V','F','ZMvtk'), ('Descriptors',) ), 33 | #('reformat_zernike', ('Z','N',), ('ZM,') ), 34 | ] 35 | 36 | def test() : 37 | pl = CompatPipeline() 38 | for fnname, inargs, outargs in FNS_AND_ARGS : 39 | globname = '{}-*.mat'.format(fnname) 40 | fn = getattr(pl,fnname) 41 | files = sorted( glob.glob( os.path.join(DATA_DIR,globname) ) ) 42 | if len(files) == 0 : raise Exception(globname) 43 | for filename in files : 44 | p = functools.partial(run, fn, filename, inargs, outargs) 45 | p.description = filename 46 | yield (p, ) 47 | 48 | def run(fn,filename,inarg_names,outarg_names) : 49 | matfile = scipy.io.loadmat( filename,squeeze_me=True ) 50 | inargs = tuple([ matfile[a] for a in inarg_names ]) 51 | outargs = tuple([ matfile[a] for a in outarg_names ]) 52 | new_outargs = fn(*inargs) 53 | if not isinstance(new_outargs,tuple) : new_outargs = tuple([new_outargs]) 54 | for n,a,aa in zip(outarg_names, outargs, new_outargs) : 55 | if isinstance(a,numpy.ndarray) and isinstance(aa,numpy.ndarray) : assert a.shape == aa.shape, 'Output {}: {} != {}'.format(n,a.shape,aa.shape) 56 | err_max = numpy.max( numpy.abs( a-aa ) ) 57 | assert err_max < ALLOWED_ERROR, 'Output {}: Error ({}) > ALLOWED_ERROR ({})'.format(n,err_max, ALLOWED_ERROR) 58 | #assert a.dtype == aa.dtype, '{} != {}'.format(a.dtype,aa.dtype) 59 | 60 | 61 | 62 | ''' 63 | def test__geometric_moments() : 64 | matfile = scipy.io.loadmat( os.path.join(DATA_DIR,'geometric_moments_orig-0.mat') ) 65 | X,K,N,num_facets,num_vertices = matfile['X'], matfile['K'], matfile['N'], matfile['num_facets'], matfile['num_vertices'] 66 | pl = CompatPipeline() 67 | X,K = pl.array(X), pl.array(K) 68 | GG = pl.geometric_moments_orig(X,K,N,num_facets,num_vertices) 69 | 70 | def test__Dabc_orig() : 71 | for filename in glob.glob( os.path.join(DATA_DIR,'Dabc_orig-*.mat' ) ) : yield run__Dabc_orig, filename 72 | 73 | def run__Dabc_orig(filename) : 74 | matfile = scipy.io.loadmat( filename ) 75 | C,N,D = matfile['C'], matfile['N'], matfile['D'] 76 | pl = CompatPipeline() 77 | DD = pl.Dabc_orig(C,N) 78 | assert DD.dtype == D.dtype, 'dtype' 79 | assert DD.shape == D.shape, 'shape' 80 | assert numpy.max( numpy.abs( D-DD ) ) < ALLOWED_ERROR, 81 | 82 | def test__mon_comb() : 83 | for filename in glob.glob( os.path.join(DATA_DIR,'mon_comb-*.mat' ) ) : yield run__mon_comb, filename 84 | ''' 85 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/trinomial_m.py: -------------------------------------------------------------------------------- 1 | def trinomial(cfg,i,j,k) : #function t=trinomial(i,j,k) 2 | #% Computes the trinomial of 3 | #% the three input arguments 4 | # 5 | aux_1=cfg.factorial(i+j+k) #aux_1=factorial(i+j+k); 6 | aux_2=cfg.factorial(i)*cfg.factorial(j)*cfg.factorial(k) #aux_2=factorial(i)*factorial(j)*factorial(k); 7 | t = aux_1/aux_2 #t= aux_1/aux_2; 8 | # 9 | return t 10 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/trinomial_matrix_m.py: -------------------------------------------------------------------------------- 1 | def trinomial_matrix(cfg,N) : #function tri_matrix=trinomial_matrix(N) 2 | #% Computes the trinomial of 3 | #% the three input arguments 4 | # 5 | tri_matrix=cfg.zeros(N+1,N+1,N+1) #tri_matrix=zeros(N+1,N+1,N+1); 6 | for i in cfg.rng(0,N) : #for i=0:N 7 | for j in cfg.rng(0,N-i) : # for j=0:(N-i) 8 | for k in cfg.rng(0,N-i-j) : # for k=0:(N-i-j) 9 | tri_matrix[i,j,k] = cfg.trinomial(i,j,k) #! # tri_matrix(i+1,j+1,k+1)=trinomial(i,j,k); 10 | # end 11 | # end 12 | #end 13 | return tri_matrix 14 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/compat/zk_demo_m.py: -------------------------------------------------------------------------------- 1 | def zk_demo(cfg,V,F,ZMvtk) : #function max_abs_diff = demo( V,F,ZMvtk ) 2 | # 3 | num_vertices = 3 # num_vertices = 3; 4 | num_facets = cfg.size(F,0) #! # num_facets = size(F,1); 5 | N = 20 # N = 20; %code will only work upto order 20 (can be fixed later) 6 | # 7 | # % ZERNIKE MOMENTS 8 | G = cfg.geometric_moments_orig(V,F,N,num_facets,num_vertices) # G=geometric_moments_orig(V,F,N,num_facets,num_vertices); 9 | Z = cfg.zernike(G,N) # Z=zernike(G,N); 10 | Descriptors = cfg.feature_extraction(Z,N) # Descriptors=feature_extraction(Z,N); 11 | # ZM= reformat_zernike(Z,N); 12 | # 13 | # %compare to your code 14 | # max_abs_diff = max(abs(abs(ZM) - abs(ZMvtk))); %error should be around 1e-8 15 | return Descriptors 16 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/D_CV_orig_m.py: -------------------------------------------------------------------------------- 1 | def D_CV_orig(cfg,facet,num_vertices,N,X,K,tri_matrix) : #function [C,Vol] = D_CV_orig(facet,num_vertices,N,X,K,tri_matrix) 2 | # 3 | C = cfg.zeros(num_vertices,N+1,N+1,N+1) #C=zeros(num_vertices,N+1,N+1,N+1); 4 | # 5 | # % Vertex 1 6 | # % Monomial combinations for each vertex in a given facet 7 | vertex_1=X[K[facet-1,0],:] #! facet is 1-indexed # vertex_1=X(K(facet,1),:); 8 | # % Vertex 9 | vx = vertex_1[0] #! # vx=vertex_1(1); 10 | vy = vertex_1[1] #! # vy=vertex_1(2); 11 | vz = vertex_1[2] #! # vz=vertex_1(3); 12 | C[0,:,:,:]=cfg.mon_comb(tri_matrix,[vx,vy,vz],N) #! # C(1,:,:,:)=mon_comb(tri_matrix,[vx vy vz],N); 13 | # 14 | # % Vertex 2 15 | # % Monomial combinations for each vertex in a given facet 16 | vertex_2=X[K[facet-1,1],:] #! # vertex_2=X(K(facet,2),:); 17 | # % Vertex 18 | vx=vertex_2[0] #! # vx=vertex_2(1); 19 | vy=vertex_2[1] #! # vy=vertex_2(2); 20 | vz=vertex_2[2] #! # vz=vertex_2(3); 21 | C[1,:,:,:]=cfg.mon_comb(tri_matrix,[vx,vy,vz],N) #! # C(2,:,:,:)=mon_comb(tri_matrix,[vx vy vz],N); 22 | # 23 | # % Vertex 1 24 | # % Monomial combinations for each vertex in a given facet 25 | vertex_3=X[K[facet-1,2],:] #! # vertex_3=X(K(facet,3),:); 26 | # % Vertex 27 | vx=vertex_3[0] #! # vx=vertex_3(1); 28 | vy=vertex_3[1] #! # vy=vertex_3(2); 29 | vz=vertex_3[2] #! # vz=vertex_3(3); 30 | C[2,:,:,:]=cfg.mon_comb(tri_matrix,[vx,vy,vz],N) #! # C(3,:,:,:)=mon_comb(tri_matrix,[vx vy vz],N); 31 | # %Calculate Volume 32 | Vol=cfg.det(cfg.cat(1,vertex_1,vertex_2,vertex_3)) #!axis # Vol=det(cat(2,vertex_1',vertex_2',vertex_3')); 33 | return C,Vol 34 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/D_SG_orig_m.py: -------------------------------------------------------------------------------- 1 | def D_SG_orig(cfg,num_facets,i,N,C,D,Vol,F) : #function G = D_SG_orig(num_facets,i,N,C,D,Vol,F) 2 | # 3 | G=cfg.zeros(N+1,N+1) #G=zeros(N+1,N+1); 4 | S=cfg.zeros(num_facets,N+1,N+1,N+1) #S=zeros(num_facets,N+1,N+1,N+1); 5 | # 6 | for j in cfg.rng(0,N-i) : #for j=0:(N-i) 7 | for k in cfg.rng(0,N-i-j) : # for k=0:(N-i-j) 8 | # 9 | S = cfg.D_SG_orig_part(num_facets,i,j,k,C,D,S,Vol,F) # S = D_SG_orig_part(num_facets,i,j,k,C,D,S,Vol,F); 10 | # % Geometric moments after summing through all facets 11 | G[j,k]=cfg.sum(S[:,i,j,k]) #! # G(j+1,k+1)=sum(S(:,i+1,j+1,k+1)); 12 | # end 13 | #end 14 | return G 15 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/D_SG_orig_part_m.py: -------------------------------------------------------------------------------- 1 | def D_SG_orig_part(cfg,num_facets,i,j,k,C,D,S,Vol,F) : #function S = D_SG_orig_part(num_facets,i,j,k,C,D,S,Vol,F) 2 | # 3 | for facet in cfg.rng(0,num_facets-1) : #! #for facet=1:num_facets 4 | # % Sijk for a given facet 5 | # 6 | # 7 | # %aux_1 = factorial(i)*factorial(j)*factorial(k); 8 | # %aux_2 = factorial(i+j+k+2); 9 | # 10 | aux_1 = F[i]*F[j]*F[k] #! # aux_1 = F(i + 1)*F(j + 1)*F(k + 1); 11 | aux_2 = F[i+j+k+2] #! # aux_2 = F(i+j+k+2 + 1); 12 | aux = aux_1/aux_2 # aux=aux_1/aux_2; 13 | # 14 | tmp=0 # tmp=0; 15 | for i1 in cfg.rng(0,i) : # for i1=0:i 16 | for j1 in cfg.rng(0,j) : # for j1=0:j 17 | for k1 in cfg.rng(0,k) : # for k1=0:k 18 | tmp = tmp + (C[facet,i1,j1,k1]*D[facet,i-i1,j-j1,k-k1]) #! # tmp=tmp+(C(facet,i1+1,j1+1,k1+1)*D(facet,i-i1+1,j-j1+1,k-k1+1)); 19 | # end 20 | # end 21 | # end 22 | tmp = tmp*aux # tmp=tmp*aux; 23 | # 24 | S[facet,i,j,k]=(Vol[facet]*tmp)/(i+j+k+3) #! # S(facet,i+1,j+1,k+1)=(Vol(facet)*tmp)/(i+j+k+3); 25 | #end 26 | return S 27 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/Dabc_orig_m.py: -------------------------------------------------------------------------------- 1 | #import profilehooks 2 | import numpy 3 | import numpy.random 4 | import sys 5 | import time 6 | import itertools 7 | 8 | 9 | def itertools_product(cfg,C,N) : 10 | D = cfg.zeros(N+1,N+1,N+1) 11 | for a,b,c in cfg.rng_prod((0,N),repeat=3 ) : 12 | temp = 0 13 | for i2,j2,k2 in cfg.rng_prod((0,a),(0,b),(0,c)) : 14 | temp += C[1,i2,j2,k2]*C[2,a-i2,b-j2,c-k2] #! 15 | D[a,b,c] = temp #! 16 | return D 17 | 18 | 19 | #@profilehooks.timecall(immediate=True) 20 | def orig(cfg,C,N) : #function D=Dabc_orig(C,N) 21 | #% Pre-computes the values for D 22 | #% and store them in matrix form 23 | #% to be used for Geometric Moments 24 | # 25 | #f = file('orig.indx','a') 26 | D = cfg.zeros(N+1,N+1,N+1) #D = zeros(N+1,N+1,N+1); 27 | for a in cfg.rng(0,N) : #for a=0:N 28 | for b in cfg.rng(0,N) : # for b=0:N 29 | for c in cfg.rng(0,N) : # for c=0:N 30 | temp = 0 # temp=0; 31 | for i2 in cfg.rng(0,a) : # for i2=0:a 32 | for j2 in cfg.rng(0,b) : # for j2=0:b 33 | for k2 in cfg.rng(0,c) : # for k2=0: 34 | #f.write('{} {} {} {} {} {}\n'.format(a,b,c,i2,j2,k2)) 35 | temp += C[1,i2,j2,k2]*C[2,a-i2,b-j2,c-k2] #! # temp=temp+C(2,i2+1,j2+1,k2+1)*C(3,a-i2+1,b-j2+1,c-k2+1); 36 | # end 37 | # end 38 | # end 39 | D[a,b,c] = temp #! # D(a+1,b+1,c+1)=temp; 40 | # end 41 | # end 42 | #end 43 | return D 44 | 45 | 46 | def generate_indices(N) : 47 | a,b,c,i2,j2,k2 = numpy.mgrid[0:N+1,0:N+1,0:N+1,0:N+1,0:N+1,0:N+1] 48 | mask = (i2 <= a) & ( j2 <= b ) & ( k2 <= c ) 49 | return a,b,c,i2,j2,k2,mask 50 | 51 | 52 | def simple(cfg,C,N) : 53 | a,b,c,i2,j2,k2,mask = generate_indices(N) 54 | C1, C2 = C[1,i2,j2,k2], C[2,a-i2,b-j2,c-k2] 55 | D = C1*C2 56 | D[~mask] = 0.0 57 | return numpy.sum(D,axis=(3,4,5)) 58 | 59 | 60 | def nd_reversed(C) : return C[::-1,::-1,::-1] 61 | 62 | 63 | def iter_rev_sum(cfg,C,N) : 64 | C1, C2 = C[1,:,:,:], C[2,:,:,:] 65 | D = numpy.zeros_like(C1) 66 | for a,b,c in cfg.rng_prod((0,N),repeat=3) : 67 | c1 = C1[:a+1,:b+1,:c+1] 68 | c2 = nd_reversed(C2[:a+1,:b+1,:c+1]) 69 | D[a,b,c] = numpy.sum(c1*c2) 70 | return D 71 | 72 | 73 | # @profilehooks.profile(filename='Dabc_orig.prfl') 74 | # def test_profile() : 75 | # from . import MultiprocPipeline as Pipeline 76 | # N = 20 77 | # C = numpy.random.rand(N+1,N+1,N+1,N+1) 78 | # pl = Pipeline() 79 | # #vec = vectorized(pl,C,N) 80 | # #foo = itertools_product(pl,C,N) 81 | # sv = sumversion(pl,C,N) 82 | # o = orig(pl,C,N) 83 | # print numpy.max(numpy.abs(sv-o)) 84 | # #assert numpy.all(vec == o) 85 | # #assert numpy.all(foo == o) 86 | # assert numpy.all(sv == o) 87 | 88 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/Qklnu_m.py: -------------------------------------------------------------------------------- 1 | def Qklnu(cfg,k,l,nu) : #function q=Qklnu(k,l,nu) 2 | # 3 | #% Computes Q, neccesary constant#% Computes Q, neccesary constant 4 | #% for the moments computation#% for the moments computation 5 | # 6 | aux_1=cfg.power(-1,k+nu)/cfg.power(4.0,k) #aux_1=power(-1,k+nu)/power(4,k) 7 | aux_2=cfg.sqrt((2*l+4*k+3)/3.0) #aux_2=sqrt((2*l+4*k+3)/3) 8 | aux_3=cfg.trinomial(nu,k-nu,l+nu+1)*cfg.nchoosek(2*(l+nu+1+k),l+nu+1+k) #aux_3=trinomial(nu,k-nu,l+nu+1)*nchoosek(2*(l+nu+1+k),l+nu+1+k) 9 | aux_4=cfg.nchoosek(2.0*(l+nu+1),l+nu+1) #aux_4=nchoosek(2*(l+nu+1),l+nu+1) 10 | q=(aux_1*aux_2*aux_3)/aux_4 #q=(aux_1*aux_2*aux_3)/aux_4 11 | return q 12 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/Yljm_m.py: -------------------------------------------------------------------------------- 1 | def Yljm(cfg,l,j,m) : #function y=Yljm(l,j,m) 2 | # 3 | #% Computes a constant used in Zernike moments 4 | # 5 | aux_1=cfg.power(-1,j)*(cfg.sqrt(2*l+1)/cfg.power(2,l)) #aux_1=power(-1,j)*(sqrt(2*l+1)/power(2,l)); 6 | aux_2=cfg.trinomial(m,j,l-m-2*j)*cfg.nchoosek(2*(l-j),l-j) #aux_2=trinomial(m,j,l-m-2*j)*nchoosek(2*(l-j),l-j); 7 | aux_3=cfg.sqrt(cfg.trinomial(m,m,l-m)) #aux_3=sqrt(trinomial(m,m,l-m)); 8 | y=(aux_1*aux_2)/aux_3 #y=(aux_1*aux_2)/aux_3; 9 | return y 10 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/__init__.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import numpy.linalg 3 | import scipy 4 | import scipy.special 5 | import time 6 | #import profilehooks 7 | import copy_reg 8 | import types 9 | import itertools 10 | 11 | from .Dabc_orig_m import iter_rev_sum as Dabc_orig 12 | from .D_CV_orig_m import D_CV_orig 13 | from .D_SG_orig_m import D_SG_orig 14 | from .D_SG_orig_part_m import D_SG_orig_part 15 | from .factorial_precalc_m import factorial_precalc 16 | from .feature_extraction_m import feature_extraction 17 | from .geometric_moments_orig_m import mproc as geometric_moments_orig 18 | from .mon_comb_m import mon_comb 19 | from .Qklnu_m import Qklnu 20 | from .reformat_zernike_m import reformat_zernike 21 | from .trinomial_matrix_m import trinomial_matrix 22 | from .trinomial_m import trinomial 23 | from .Yljm_m import Yljm 24 | from .zernike_m import zernike 25 | from .zk_demo_m import zk_demo 26 | 27 | class MultiprocPipeline(object) : 28 | geometric_moments_orig = geometric_moments_orig 29 | trinomial_matrix = trinomial_matrix 30 | trinomial = trinomial 31 | D_CV_orig = D_CV_orig 32 | mon_comb = mon_comb 33 | #Dabc_orig = Dabc_orig 34 | D_SG_orig = D_SG_orig 35 | D_SG_orig_part = D_SG_orig_part 36 | factorial_precalc = factorial_precalc 37 | Yljm = Yljm 38 | Qklnu = Qklnu 39 | zernike = zernike 40 | feature_extraction = feature_extraction 41 | 42 | pi = numpy.pi 43 | NaN = numpy.NaN 44 | 45 | def __init__(self) : 46 | self.tic_time = None 47 | 48 | def Dabc_orig(*args,**dargs) : return Dabc_orig(*args,**dargs) # you have to do this for "import ... as ..." functions that are run asynch 49 | def display(self,astring,*args) : 50 | if len(args) > 0 : astring = astring.format(*args) 51 | print(astring) 52 | def zeros(self,*args,**dargs) : return numpy.zeros(args,**dargs) 53 | def rng(self,*args) : 54 | if len(args) == 1 : return range(args[0]+1) 55 | elif len(args) == 2 : return range(args[0],args[1]+1) 56 | elif len(args) == 3 : return range(args[0],args[1]+1,args[2]) 57 | else : raise Exception() 58 | def rng_prod(self,*args,**dargs) : 59 | args = tuple([ self.rng(*a) for a in args ]) 60 | return itertools.product(*args,**dargs) 61 | def factorial(self,*args,**dargs) : return scipy.special.factorial(*args,**dargs) 62 | def tic(self) : 63 | self.tic_time = time.time() 64 | def toc(self) : 65 | if self.tic_time is None : raise Exception() 66 | t = self.tic_time 67 | self.tic_time = None 68 | return time.time() - t 69 | def mod(self,*args,**dargs) : return numpy.mod(*args,**dargs) 70 | def power(self,*args,**dargs) : return numpy.power(*args,**dargs) 71 | def det(self,*args,**dargs) : return numpy.linalg.det(*args,**dargs) 72 | def cat(self,axis,*args) : 73 | assert len(args) >= 2 74 | ndim = args[0].ndim 75 | assert all([ a.ndim == ndim for a in args]) 76 | if axis >= ndim : args = tuple([ numpy.expand_dims(a,axis) for a in args ]) 77 | return numpy.concatenate(args,axis=axis) 78 | def sqrt(self,*args,**dargs) : return scipy.sqrt(*args,**dargs) 79 | def nchoosek(self,*args,**dargs) : return scipy.special.comb(*args,**dargs) 80 | def floor(self,*args,**dargs) : return numpy.floor(*args,**dargs).astype(int) 81 | def conj(self,*args,**dargs) : return numpy.conj(*args,**dargs) 82 | def sum(self,*args,**dargs) : return numpy.sum(*args,**dargs) 83 | def real(self,*args,**dargs) : return numpy.real(*args,**dargs) 84 | def imag(self,*args,**dargs) : return numpy.imag(*args,**dargs) 85 | def norm(self,arr,ord=None) : 86 | if ord is not None : return numpy.linalg.norm(arr,ord=ord) 87 | return numpy.linalg.norm(arr) 88 | def rot90(self,arr,k) : 89 | if len(arr.shape) == 1 and k == 2 : return numpy.flipud(arr) 90 | else : raise NotImplementedError() 91 | def find(self,bool_arr) : return bool_arr 92 | def size(self,arr,dim=None) : 93 | if dim is None : return arr.shape 94 | else : return arr.shape[dim] 95 | #@profilehooks.profile(filename='demo.prfl') 96 | def demo(self,V,F,ZMvtk) : return zk_demo(self,V,F,ZMvtk) 97 | 98 | 99 | def unpickle_method(func_name, obj, cls): 100 | for cls in cls.mro(): 101 | try : func = cls.__dict__[func_name] 102 | except KeyError : pass 103 | else : break 104 | return func.__get__(obj, cls) 105 | 106 | 107 | def pickle_method(method): 108 | func_name = method.im_func.__name__ 109 | obj = method.im_self 110 | cls = method.im_class 111 | return unpickle_method, (func_name, obj, cls) 112 | 113 | 114 | copy_reg.pickle(types.MethodType, pickle_method, unpickle_method) 115 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/factorial_precalc_m.py: -------------------------------------------------------------------------------- 1 | def factorial_precalc(cfg,N) : #function F = factorial_precalc(N) 2 | # 3 | F = cfg.zeros(N+3) 4 | for i in cfg.rng(1,N) : #for i = 1:N 5 | # 6 | for j in cfg.rng(0,N-i) : # for j=0:(N-i) 7 | for k in cfg.rng(0,N-i-j) : # for k=0:(N-i-j) 8 | # 9 | F[i] = cfg.factorial(i) #! # F(i + 1) = factorial(i); 10 | F[j] = cfg.factorial(j) #! # F(j + 1) = factorial(j); 11 | F[k] = cfg.factorial(k) #! # F(k + 1) = factorial(k); 12 | F[i+j+k+2] = cfg.factorial(i+j+k+2) #! # F(i+j+k+2 + 1) = factorial(i+j+k+2); 13 | # 14 | # end 15 | # end 16 | #end 17 | return F 18 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/feature_extraction_m.py: -------------------------------------------------------------------------------- 1 | def feature_extraction(cfg,Z,N) : #function Descriptors=feature_extraction(Z,N) 2 | # 3 | #% The features are the magnitude of the Zernike moments. 4 | #% Collect the moments into (2*l+1)-dimensional vectors 5 | #% and define the rotationally invariant 3D Zernike descriptors 6 | #% Fnl as norms of vectors Znl. 7 | # 8 | F=cfg.zeros(N+1,N+1)+cfg.NaN #F=zeros(N+1,N+1)+NaN; 9 | #% Calcuate the magnitude 10 | for n in cfg.rng(0,N) : #for n=0:N 11 | for l in cfg.rng(0,n) : # for l=0:n 12 | if cfg.mod(n-l,2)==0 : # if mod(n-l,2)==0 13 | aux_1=Z[n,l,0:(l+1)] #! # aux_1=Z(n+1,l+1,1:l+1); 14 | #! matlab col-major; no need to transpose # aux_1=aux_1(:)'; 15 | if l > 0 : # if l>0 16 | # % Taking the values for m<0 17 | aux_2=cfg.conj(aux_1[1:(l+1)]) #! # aux_2=conj(aux_1(2:(l+1))); 18 | for m in cfg.rng(1,l) : # for m=1:l 19 | aux_2[m-1]=aux_2[m-1]*cfg.power(-1,m) #! # aux_2(m)=aux_2(m)*power(-1,m); 20 | # end 21 | # % Sorting the vector 22 | aux_2=cfg.rot90(aux_2,2) # aux_2=rot90(aux_2,2); 23 | aux_1=cfg.cat(0,aux_2,aux_1) #! axis # aux_1=cat(2,aux_2,aux_1); 24 | # end 25 | F[n,l] = cfg.norm(aux_1,2) #! # F(n+1,l+1)=norm(aux_1,2); 26 | # end 27 | # end 28 | #end 29 | #% Generate vector of Zernike descriptors 30 | #% Column vector that store the magnitude 31 | #% of the Zernike moments for n,l. 32 | F = F.transpose() #! matlab indexin is col-wise. tranpose does not affect the values, just their ordering 33 | idx=cfg.find(F>=0) #idx=find(F>=0); 34 | Descriptors = F[idx] #Descriptors=F(idx); 35 | return Descriptors 36 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/mon_comb_m.py: -------------------------------------------------------------------------------- 1 | def mon_comb(cfg,tri_matrix,vertex,N) : #function c=mon_comb(tri_matrix,vertex,N) 2 | #% Computes the value for a specified monomial 3 | #% combination for a given vertex 4 | # 5 | #% Vertex coordinates 6 | x = vertex[0] #! #x=vertex(1); 7 | y = vertex[1] #! #y=vertex(2); 8 | z = vertex[2] #! #z=vertex(3); 9 | #% Computation 10 | c=cfg.zeros(N+1,N+1,N+1) #c=zeros(N+1,N+1,N+1); 11 | for i in cfg.rng(0,N) : #for i=0:N 12 | for j in cfg.rng(0,N-i) : # for j=0:(N-i) 13 | for k in cfg.rng(0,N-i-j) : # for k=0:(N-i-j) 14 | mon=cfg.power(x,i)*cfg.power(y,j)*cfg.power(z,k) # mon=power(x,i)*power(y,j)*power(z,k); 15 | c[i,j,k] = tri_matrix[i,j,k]*mon #! # c(i+1,j+1,k+1)=tri_matrix(i+1,j+1,k+1)*mon; 16 | # end 17 | # end 18 | #end 19 | return c 20 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/reformat_zernike_m.py: -------------------------------------------------------------------------------- 1 | def reformat_zernike(cfg,Z,N) : #function ZM = reformat_zernike(Z,N) 2 | # 3 | coord = cfg.load_coord() #load coord; 4 | # 5 | ZM = [] #ZM = []; 6 | for c in cfg.rng(coord,1) : #for c = 1:size(coord,1); 7 | # 8 | # 9 | if coord[c,1]+1 <= N+1 : # if coord(c,1)+1 <= N+1; 10 | ZM[c,1] = Z[coord[c,1]+1,coord[c,2]+1,coord[c,3]+1] # ZM(c,1) = Z(coord(c,1)+1,coord(c,2)+1,coord(c,3)+1); 11 | else : # else 12 | break # break 13 | # end 14 | #end 15 | return ZM 16 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/test.py: -------------------------------------------------------------------------------- 1 | import mindboggle.guts 2 | import numpy 3 | import os.path 4 | import scipy.io 5 | import glob 6 | import functools 7 | 8 | from . import MultiprocPipeline as Pipeline 9 | 10 | def read_vtk(filename) : 11 | points, indices, lines, faces, depths, scalar_names, npoints, input_vtk = mindboggle.mio.vtks.read_vtk(filename) 12 | return numpy.array(points), numpy.array(faces) 13 | 14 | head,tail = os.path.split(__file__) 15 | DATA_DIR = os.path.join(head,'test_data') 16 | ALLOWED_ERROR = 1e-8 17 | 18 | FNS_AND_ARGS = [ #('D_CV_orig', ('facet','num_vertices','N','X','K','tri_matrix',), ('C','Vol',) ), 19 | #('trinomial', ('i','j','k',), ('t',) ), 20 | #('trinomial_matrix', ('N',), ('tri_matrix',) ), 21 | #('mon_comb', ('tri_matrix','vertex','N',), ('c',) ), 22 | #('D_SG_orig_part', ('num_facets','i','j','k','C','D','S','Vol','F',), ('S',) ), 23 | #('D_SG_orig', ('num_facets','i','N','C','D','Vol','F',), ('G',) ), 24 | #('Dabc_orig', ('C','N',), ('D',) ), #slow 25 | #('factorial_precalc', ('N',), ('F',) ), 26 | #('Yljm', ('l','j','m',), ('y',) ), 27 | #('Qklnu', ('k','l','nu',), ('q',) ), 28 | #('zernike', ('G','N',), ('Z',) ), 29 | #('feature_extraction', ('Z','N',), ('Descriptors',) ), 30 | #('geometric_moments_orig', ('X','K','N','num_facets','num_vertices',), ('G',) ), #slow 31 | ('demo', ('V','F','ZMvtk'), ('Descriptors',) ), 32 | #('reformat_zernike', ('Z','N',), ('ZM,') ), 33 | ] 34 | 35 | def test() : 36 | pl = Pipeline() 37 | for fnname, inargs, outargs in FNS_AND_ARGS : 38 | globname = '{}-*.mat'.format(fnname) 39 | fn = getattr(pl,fnname) 40 | files = sorted( glob.glob( os.path.join(DATA_DIR,globname) ) ) 41 | if len(files) == 0 : raise Exception(globname) 42 | for filename in files : 43 | p = functools.partial(run, fn, filename, inargs, outargs) 44 | p.description = filename 45 | yield (p, ) 46 | 47 | def run(fn,filename,inarg_names,outarg_names) : 48 | matfile = scipy.io.loadmat( filename,squeeze_me=True ) 49 | inargs = tuple([ matfile[a] for a in inarg_names ]) 50 | outargs = tuple([ matfile[a] for a in outarg_names ]) 51 | new_outargs = fn(*inargs) 52 | if not isinstance(new_outargs,tuple) : new_outargs = tuple([new_outargs]) 53 | for n,a,aa in zip(outarg_names, outargs, new_outargs) : 54 | if isinstance(a,numpy.ndarray) and isinstance(aa,numpy.ndarray) : assert a.shape == aa.shape, 'Output {}: {} != {}'.format(n,a.shape,aa.shape) 55 | err_max = numpy.max( numpy.abs( a-aa ) ) 56 | assert err_max < ALLOWED_ERROR, 'Output {}: Error ({}) > ALLOWED_ERROR ({})'.format(n,err_max, ALLOWED_ERROR) 57 | #assert a.dtype == aa.dtype, '{} != {}'.format(a.dtype,aa.dtype) 58 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/trinomial_m.py: -------------------------------------------------------------------------------- 1 | def trinomial(cfg,i,j,k) : #function t=trinomial(i,j,k) 2 | #% Computes the trinomial of 3 | #% the three input arguments 4 | # 5 | aux_1=cfg.factorial(i+j+k) #aux_1=factorial(i+j+k); 6 | aux_2=cfg.factorial(i)*cfg.factorial(j)*cfg.factorial(k) #aux_2=factorial(i)*factorial(j)*factorial(k); 7 | t = aux_1/aux_2 #t= aux_1/aux_2; 8 | # 9 | return t 10 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/trinomial_matrix_m.py: -------------------------------------------------------------------------------- 1 | def trinomial_matrix(cfg,N) : #function tri_matrix=trinomial_matrix(N) 2 | #% Computes the trinomial of 3 | #% the three input arguments 4 | # 5 | tri_matrix=cfg.zeros(N+1,N+1,N+1) #tri_matrix=zeros(N+1,N+1,N+1); 6 | for i in cfg.rng(0,N) : #for i=0:N 7 | for j in cfg.rng(0,N-i) : # for j=0:(N-i) 8 | for k in cfg.rng(0,N-i-j) : # for k=0:(N-i-j) 9 | tri_matrix[i,j,k] = cfg.trinomial(i,j,k) #! # tri_matrix(i+1,j+1,k+1)=trinomial(i,j,k); 10 | # end 11 | # end 12 | #end 13 | return tri_matrix 14 | -------------------------------------------------------------------------------- /mindboggle/x/test_zernike/multiproc/zk_demo_m.py: -------------------------------------------------------------------------------- 1 | def zk_demo(cfg,V,F,ZMvtk) : #function max_abs_diff = demo( V,F,ZMvtk ) 2 | # 3 | num_vertices = 3 # num_vertices = 3; 4 | num_facets = cfg.size(F,0) #! # num_facets = size(F,1); 5 | N = 20 # N = 20; %code will only work upto order 20 (can be fixed later) 6 | # 7 | # % ZERNIKE MOMENTS 8 | G = cfg.geometric_moments_orig(V,F,N,num_facets,num_vertices) # G=geometric_moments_orig(V,F,N,num_facets,num_vertices); 9 | Z = cfg.zernike(G,N) # Z=zernike(G,N); 10 | Descriptors = cfg.feature_extraction(Z,N) # Descriptors=feature_extraction(Z,N); 11 | # ZM= reformat_zernike(Z,N); 12 | # 13 | # %compare to your code 14 | # max_abs_diff = max(abs(abs(ZM) - abs(ZMvtk))); %error should be around 1e-8 15 | return Descriptors 16 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- 3 | # vi: set ft=python sts=4 ts=4 sw=4 et: 4 | """ 5 | Mindboggle: package for automated human brain image labeling and morphometry. 6 | 7 | """ 8 | 9 | import os 10 | import sys 11 | from os.path import join as pjoin 12 | 13 | # BEFORE importing distguts, remove MANIFEST. distguts doesn't properly 14 | # update it when the contents of directories change. 15 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') 16 | 17 | # For some commands, use setuptools. 18 | if len(set(('develop', 'bdist_egg', 'bdist_rpm', 'bdist', 'bdist_dumb', 19 | 'bdist_wininst', 'install_egg_info', 'egg_info', 'easy_install', 20 | )).intersection(sys.argv)) > 0: 21 | pass 22 | from distutils.core import setup 23 | 24 | # Get version and release info, which is all stored in info.py 25 | ver_file = pjoin(os.getcwd(), 'info.py') 26 | exec(open(ver_file).read()) 27 | 28 | def main(**extra_args): 29 | setup(name=NAME, 30 | maintainer=MAINTAINER, 31 | maintainer_email=MAINTAINER_EMAIL, 32 | description=DESCRIPTION, 33 | long_description=LONG_DESCRIPTION, 34 | url=URL, 35 | download_url=DOWNLOAD_URL, 36 | license=LICENSE, 37 | classifiers=CLASSIFIERS, 38 | author=AUTHOR, 39 | author_email=AUTHOR_EMAIL, 40 | platforms=PLATFORMS, 41 | version=VERSION, 42 | requires=REQUIRES, 43 | provides=PROVIDES, 44 | packages=['mindboggle', 45 | 'mindboggle.data', 46 | 'mindboggle.evaluate', 47 | 'mindboggle.features', 48 | 'mindboggle.guts', 49 | 'mindboggle.mio', 50 | 'mindboggle.shapes', 51 | 'mindboggle.shapes.zernike', 52 | 'mindboggle.thirdparty'], 53 | package_data={'mindboggle': [pjoin('data', '*.nii.gz'), 54 | pjoin('data', '*.txt')]}, 55 | scripts=[pjoin('mindboggle', 'mindboggle'), 56 | pjoin('mindboggle', 'mindboggle123'), 57 | pjoin('colors_script', 'calc_colormap.py'), 58 | pjoin('colors_script', 'convert_to_mipav_lut.py')], 59 | **extra_args 60 | ) 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /vtk_cpp_tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # http://www.vtk.org/Wiki/VTK/Tutorials/CMakeListsFile 2 | cmake_minimum_required(VERSION 3.0) 3 | project(mindboggle_surfaces) 4 | ## Rather than set the VTK_DIR, compile with 5 | ## "cmake .. -DVTK_DIR:STRING=/Users/arno/anaconda/lib/cmake/vtk-7.0" 6 | #set(VTK_DIR "/Users/arno/anaconda/lib/cmake/vtk-7.0") 7 | #find_package(VTK REQUIRED NO_MODULE) 8 | find_package(VTK 8.1 COMPONENTS vtkInteractionStyle vtkRenderingFreeType vtkRenderingOpenGL2 vtkRenderingVolumeOpenGL2 vtkIOLegacy vtkIOMINC vtkIOGeometry vtkImagingStencil vtkImagingMorphological vtkFiltersModeling NO_MODULE) 9 | include(${VTK_USE_FILE}) 10 | 11 | #if(COMMAND CMAKE_POLICY) 12 | # CMAKE_POLICY(SET CMP0003 NEW) 13 | #endif(COMMAND CMAKE_POLICY) 14 | 15 | # David Gobbi on vtkusers mailing list: 16 | # For building a binary package to share with others, 17 | # set to a reasonably old deployment target (e.g. 10.7) and SDK (e.g. 10.9): 18 | #set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7") 19 | #set(CMAKE_OSX_SYSROOT "macosx10.9") 20 | 21 | add_subdirectory( 22 | travel_depth 23 | ) 24 | 25 | add_subdirectory( 26 | curvature 27 | ) 28 | 29 | add_subdirectory( 30 | surface_overlap 31 | ) 32 | 33 | add_subdirectory( 34 | area 35 | ) 36 | 37 | add_subdirectory( 38 | gradient 39 | ) 40 | 41 | add_subdirectory( 42 | geodesic_depth 43 | ) 44 | 45 | #add_subdirectory( 46 | #medial_surfaces 47 | #) 48 | 49 | add_library( 50 | MeshAnalyser MeshAnalyser.cpp 51 | ) 52 | install(TARGETS MeshAnalyser 53 | LIBRARY DESTINATION lib 54 | ARCHIVE DESTINATION lib) 55 | 56 | add_library( 57 | FsSurfaceReader FsSurfaceReader.cpp 58 | ) 59 | 60 | add_library( 61 | VtkFileEditor VtkFileEditor.cpp 62 | ) 63 | 64 | add_library( 65 | TravelDepth TravelDepth.cpp 66 | ) 67 | 68 | add_library( 69 | Overlap Overlap.cpp 70 | ) 71 | 72 | add_library( 73 | GradientComputer GradientComputer.cpp 74 | ) 75 | 76 | add_library( 77 | PointAreaComputer PointAreaComputer.cpp 78 | ) 79 | 80 | target_link_libraries( 81 | MeshAnalyser 82 | ) 83 | 84 | target_link_libraries( 85 | TravelDepth 86 | ) 87 | 88 | target_link_libraries( 89 | GradientComputer 90 | ) 91 | 92 | target_link_libraries( 93 | Overlap 94 | PointAreaComputer 95 | ) 96 | -------------------------------------------------------------------------------- /vtk_cpp_tools/FsSurfaceReader.cpp: -------------------------------------------------------------------------------- 1 | /* ******************************************************************** 2 | * FsSurfaceReader 3 | * 4 | * Copyright 2011 Joachim Giard 5 | * Université catholique de Louvain, Belgium 6 | * Apache License, Version 2.0 7 | * 8 | * Class containing methods to read a freesurfer mesh file and to 9 | * convert it to vtk data. 10 | * 11 | * *******************************************************************/ 12 | 13 | #include "FsSurfaceReader.h" 14 | 15 | 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | 26 | //using namespace std; 27 | 28 | FsSurfaceReader::FsSurfaceReader(char *fileName) 29 | { 30 | ifstream myfile; 31 | myfile.open (fileName, ios::in | ios::binary); 32 | 33 | vtkPolyData* pd = vtkPolyData::New(); 34 | 35 | int fileIdType = readInt3(myfile); 36 | 37 | std::string creator = readTo2eol(myfile); 38 | 39 | unsigned char tmp[4]; 40 | int x; 41 | 42 | m_mesh = vtkPolyData::New(); 43 | 44 | myfile.read((char*)tmp, 4); 45 | x = (((int)(tmp[0])) << 24) | 46 | (((int)(tmp[1])) << 16) | 47 | (((int)(tmp[2])) << 8) | 48 | (int)tmp[3]; 49 | int vertexCount = x; 50 | cout<<"vertex count "<InsertNextPoint(pos); 76 | } 77 | 78 | cout<<"points Inserted"<PrintSelf(cout, indent); 83 | 84 | pd->SetPoints(points); 85 | 86 | vtkCellArray* cells = vtkCellArray::New(); 87 | for(int i = 0 ; iInsertNextId(x); 97 | } 98 | 99 | cells->InsertNextCell(pointList); 100 | 101 | } 102 | 103 | cout<<"faces Inserted"<PrintSelf(cout, indent); 106 | 107 | 108 | pd->SetPolys(cells); 109 | 110 | // VTK6 migration: http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Removal_of_Update 111 | // pd->Update(); 112 | 113 | cout<PrintSelf(cout,indent); 116 | 117 | vtkPolyDataNormals *pdn = vtkPolyDataNormals::New(); 118 | pdn->SetInputData(pd); 119 | pdn->SetFeatureAngle(90); 120 | pdn->SplittingOff(); 121 | 122 | // VTK6 migration: http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Removal_of_Update 123 | // pd->Update(); 124 | 125 | cout<GetOutput()->PrintSelf(cout,indent); 128 | 129 | m_mesh->DeepCopy(pdn->GetOutput()); 130 | 131 | // vtkPolyDataWriter* pdw = vtkPolyDataWriter::New(); 132 | // pdw->SetInputData(m_mesh); 133 | // pdw->SetFileName("test.vtk"); 134 | // pdw->Write(); 135 | // pdw->Update(); 136 | // pdw->Delete(); 137 | 138 | cells->Delete(); 139 | pdn->Delete(); 140 | points->Delete(); 141 | 142 | } 143 | 144 | FsSurfaceReader::~FsSurfaceReader() 145 | { 146 | m_mesh->Delete(); 147 | } 148 | 149 | 150 | vtkPolyData* FsSurfaceReader::GetVTKData() 151 | { 152 | return m_mesh; 153 | } 154 | 155 | int FsSurfaceReader::readInt3(ifstream &myfile) 156 | { 157 | unsigned char tmp[4]; 158 | int x; 159 | myfile.read((char*)tmp, 3); 160 | x = (((int)(tmp[0])) << 16) | 161 | (((int)(tmp[1])) << 8) | 162 | (int)tmp[2]; 163 | // cout<<"File Type Id "< 17 | 18 | #include 19 | #include 20 | 21 | using namespace std; 22 | 23 | class FsSurfaceReader 24 | { 25 | public: 26 | 27 | //constructor and destructor 28 | FsSurfaceReader(char* fileName); 29 | ~FsSurfaceReader(); 30 | 31 | vtkPolyData* GetVTKData(); 32 | 33 | private: 34 | 35 | vtkPolyData* m_mesh; 36 | int readInt3(ifstream &myfile); 37 | std::string readTo2eol(ifstream &myfile); 38 | 39 | }; 40 | 41 | 42 | #endif // FS_SURFACE_READER_H_ 43 | -------------------------------------------------------------------------------- /vtk_cpp_tools/GradientComputer.cpp: -------------------------------------------------------------------------------- 1 | /* ******************************************************************** 2 | * Gradient Computer 3 | * 4 | * Copyright 2013 Joachim Giard 5 | * Université catholique de Louvain, Belgium 6 | * Apache License, Version 2.0 7 | * 8 | * Class containing various methods to compute gradients of a scalar 9 | * field on a mesh 10 | * 11 | * *******************************************************************/ 12 | 13 | #include "GradientComputer.h" 14 | 15 | #include "PointAreaComputer.h" 16 | 17 | #include "MeshAnalyser.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using namespace std; 29 | 30 | GradientComputer::GradientComputer(vtkPolyData *mesh) 31 | { 32 | m_mesh = mesh; 33 | 34 | vtkPolyDataNormals *pdn = vtkPolyDataNormals::New(); 35 | pdn->SetInputData(m_mesh); 36 | pdn->SetFeatureAngle(90); 37 | pdn->SplittingOff(); 38 | pdn->Update(); 39 | 40 | // VTK6 migration: http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Removal_of_Update 41 | // Old: vtkPolyData* nor = pdn->GetOutput(); nor->Update(); 42 | // m_normals = nor->GetPointData()->GetNormals(); 43 | pdn->Update(); 44 | m_normals = pdn->GetOutput()->GetPointData()->GetNormals(); 45 | 46 | 47 | m_gradientValueArray = vtkDoubleArray::New(); 48 | m_steepestDescentArray = vtkDoubleArray::New(); 49 | m_steepestDescentArray->SetNumberOfComponents(3); 50 | } 51 | 52 | 53 | GradientComputer::~GradientComputer() 54 | { 55 | m_gradientValueArray->Delete(); 56 | m_steepestDescentArray->Delete(); 57 | } 58 | 59 | void GradientComputer::WriteIntoFile(char *fileName) 60 | { 61 | MeshAnalyser* ma = new MeshAnalyser(m_mesh); 62 | ma->WriteIntoFile(fileName,m_gradientValueArray); 63 | delete ma; 64 | } 65 | 66 | void GradientComputer::ComputeGradient() 67 | { 68 | vtkDataArray* scalarField = m_mesh->GetPointData()->GetScalars(); 69 | ComputeGradient(scalarField); 70 | } 71 | 72 | void GradientComputer::ComputeGradient(vtkDataArray *scalar) 73 | { 74 | PointAreaComputer* pac = new PointAreaComputer(m_mesh); 75 | pac->ComputeArea(); 76 | vtkDoubleArray* pointArea = pac->GetArea(); 77 | double point[3]; 78 | double neigPoint[3]; 79 | double projNeigPoint[3]; 80 | double normal[3]; 81 | 82 | double scalarDiff; 83 | double gradientValue; 84 | 85 | double steepestDescent[3]; 86 | double totalNeigArea; 87 | 88 | int neigId; 89 | 90 | vtkIdList* neig = vtkIdList::New(); 91 | 92 | for(int i =0; iGetNumberOfPoints();i++) 93 | { 94 | GetPointNeighbors(i,neig); 95 | m_mesh->GetPoint(i,point); 96 | m_normals->GetTuple(i,normal); 97 | 98 | totalNeigArea = 0; 99 | for(int k=0; k<3; k++) 100 | { 101 | steepestDescent[k] = 0; 102 | } 103 | 104 | for(int j=0; jGetNumberOfIds(); j++) 105 | { 106 | neigId = neig->GetId(j); 107 | m_mesh->GetPoint(neigId, neigPoint); 108 | ProjectPointToPlane(neigPoint,point,normal,projNeigPoint); 109 | totalNeigArea += pointArea->GetValue(neigId); 110 | scalarDiff = scalar->GetTuple1(neigId)-scalar->GetTuple1(i); 111 | 112 | for(int k=0; k<3; k++) 113 | { 114 | steepestDescent[k] += pointArea->GetValue(neigId) 115 | * (projNeigPoint[k] - point[k]) 116 | * scalarDiff; 117 | } 118 | } 119 | for(int k=0; k<3; k++) 120 | { 121 | steepestDescent[k] /= totalNeigArea; 122 | } 123 | m_steepestDescentArray->InsertNextTuple(steepestDescent); 124 | gradientValue = vtkMath::Norm(steepestDescent); 125 | m_gradientValueArray->InsertNextValue(gradientValue); 126 | } 127 | 128 | } 129 | 130 | void GradientComputer::ProjectPointToPlane(double *pointToProject, double *inPlanePoint, double *normal, double *projectedPoint) 131 | { 132 | double relativePoint[3]; 133 | for(int k =0; k<3 ; k++) 134 | { 135 | relativePoint[k] = pointToProject[k] - inPlanePoint[k]; 136 | } 137 | 138 | double dotProd = vtkMath::Dot(relativePoint, normal)/vtkMath::Norm(normal); 139 | 140 | for(int k =0; k<3 ; k++) 141 | { 142 | projectedPoint[k] = pointToProject[k] - dotProd * normal[k]; 143 | } 144 | 145 | } 146 | 147 | void GradientComputer::GetPointNeighbors(vtkIdType id, vtkIdList* neighbors) 148 | { 149 | vtkIdList *cellids = vtkIdList::New(); 150 | m_mesh->GetPointCells(id,cellids); 151 | neighbors->Reset(); 152 | for (int i = 0; i < cellids->GetNumberOfIds(); i++) 153 | { 154 | for(int j = 0; j < m_mesh->GetCell(cellids->GetId(i))->GetNumberOfPoints(); j++) 155 | { 156 | if(m_mesh->GetCell(cellids->GetId(i))->GetPointId(j)GetNumberOfPoints()) 157 | { 158 | neighbors->InsertUniqueId(m_mesh->GetCell(cellids->GetId(i))->GetPointId(j)); 159 | } 160 | } 161 | } 162 | cellids->Delete(); 163 | } 164 | -------------------------------------------------------------------------------- /vtk_cpp_tools/GradientComputer.h: -------------------------------------------------------------------------------- 1 | /* ******************************************************************** 2 | * Gradient Computer 3 | * 4 | * Copyright 2013 Joachim Giard 5 | * Université catholique de Louvain, Belgium 6 | * Apache License, Version 2.0 7 | * 8 | * Class containing various methods to compute gradients of a scalar 9 | * field on a mesh 10 | * 11 | * *******************************************************************/ 12 | 13 | #ifndef GRADIENTCOMPUTER_H 14 | #define GRADIENTCOMPUTER_H 15 | 16 | #include 17 | 18 | class GradientComputer 19 | { 20 | public: 21 | // Constructor. 22 | GradientComputer(vtkPolyData* mesh); 23 | 24 | // destructor 25 | ~GradientComputer(); 26 | 27 | void WriteIntoFile(char* fileName); 28 | 29 | void ComputeGradient(); 30 | void ComputeGradient(vtkDataArray* scalar); 31 | 32 | private: 33 | 34 | void ProjectPointToPlane(double* pointToProject, double* inPlanePoint, double* normal, double* projectedPoint); 35 | void GetPointNeighbors(vtkIdType id, vtkIdList *neighbors); 36 | 37 | vtkDoubleArray* m_pointsArea; 38 | vtkPolyData* m_mesh; 39 | vtkDataArray* m_normals; 40 | vtkDoubleArray* m_gradientValueArray; 41 | vtkDoubleArray* m_steepestDescentArray; 42 | 43 | }; 44 | 45 | #endif // GRADIENTCOMPUTER_H 46 | -------------------------------------------------------------------------------- /vtk_cpp_tools/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2009 Joachim Giard, Université catholique de Louvain, Belgium 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | -------------------------------------------------------------------------------- /vtk_cpp_tools/Overlap.cpp: -------------------------------------------------------------------------------- 1 | /* ******************************************************************** 2 | * Overlap 3 | * 4 | * Copyright 2012 Joachim Giard 5 | * Université catholique de Louvain, Belgium 6 | * Apache License, Version 2.0 7 | * 8 | * Class containing various methods to compute overlaps 9 | * between pairs of labels 10 | * 11 | * *******************************************************************/ 12 | 13 | #include "Overlap.h" 14 | 15 | #include "PointAreaComputer.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | using namespace std; 26 | 27 | Overlap::Overlap(vtkPolyData *mesh1, vtkPolyData *mesh2) 28 | { 29 | m_pointsArea = vtkDoubleArray::New(); 30 | m_labels1Areas = vtkDoubleArray::New(); 31 | m_labels2Areas = vtkDoubleArray::New(); 32 | m_labelsCommonAreas = vtkDoubleArray::New(); 33 | 34 | m_jaccard = vtkDoubleArray::New(); 35 | m_dice = vtkDoubleArray::New(); 36 | 37 | m_mesh1 = mesh1; 38 | m_mesh2 = mesh2; 39 | 40 | m_maxLabel = 0; 41 | } 42 | 43 | Overlap::~Overlap() 44 | { 45 | m_pointsArea->Delete(); 46 | m_labels1Areas->Delete(); 47 | m_labels2Areas->Delete(); 48 | m_labelsCommonAreas->Delete(); 49 | } 50 | 51 | void Overlap::ComputeOverlap() 52 | { 53 | // ComputePointsArea(); 54 | 55 | PointAreaComputer* areaComputer = new PointAreaComputer(m_mesh1); 56 | areaComputer->ComputeArea(); 57 | m_pointsArea = areaComputer->GetArea(); 58 | 59 | int cLabel1, cLabel2; 60 | double cArea1, cArea2, cAreaC; 61 | double iArea; 62 | double dice, jaccard; 63 | 64 | vtkDataArray* labels1 = m_mesh1->GetPointData()->GetScalars(); 65 | vtkDataArray* labels2 = m_mesh2->GetPointData()->GetScalars(); 66 | 67 | for(int i = 0; iGetNumberOfPoints(); i++) 68 | { 69 | // cout<GetValue(i)<<" "<GetTuple1(i)<<" "<GetTuple1(i)<GetTuple1(i)) 71 | { 72 | m_maxLabel = labels1->GetTuple1(i); 73 | } 74 | if(m_maxLabel < labels2->GetTuple1(i)) 75 | { 76 | m_maxLabel = labels2->GetTuple1(i); 77 | } 78 | } 79 | 80 | for(int i = 0; iInsertNextValue(0); 83 | m_labels2Areas->InsertNextValue(0); 84 | m_labelsCommonAreas->InsertNextValue(0); 85 | } 86 | 87 | for(int i = 0; iGetNumberOfPoints(); i++) 88 | { 89 | cLabel1 = labels1->GetTuple1(i); 90 | cLabel2 = labels2->GetTuple1(i); 91 | 92 | cArea1 = m_labels1Areas->GetValue(cLabel1); 93 | cArea2 = m_labels2Areas->GetValue(cLabel2); 94 | 95 | iArea = m_pointsArea->GetValue(i); 96 | 97 | 98 | m_labels1Areas->SetValue(cLabel1, cArea1 + iArea); 99 | m_labels2Areas->SetValue(cLabel2, cArea2 + iArea); 100 | 101 | if(cLabel1 == cLabel2) 102 | { 103 | cAreaC = m_labelsCommonAreas->GetValue(cLabel1); 104 | m_labelsCommonAreas->SetValue(cLabel1, cAreaC + iArea); 105 | } 106 | } 107 | 108 | cout<<"Label Dice Jaccard Common Area1 Area2"<GetValue(i); 113 | cArea1 = m_labels1Areas->GetValue(i); 114 | cArea2 = m_labels2Areas->GetValue(i); 115 | 116 | if(cAreaC > 0) 117 | { 118 | dice = cAreaC / ( (cArea1 + cArea2 ) / 2.0 ); 119 | jaccard = cAreaC / (cArea1 + cArea2 - cAreaC); 120 | } 121 | else 122 | { 123 | dice = 0; 124 | jaccard = 0; 125 | } 126 | 127 | m_dice->InsertNextValue(dice); 128 | m_jaccard->InsertNextValue(jaccard); 129 | if(m_labels1Areas->GetValue(i) > 0 || m_labels2Areas->GetValue(i) > 0 ) 130 | { 131 | cout<GetValue(i)<<" "<< m_labels1Areas->GetValue(i)<<" "<< m_labels2Areas->GetValue(i)<GetValue(i) > 0 || m_labels2Areas->GetValue(i) > 0 ) 148 | { 149 | myfile <GetValue(i)<<" " 151 | <GetValue(i)<<" " 152 | << m_labelsCommonAreas->GetValue(i)<<" " 153 | << m_labels1Areas->GetValue(i)<<" " 154 | << m_labels2Areas->GetValue(i)< 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | PointAreaComputer::PointAreaComputer(vtkPolyData *mesh) 24 | { 25 | m_mesh = mesh; 26 | m_pointsArea = vtkDoubleArray::New(); 27 | } 28 | 29 | PointAreaComputer::~PointAreaComputer() 30 | { 31 | m_pointsArea->Delete(); 32 | } 33 | 34 | void PointAreaComputer::ComputeArea() 35 | { 36 | m_pointsArea = ComputeVoronoiArea(); 37 | } 38 | 39 | vtkDoubleArray* PointAreaComputer::GetArea() 40 | { 41 | return m_pointsArea; 42 | } 43 | 44 | void PointAreaComputer::WriteIntoFile(char *fileName) 45 | { 46 | vtkPolyDataWriter* writer=vtkPolyDataWriter::New(); 47 | writer->SetFileName(fileName); 48 | m_mesh->GetPointData()->SetScalars(m_pointsArea); 49 | writer->SetInputData(m_mesh); 50 | writer->Write(); 51 | writer->Delete(); 52 | } 53 | 54 | 55 | vtkDoubleArray* PointAreaComputer::ComputeVoronoiArea() 56 | { 57 | // initialisation 58 | vtkCellArray* cells=m_mesh->GetPolys(); 59 | int nbPolys = cells->GetNumberOfCells(); 60 | vtkDoubleArray* pointsArea = vtkDoubleArray::New(); 61 | 62 | for(int i=0;iGetNumberOfPoints();i++) 63 | { 64 | pointsArea->InsertNextValue(0); 65 | } 66 | 67 | int cellIds[3]; 68 | 69 | double pos1[3]; 70 | double pos2[3]; 71 | double pos3[3]; 72 | 73 | float a; 74 | float b; 75 | float c; 76 | 77 | float alpha; 78 | float beta; 79 | float gamma; 80 | 81 | float area, areaA, areaB, areaC; 82 | 83 | bool obtuse = false; 84 | 85 | for (int i=0;iGetCell(i)->GetPointId(0); 88 | cellIds[1]=m_mesh->GetCell(i)->GetPointId(1); 89 | cellIds[2]=m_mesh->GetCell(i)->GetPointId(2); 90 | 91 | if(cellIds[0]>m_mesh->GetNumberOfPoints()||cellIds[1]>m_mesh->GetNumberOfPoints()||cellIds[2]>m_mesh->GetNumberOfPoints()) 92 | { 93 | cout<<"point surface cell id problem: "<GetPoint(cellIds[0],pos1); 98 | m_mesh->GetPoint(cellIds[1],pos2); 99 | m_mesh->GetPoint(cellIds[2],pos3); 100 | 101 | // distances between points of each triangle 102 | a=sqrt(vtkMath::Distance2BetweenPoints(pos3,pos2)); 103 | b=sqrt(vtkMath::Distance2BetweenPoints(pos1,pos3)); 104 | c=sqrt(vtkMath::Distance2BetweenPoints(pos2,pos1)); 105 | 106 | // set 1/3 areas to zero by default 107 | areaA = 0; 108 | areaB = 0; 109 | areaC = 0; 110 | 111 | // if distances greater than zero 112 | if(a>0 && b>0 && c>0) 113 | { 114 | // angles 115 | alpha = acos( (pow(b,2) + pow(c,2) - pow(a,2)) / (2*b*c) ); 116 | beta = acos( (pow(a,2) + pow(c,2) - pow(b,2)) / (2*a*c) ); 117 | gamma = acos( (pow(b,2) + pow(a,2) - pow(c,2)) / (2*b*a) ); 118 | 119 | // don't set 1/3 areas if angles are not numbers 120 | if( vtkMath::IsNan(alpha) || vtkMath::IsNan(beta) || vtkMath::IsNan(gamma) ) 121 | { 122 | } 123 | // else set 1/3 areas 124 | else 125 | { 126 | if( alpha > vtkMath::Pi()/2 || beta > vtkMath::Pi()/2 || gamma > vtkMath::Pi()/2 ) 127 | { 128 | // Herons's formula 129 | area = 0.25 * sqrt( (a+b+c)*(b+c-a)*(a-b+c)*(a+b-c) ); 130 | 131 | if(alpha > vtkMath::Pi()/2) 132 | { 133 | areaA = area/2; 134 | areaB = area/4; 135 | areaC = area/4; 136 | } 137 | else if (beta > vtkMath::Pi()/2) 138 | { 139 | areaA = area/4; 140 | areaB = area/2; 141 | areaC = area/4; 142 | } 143 | else if (gamma > vtkMath::Pi()/2) 144 | { 145 | areaA = area/4; 146 | areaB = area/4; 147 | areaC = area/2; 148 | } 149 | } 150 | else 151 | { 152 | areaA = (pow(b,2) / tan(beta) + pow(c,2) / tan(gamma)) /8; 153 | areaB = (pow(a,2) / tan(alpha) + pow(c,2) / tan(gamma)) /8; 154 | areaC = (pow(b,2) / tan(beta) + pow(a,2) / tan(alpha)) /8; 155 | } 156 | } 157 | } 158 | 159 | // add 1/3 of the face area to each point of the triangle 160 | pointsArea->SetValue(cellIds[0],pointsArea->GetValue(cellIds[0])+ areaA); 161 | pointsArea->SetValue(cellIds[1],pointsArea->GetValue(cellIds[1])+ areaB); 162 | pointsArea->SetValue(cellIds[2],pointsArea->GetValue(cellIds[2])+ areaC); 163 | } 164 | } 165 | 166 | return pointsArea; 167 | 168 | } 169 | 170 | 171 | -------------------------------------------------------------------------------- /vtk_cpp_tools/PointAreaComputer.h: -------------------------------------------------------------------------------- 1 | // ********************************************************* 2 | // Copyright (c) Universite catholique de Louvain. 3 | // All rights reserved 4 | // 5 | // Place du Levant, 2 6 | // 1348 Louvain-la-Neuve 7 | // Belgium 8 | // Tel : +32 10 47 23 00 9 | // 10 | // ********************************************************* 11 | 12 | #ifndef POINTAREACOMPUTER_H 13 | #define POINTAREACOMPUTER_H 14 | 15 | #include 16 | 17 | class PointAreaComputer 18 | { 19 | public: 20 | // Constructor. 21 | PointAreaComputer(vtkPolyData* mesh); 22 | // destructor 23 | ~PointAreaComputer(); 24 | 25 | //Compute the voronoi area of each point 26 | void ComputeArea(); 27 | 28 | vtkDoubleArray* GetArea(); 29 | 30 | void WriteIntoFile(char* fileName); 31 | 32 | private: 33 | vtkDoubleArray* ComputeVoronoiArea(); 34 | 35 | vtkDoubleArray* m_pointsArea; 36 | 37 | vtkPolyData* m_mesh; 38 | }; 39 | 40 | #endif // POINTAREACOMPUTER_H 41 | -------------------------------------------------------------------------------- /vtk_cpp_tools/TravelDepth.h: -------------------------------------------------------------------------------- 1 | // ********************************************************* 2 | // Copyright (c) Universite catholique de Louvain. 3 | // All rights reserved 4 | // 5 | // Place du Levant, 2 6 | // 1348 Louvain-la-Neuve 7 | // Belgium 8 | // Tel : +32 10 47 23 00 9 | // 10 | // ********************************************************* 11 | 12 | #ifndef TRAVELDEPTH_H 13 | #define TRAVELDEPTH_H 14 | 15 | #include "MeshAnalyser.h" 16 | 17 | class TravelDepth 18 | { 19 | public: 20 | TravelDepth(vtkPolyData* mesh); 21 | TravelDepth(char* fileName); 22 | ~TravelDepth(); 23 | 24 | void ComputeDepth(); 25 | 26 | vtkDoubleArray* GetDepth(); 27 | 28 | void WriteIntoFile(char* fileName); 29 | 30 | private: 31 | 32 | void Initialize(); 33 | 34 | void ComputeConvexHull(); 35 | void AffectDepthToVisiblePoints(); 36 | void DoublePropagationLoop(); 37 | 38 | void GeodesicPropagation(); 39 | void EuclideanPushPropagation(); 40 | void EuclideanPullPropagation(); 41 | void CompleteGeodesicPropagation(); 42 | 43 | void DecreaseReferenceSet(vtkIdList *changed); 44 | void RefillReferenceSet(); 45 | 46 | void ReachMaxConfidence(int i); 47 | 48 | void GetPointNeighbors(vtkIdType id, vtkIdList *neighbors); 49 | 50 | bool UpdateDepth(vtkIdType idParent, vtkIdType idChild, double valueDiff); 51 | void UpdateConfidence(vtkIdList* idsToCheck, vtkIdList* idsNotToUpdate); 52 | 53 | bool CheckIntersection(double x1, double y1, double z1, double x2, double y2, double z2); 54 | 55 | 56 | vtkDoubleArray* m_depth; 57 | vtkDoubleArray* m_normalizedDepth; 58 | 59 | vtkPolyData* m_mesh; 60 | vtkPolyData* m_hull; 61 | 62 | MeshAnalyser* m_meshAnalyser; 63 | 64 | vtkCellLocator *m_hullLocator; 65 | vtkCellLocator *m_meshLocator; 66 | vtkPointLocator *m_meshPointLocator; 67 | 68 | vtkDoubleArray* m_confidence; 69 | vtkIdList* m_lowConfidenceIds; 70 | vtkIdList* m_referenceIds; 71 | 72 | int m_maxIt; 73 | int m_maxConfidence; 74 | int m_maxBound; 75 | 76 | 77 | 78 | }; 79 | 80 | 81 | #endif // TRAVELDEPTH_H 82 | -------------------------------------------------------------------------------- /vtk_cpp_tools/VtkFileEditor.cpp: -------------------------------------------------------------------------------- 1 | /* ******************************************************************** 2 | * VtkFileEditor 3 | * 4 | * Copyright 2011 Joachim Giard 5 | * Université catholique de Louvain, Belgium 6 | * Apache License, Version 2.0 7 | * 8 | * Class containing methods to edit a vtk file 9 | * 10 | * *******************************************************************/ 11 | 12 | #include "VtkFileEditor.h" 13 | 14 | VtkFileEditor::VtkFileEditor(char *fileName) 15 | { 16 | m_inFile.open (fileName, ios::in); 17 | m_outFile.open (fileName, ios::out | ios::app); 18 | } 19 | 20 | 21 | VtkFileEditor::~VtkFileEditor() 22 | { 23 | m_inFile.close(); 24 | m_outFile.close(); 25 | } 26 | 27 | void VtkFileEditor::CreateField(char *fieldName, vtkDoubleArray *values) 28 | { 29 | m_outFile<GetNumberOfTuples() ; i++) 34 | { 35 | m_outFile<GetValue(i)< 16 | 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | class VtkFileEditor 23 | { 24 | public: 25 | //constructor and destructor 26 | VtkFileEditor(char* fileName); 27 | ~VtkFileEditor(); 28 | 29 | void CreateField(char* fieldName, vtkDoubleArray* values); 30 | 31 | private: 32 | ifstream m_inFile; 33 | ofstream m_outFile; 34 | 35 | }; 36 | 37 | #endif // VTKFILEEDITOR_H 38 | -------------------------------------------------------------------------------- /vtk_cpp_tools/area/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # Find VTK: 4 | find_package(VTK REQUIRED NO_MODULE) 5 | include(${VTK_USE_FILE}) 6 | 7 | # This project is designed to be built outside the Insight source tree: 8 | project(point_area) 9 | 10 | add_executable( 11 | PointAreaMain PointAreaMain.cpp 12 | ) 13 | install(TARGETS PointAreaMain 14 | RUNTIME DESTINATION bin) 15 | 16 | target_link_libraries( 17 | PointAreaMain 18 | MeshAnalyser 19 | PointAreaComputer 20 | ${VTK_LIBRARIES} 21 | ) 22 | -------------------------------------------------------------------------------- /vtk_cpp_tools/area/PointAreaMain.cpp: -------------------------------------------------------------------------------- 1 | #include "../PointAreaComputer.h" 2 | #include "../MeshAnalyser.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | template vtkPolyData *ReadObject(const char*fileName) 16 | { 17 | vtkSmartPointer reader = 18 | vtkSmartPointer::New(); 19 | reader->SetFileName(fileName); 20 | 21 | reader->Update(); 22 | reader->GetOutput()->Register(reader); 23 | return reader->GetOutput(); 24 | } 25 | 26 | void print_help() 27 | { 28 | printf( 29 | "Usage: PointAreaComputer InputVTKMesh\n" 30 | ); 31 | } 32 | 33 | int main(int argc, char** argv) 34 | { 35 | time_t start= time(NULL); 36 | vtkPolyData *dataSet; 37 | std::string extension = ".vtk"; 38 | //vtksys::SystemTools::GetFilenameLastExtension(argv[1]); 39 | if (extension == ".vtk") 40 | dataSet = ReadObject (argv[1]); 41 | else if (extension == ".obj") 42 | dataSet = ReadObject (argv[1]); 43 | else if (extension == ".stl") 44 | dataSet = ReadObject (argv[1]); 45 | 46 | 47 | PointAreaComputer* area = new PointAreaComputer(dataSet); 48 | area->ComputeArea(); 49 | area->WriteIntoFile(argv[2]); 50 | 51 | cout<<"Elapsed time (area): "< 4 | #include 5 | #include 6 | 7 | void print_help() 8 | { 9 | printf( 10 | "Usage: CurvatureMain [Options] InputVTKMesh MeanCurvatureOutput\n" 11 | "Options: \n" 12 | " -m Method: set the method used to compute curvature(s) (default 0)\n" 13 | " 0 -- Use ComputePrincipalCurvatures() function to compute both mean and Gaussian curvatures based on the relative direction of the normal vectors in a small neighborhood\n" 14 | " 1 -- Use ComputeBothCurvatures() function to compute both mean and Gaussian curvatures based on the local ratios between a filtered surface and the original surface area\n" 15 | " 2 -- Use ComputeCurvature() function to compute the mean curvature based on the direction of the displacement vectors during a Laplacian filtering\n" 16 | " -n Neighborhood: set the neighborhood size for computing curvature (default 0.7)\n" 17 | " -g GaussianCurvVTK: set the output file to save Gaussian curvature (no default)\n" 18 | " -x MaxCurvVTK: set the output file to save maximum curvature (no default)\n" 19 | " -i MinCurvVTK: set the output file to save minimum curvature (no default)\n" 20 | " -d DirectionVTK: set the output file to save minimal curvature's direction (no default)\n" 21 | "Example: CurvatureMain -m 0 -n 0.75 -i lh.min_curv.vtk -x lh.max_curv.vtk -g lh.gaussian_curv.vtk -d lh.min_dir.vtk lh.pial.vtk lh.mean_curv.vtk \n" 22 | ); 23 | } 24 | 25 | int main(int argc, char** argv) 26 | { 27 | cout<ComputeCurvature(NeighborhoodSize, 20); 120 | break; 121 | case 1: 122 | ma->ComputeBothCurvatures(NeighborhoodSize); 123 | break; 124 | default: // =0 125 | vtkDoubleArray* minDirections= ma->ComputePrincipalCurvatures(NeighborhoodSize); 126 | if(MinDir) 127 | { 128 | cout<<"Saving directions of minimal curvature into file "<GetNumberOfTuples() ; i++) 136 | { 137 | minDirections->GetTuple(i,dir); 138 | myfile<WriteIntoFile(argv[argc-1], (char*)"curv"); // the very last input is the VTK for mean curv 146 | if(Gaussian) 147 | { 148 | cout<<"Saving Gaussian curvature into file "<WriteIntoFile(GaussianVTK, (char*)"gCurv"); 150 | } 151 | if(Max) 152 | { 153 | cout<<"Saving maximum curvature into file "<WriteIntoFile(MaxVTK, (char*)"curv1"); 155 | } 156 | 157 | if(Min) 158 | { 159 | cout<<"Saving minimum curvature into file "<WriteIntoFile(MinVTK, (char*)"curv2"); 161 | } 162 | cout<<"Elapsed time: "< 5 | #include 6 | #include 7 | 8 | int main(int argc, char** argv) 9 | { 10 | time_t start= time(NULL); 11 | 12 | // TravelDepth* depthComputer = new TravelDepth(argv[1]); 13 | // depthComputer->ComputeDepth(); 14 | // depthComputer->WriteIntoFile(argv[2]); 15 | 16 | MeshAnalyser* depthComputer = new MeshAnalyser(argv[1]); 17 | depthComputer->ComputeGeodesicDepthFromClosed(false); 18 | depthComputer->WriteIntoFile(argv[2],(char*)"geoDepth"); 19 | 20 | if(argc > 3) { 21 | depthComputer->WriteIntoFile(argv[3],(char*)"closed"); 22 | } 23 | 24 | cout<<"Elapsed time (geodesic depth): "< 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | template vtkPolyData *ReadObject(const char*fileName) 16 | { 17 | vtkSmartPointer reader = 18 | vtkSmartPointer::New(); 19 | reader->SetFileName(fileName); 20 | 21 | reader->Update(); 22 | reader->GetOutput()->Register(reader); 23 | return reader->GetOutput(); 24 | } 25 | 26 | void print_help() 27 | { 28 | printf( 29 | "Usage: GradientComputer InputVTKMesh\n" 30 | ); 31 | } 32 | 33 | int main(int argc, char** argv) 34 | { 35 | time_t start= time(NULL); 36 | vtkPolyData *dataSet; 37 | std::string extension = ".vtk"; 38 | //vtksys::SystemTools::GetFilenameLastExtension(argv[1]); 39 | if (extension == ".vtk") 40 | dataSet = ReadObject (argv[1]); 41 | else if (extension == ".obj") 42 | dataSet = ReadObject (argv[1]); 43 | else if (extension == ".stl") 44 | dataSet = ReadObject (argv[1]); 45 | 46 | GradientComputer* area = new GradientComputer(dataSet); 47 | area->ComputeGradient(); 48 | area->WriteIntoFile(argv[2]); 49 | 50 | cout<<"Elapsed time (area): "< 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | using namespace std; 19 | 20 | #ifndef MEDIALSURFACECOMPUTER_H 21 | #define MEDIALSURFACECOMPUTER_H 22 | 23 | class MedialSurfaceComputer 24 | { 25 | public: 26 | MedialSurfaceComputer(vtkPolyData *originalMesh, vtkPolyData *fundi); 27 | ~MedialSurfaceComputer(); 28 | 29 | void WriteIntoFile(char* fileName); 30 | 31 | private: 32 | vtkPolyData* m_medialSurface; 33 | 34 | vtkPolyData* m_originalFundi; 35 | 36 | vtkPolyData* m_originalMesh; 37 | vtkPointLocator* m_originalPointLocator; 38 | vtkOBBTree* m_originalCellLocator; 39 | 40 | 41 | vtkPolyData* m_processedFundi; 42 | 43 | vector m_layers; 44 | 45 | vtkDataArray* m_normals; 46 | vtkDoubleArray* m_pitsNormals; 47 | 48 | vtkPoints* m_candidatePoints; 49 | vtkPolyData* m_candidatePolyData; 50 | 51 | vtkDataArray* m_metric; 52 | vtkPointLocator* m_candidateLocator; 53 | 54 | int m_nbLayers; 55 | 56 | vtkIdList* m_bins; 57 | 58 | void ProcessFundi(); 59 | 60 | void BuildMedialSurface(); 61 | void AffectNormalsToFundi(); 62 | void BuildMeshFromLayers(); 63 | void FindCandidatePoints(); 64 | void FilterPointPosition(vtkPolyData* mesh); 65 | void AnchorPointToCandidate(double point[3]); 66 | void AnchorAllPointsToCandidates(); 67 | 68 | void SelectNextPoint(double point[3], vtkPolyData *prevLayer, int i); 69 | 70 | void GetPointNeighbors(vtkPolyData* pd, vtkIdType id, vtkIdList *neighbors); 71 | 72 | bool ProjectInNormalDirection(vtkIdType pointId, double interPoint[]); 73 | 74 | void FrontVoronoi(); 75 | 76 | }; 77 | 78 | 79 | 80 | 81 | #endif // MEDIALSURFACECOMPUTER_H 82 | -------------------------------------------------------------------------------- /vtk_cpp_tools/medial_surfaces/MedialSurfaceMain.cpp: -------------------------------------------------------------------------------- 1 | #include "MedialSurfaceComputer.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | template vtkPolyData *ReadObject(const char*fileName) 16 | { 17 | vtkSmartPointer reader = 18 | vtkSmartPointer::New(); 19 | reader->SetFileName(fileName); 20 | 21 | reader->Update(); 22 | reader->GetOutput()->Register(reader); 23 | return reader->GetOutput(); 24 | } 25 | 26 | int main(int argc, char** argv) 27 | { 28 | time_t start= time(NULL); 29 | 30 | vtkPolyData* travelData; 31 | vtkPolyData* fundiData; 32 | 33 | std::string extension1 = 34 | vtksys::SystemTools::GetFilenameLastExtension(argv[1]); 35 | std::string extension2 = 36 | vtksys::SystemTools::GetFilenameLastExtension(argv[2]); 37 | 38 | if (extension1 == ".vtk") 39 | travelData = ReadObject (argv[1]); 40 | else if (extension1 == ".obj") 41 | travelData = ReadObject (argv[1]); 42 | else if (extension1 == ".stl") 43 | travelData = ReadObject (argv[1]); 44 | 45 | if (extension2 == ".vtk") 46 | fundiData = ReadObject (argv[2]); 47 | else if (extension2 == ".obj") 48 | fundiData = ReadObject (argv[2]); 49 | else if (extension2 == ".stl") 50 | fundiData = ReadObject (argv[2]); 51 | 52 | 53 | MedialSurfaceComputer* msc = new MedialSurfaceComputer( travelData, fundiData ); 54 | 55 | msc->WriteIntoFile(argv[3]); 56 | 57 | cout<<"Elapsed time (meshTest): "< 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | template vtkPolyData *ReadObject(const char*fileName) 16 | { 17 | vtkSmartPointer reader = 18 | vtkSmartPointer::New(); 19 | reader->SetFileName(fileName); 20 | 21 | reader->Update(); 22 | reader->GetOutput()->Register(reader); 23 | return reader->GetOutput(); 24 | } 25 | 26 | void print_help() 27 | { 28 | printf( 29 | "Usage: Overlap InputVTKMesh1 InputVTKMesh2 OutputFileName\n" 30 | ); 31 | } 32 | 33 | int main(int argc, char** argv) 34 | { 35 | time_t start= time(NULL); 36 | 37 | vtkPolyData* data1; 38 | vtkPolyData* data2; 39 | 40 | std::string extension1 = ".vtk"; 41 | //vtksys::SystemTools::GetFilenameLastExtension(argv[1]); 42 | std::string extension2 = ".vtk"; 43 | //vtksys::SystemTools::GetFilenameLastExtension(argv[2]); 44 | 45 | if (extension1 == ".vtk") 46 | data1 = ReadObject (argv[1]); 47 | else if (extension1 == ".obj") 48 | data1 = ReadObject (argv[1]); 49 | else if (extension1 == ".stl") 50 | data1 = ReadObject (argv[1]); 51 | 52 | if (extension2 == ".vtk") 53 | data2 = ReadObject (argv[2]); 54 | else if (extension2 == ".obj") 55 | data2 = ReadObject (argv[2]); 56 | else if (extension2 == ".stl") 57 | data2 = ReadObject (argv[2]); 58 | 59 | 60 | Overlap* surfOverlap = new Overlap(data1, data2); 61 | surfOverlap->ComputeOverlap(); 62 | surfOverlap->WriteIntoFile(argv[3]); 63 | 64 | 65 | cout<<"Elapsed time (meshTest): "< 5 | #include 6 | #include 7 | 8 | 9 | void print_help() 10 | { 11 | printf( 12 | "Usage: TravelDepthMain [Options] InputVTKMesh MeanCurvatureOutput\n" 13 | "Options: \n" 14 | " -n: Normalize the output values beteween 0 and 1\n" 15 | " -w outputWrapperMesh: export the wrapper mesh\n" 16 | "Example: TravelDepthMain -n -w wrapper.vtk lh.pial.vtk lh.travel_depth.vtk \n" 17 | ); 18 | } 19 | 20 | int main(int argc, char** argv) 21 | { 22 | 23 | if(argc < 3) 24 | { 25 | print_help(); 26 | return -1; 27 | } 28 | 29 | time_t start= time(NULL); 30 | 31 | bool normalized = false; 32 | bool wrapperExported = false; 33 | int wrapperNameId; 34 | 35 | /* Processing options and arguments */ 36 | for (int i=1;iComputeTravelDepthFromClosed(normalized); 61 | depthComputer->WriteIntoFile(argv[argc-1],(char*)"depth"); 62 | 63 | if(wrapperExported) { 64 | depthComputer->WriteIntoFile(argv[wrapperNameId],(char*)"closed"); 65 | } 66 | 67 | 68 | cout<<"Elapsed time (meshTest): "<