-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add support for MINC image IO #716
Conversation
LGTM ! Thanks for the contribution ! |
xref CoBrALab/atlases#6 |
@fedorov Thanks for the note! I am trying to update ITK's MINC to address the reported Windows build issue... |
So, what is the problem now? |
ITK's libminc is updated to the latest http://review.source.kitware.com/#/c/22329/ This includes: BIC-MNI/libminc@d8cdab3 but newer Visual Studio may still not work because of BIC-MNI/libminc#77 |
Spoke too soon: the update does include BIC-MNI/libminc@9679353 @lassoan could you please test? We should then mark BIC-MNI/libminc#77 as closed if it has been addressed. |
@thewtex I can test on mac, if this would help, but I won't find time to rigorously examine the code (I see you assigned me on gerrit), I have no familiarity with this library at all. Let me know if it would help if I test this branch on mac, I don't want to do if someone else is already did/doing it. |
@fedorov Thanks, yes that would help. I only tested on Linux. To test, check out the branch: git fetch http://review.source.kitware.com/ITK refs/changes/29/22329/1 && git checkout FETCH_HEAD and set To build only
To run just the MINC tests:
|
@thewtex ok I will test ITK as you suggested. Should we test if this causes any issues with SimpleITK? Isn't this specific PR premature, as it would need to also include an update to ITK which is not finalized itself yet? |
@fedorov thanks! I do not anticipate any issues with SimpleITK. Yes, we will need to get the fixes into ITK first, then update Slicer's version of ITK. |
@thewtex What should I test? Should I try to build the version in this PR? If a custom ITK version is needed, could you update the ITK repository/git tag in SuperBuild\External_ITKv4.cmake to that version? |
Here is the error I am getting on mac compiling ITK branch @thewtex asked me to test:
|
The issue of MINC support came up a couple of times in the past but we failed to add it due that there were always build errors on non-Linux platforms. Considering persistent build issues, lack of cross-platform interest of MINC developers, and existence of a number of other well-supported alternative file formats, I would consider moving away from this format, maybe even move it from ITK proper to a remote module. |
@fedorov - somehow it is configured to search for NetCDF , can you send configuration parameters? |
@vfonov: as mentioned earlier by @thewtex, the proposed modification to ITK to include MINC support is in this branch: http://review.source.kitware.com/#/c/22329/. Instructions how to build it are provided here: Slicer/Slicer#716 (comment). If you have a mac, you should be able to reproduce the issue and debug it. I don't know how and where configuration parameters are passed -- it is configured as a third-party module of ITK, and I don't know the details of implementation. |
Here are my updates: http://review.source.kitware.com/#/c/22331/ To test it , I configure with -DITK_USE_SYSTEM_MINC:BOOL=OFF -DModule_ITKIOMINC:BOOL=ON -DModule_ITKIOTransformMINC:BOOL=ON -DModule_ITKMINC:BOOL=ON To compile: make ITKIOMINC-all ITKIOTransformMINC-all And to run tests: ctest -L ITKIOTransformMINC -L ITKIOMINC |
@vfonov great!
|
Run the UpdateFromUpstream.sh script to extract upstream MINC using the following shell commands. $ git archive --prefix=upstream-minc/ 3d79acf3 -- ./ChangeLog ./volume_io ./libsrc ./libsrc/minc_compat.h ./libcommon/minc_config.h ./libcommon/minc_config.c ./libsrc/minc_format_convert.c ./libsrc/value_conversion.c ./libsrc/hdf_convenience.c ./libcommon/read_file_names.c ./libsrc/minc_simple.c ./libcommon/time_stamp.h ./libsrc/hdf_convenience.h ./libsrc/type_limits.h ./libcommon/read_file_names.h ./libsrc/minc_varlists.h ./libcommon/restructure.h ./libsrc/nd_loop.h ./libcommon/restructure.c ./libsrc/minc_simple.h ./libsrc/strdup.c ./libsrc/minc_useful.h ./libsrc/minc_convenience.c ./libsrc/minc_basic.h ./libsrc/minc_compat.c ./libcommon/time_stamp.c ./libsrc/voxel_loop.h ./libsrc/minc_routines.h ./libsrc/minc_private.h ./libsrc/netcdf_convenience.c ./libsrc/voxel_loop.c ./libsrc/dim_conversion.c ./libsrc/minc_format_convert.h ./libsrc/nd_loop.c ./libcommon/ParseArgv.h ./libcommon/minc_error.c ./libcommon/minc_error.h ./libsrc/minc_structures.h ./libsrc/minc.h ./libsrc/image_conversion.c ./libcommon/ParseArgv.c ./libcommon/minc_common_defs.h ./COPYING ./UseLIBMINC.cmake.in ./NEWS ./AUTHORS ./libsrc2/m2util.c ./libsrc2/minc2_defs.h ./libsrc2/minc2_api.h ./libcommon/minc2_error.h ./libsrc2/grpattr.c ./libsrc2/hyper.c ./libsrc2/minc_compat2.h ./libcommon/minc2_error.c ./libsrc2/record.c ./libsrc2/volume.c ./libsrc2/datatype.c ./libsrc2/volprops.c ./libsrc2/valid.c ./libsrc2/convert.c ./libsrc2/free.c ./libsrc2/dimension.c ./libsrc2/label.c ./libsrc2/minc2.h ./libsrc2/minc2_private.h ./libsrc2/slice.c ./libsrc2/minc2_structs.h ./CMakeLists.txt ./nifti ./LIBMINCConfig.cmake.in ./README.release ./INSTALL ./config.h.cmake ./README | tar x $ git shortlog --perl-regexp --author='^((?!Kitware Robot).*)$' --no-merges --abbrev=8 --format='%h %s' 8632513e..3d79acf3 Chris Hammill (1): 06f3e87b Unsatisfying solution to issue InsightSoftwareConsortium#71 Robert D. Vincent (34): 5b483ac0 Fix problem discovered by Jerome Redoute - voxel_loop programs do not properly remove the loop dimension if it contains a 'xxxx-width' variable. 59678daa Minor fixes for MINC2.0 API. Implement alignment, properly record dimorder for irregular dimension variables, quiet some errors. f0126d35 Hopefully useful version of minc_get_world_transform() and new function minc_transform_to_world(). 3775a0a9 Propagate read errors such that voxel_loop() now returns an integer exit code. 2e33bca0 Propagate read errors through volume_io as well. 5ac1aca8 Fix warning. 3ca34259 Correctly place attributes intended for the image variable (e.g. 'complete'). 25792953 Avoid repetitive code while correcting placement of attributes within the HDF5 hierarchy. 17aa090d Fix BIC-MNI/minc-tools#45 - add quotes around argv items that contain spaces. e7101d7a Make sure variable is initialized. d99dd016 Fix InsightSoftwareConsortium#74, don't assume hid_t === int since this is no longer true in HDF5 1.10. e7df7ce1 Minor fixes so that miclose() return value is correct. 2f6b922f Fix issues with proper ranging of data in NIfTI files. 6fbea42f Fix memory leaks to keep LeakSanitizer happy. eb7cf239 Add multidim array tests. 1f4a4c5a Fix warnings. 3f0c0389 Fix BIC-MNI/Display#63, Ignore MGZ/freesurfer offsets so that volumes align with their surfaces. 00ac284f Fix warnings for unused variables (in an unused test). 3b2df807 Major fix to NIfTI reading for images with non-standard transforms. f01e9be2 Fix problem if scl_slope is zero. 063fce99 Correctly read NIfTI files with a fifth dimension. 1e1b300d Attempt to improve speed of NIfTI loader. f3f881fe Fix bug in nifti reader. 433acc15 Implement some additional special cases for volume interpolation. 85733672 Basic reader for NRRD format. 14cee37d Fix minor memory leak. baced81b Add libcommon to LIBMINC_INCLUDE_DIRS_CONFIG so that minctools will build. 931df645 Fix InsightSoftwareConsortium#78, correct documentation for miget_dimension_sampling_flag(). c3841475 Fix use-after-free error. 3d5a2277 Fix range calculation for small NIfTI files. 62a6a849 Fix InsightSoftwareConsortium#80, memory leaks in hyperslab reading. b2fdfff7 testing for leaks. 4d68e862 Free memory at end of test. 3daa90b4 Fix issue when copying a non-allocated volume. Vladimir S. FONOV (38): 2c9fe645 Removing allocation debug code, it is superseded by address sanitizer or valgrind d3ab23b5 Added proper flag to MIcomplete when minc file is successfully closed 39d86771 Replaced C++ comment to C comment 6ef58fe9 Added option to work with integer labels (avoid inter-slice scaling) 9c27bde6 Disabled writing of complete flag temporarely 5df49651 WIP: adding labels to volumeio 89a82cf9 WIP: modifying volume_io to work properly with labels 466cdede WIP: adding possibility to debug minc2 volume io interface bbf80974 Added labels support in volume_io and a new environment configuration variable MINC_PREFER_V2_API to force volume_io to use MINC2 API directly, mostly for debugging purposes 3764357a Finalizing MINC2 api choise support in volume_io 0bd33a2e Fixed segfault that creeped in after the previous commit 46261240 Tweaking voxel_loop 745d75a9 Removed FindHDF5 and bumped cmake version requirements, addresses InsightSoftwareConsortium#71 d641c4fd Updating HDF5 variables, fixing libnifti internal build dependencies b45312d9 Disabled allocation debugging in volume_io - superceded by valgrind and asan 21125c4b Downgraded cmake requirements to satisfy travis-ci 44b8d4b3 Fixed memory leak in minc_long_attr tests 92ba4fa2 Fixing function forgotten in d99dd01632dbcb62870870557b333142b9117e9a , related to InsightSoftwareConsortium#74 eb7eb487 Fixing memory leak, addresses InsightSoftwareConsortium#75 70a27484 Added description of environment variables 96793536 Added explicit test for rint, addresses InsightSoftwareConsortium#77 f134ca9c Updated brew control sum for HDF5 eecefd5d Refactoring minc2 internals 34b08c7e Trying to make travis-build happy d9d98771 Fixed dimorder variable contents for image-min and image-max 54169226 Made some tests actually perform something meaningless and report errors if things don't work dbf3e037 Minor change: fixed comments dd93215a Refactring error handling in volume_io f864dd22 Fixing failed build when MINC1 support is disabled bb7ce2db Refactoring common minc1&minc2 code a74eef51 Refactoring minc error reporting cba6f09b Bumped package patch version b1cd7f50 Updated comment for restructure d8cdab34 Hopefully fixes compilation issue on Windows, addresses CoBrALab/atlases#6 bd17b1f2 Replaced c++ style comment with c a44cf8de Added a hack to address BIC-MNI/minc-tools#59 f8f16142 Fixed volume_io error reporting routine, adresses BIC-MNI/Register#16 3d79acf3 Fixing issue from Slicer/Slicer#716: moved code from libsrc into libcommon, removed unused varable Change-Id: I8d3238e3bf830b6c4df9a64df35567e01268a030
Hats off to @vfonov for the update! @lassoan Here is a branch that includes the MINC/ITK update: https://github.com/thewtex/Slicer/tree/minc-io-with-itk-update |
@thewtex Thanks, I've started a build of https://github.com/thewtex/Slicer/tree/minc-io-with-itk-update on Win10 with VS2013. Build failed with this error:
full log: |
@lassoan Thanks for testing on the target compiler / platform. It looks like the system has |
@lassoan Please try this branch: https://github.com/thewtex/Slicer/tree/minc-io-with-itk-update-2 |
Build failed with this error: 35> Project "C:\D\E\Slicer-0-build\ITKv4-build\ALL_BUILD.vcxproj" (1) is building "C:\D\E\Slicer-0-build\ITKv4-build\Modules\IO\MINC\src\ITKIOMINC.vcxproj" (110) on node 1 (default targets). I start a clean build now. @thewtex Would you like to get access to the computer so that you can test and fix the errors directly? If yes then send me a message in private. |
@lassoan Thanks for checking. If the error persists after a fresh build, I'll try to reproduce on a different box, and, if I still persists, debugging on the target will be very helpful. |
The error is the same when starting the build from scratch. See full build log here (first error is around line 79121): https://1drv.ms/t/s!Arm_AFxB9yqHr61zxIsdFj_PLLf5qw |
Issue #4085 This enables MINC Image IO via ITK. This currently supports MINC version 2 (HDF5-based).
Rebased on Slicer master, which now includes updated ITK, which includes updated libminc. These include fixes for Visual Studio. |
@@ -55,6 +55,7 @@ ITKImageFileFormat FileFormatTable[] = | |||
{"MGHImageIO", "Uncompressed FreeSurfer pixel data in binary", "MGH", ".mgh"}, | |||
{"MGHImageIO", "Gzip Compressed FreeSurfer pixel data in binary", "MGH", ".mgz"}, | |||
{"MGHImageIO", "Gzip Compressed FreeSurfer pixel data in binary", "MGH", ".mgh.gz"}, | |||
{"MINCImageIO", "Optional compression. Binary pixel data", "MINC", ".mnc"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should a line line like this be added then:
{"MINCImageIO", "Gzip Compressed binary pixel data", "MINC", ".mnc.gz"},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be careful here, classically, .mnc.gz files are "MINC1" aka NetCDF files, which the ITK MINC IO can't open.
.mnc files are now typically MINC2 files which are HDF5 with internal zlib compression built into the filespec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integrated MINC ITK reader is based only on MINC2 library, and is not capable of reading MINC1 files.
If one would compile full minc library (with MINC1 & MINC2 support) and incorporated it into Slicer, then ITK would be able to read .mnc.gz files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback.
Would the following be correct then:
{"MINCImageIO", "MINC2 binary pixel data using HDF5 with internal zlib compression", "MINC2", ".mnc"},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compression have to be enabled though, through SetUseCompression / UseCompressionOn - methods of ImageIOBase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, I will plan on using this then:
{"MINCImageIO", "MINC2 binary pixel data using HDF5 with optional internal zlib compression", "MINC2", ".mnc"},
Integrated in r26011 @lassoan That said, could you confirm that loading the sample data |
I've tested this and Reading/writing .mnc files work well on Windows. |
🍾 Thanks all for working together to make this happen! |
@thewtex when compiling Slicer using centos 5 with g++ 4.8.2 from the latest version of docker-centos-build, it reports the following error:
|
The try_compile associated with Modules/ThirdParty/MINC/src/libminc/CMakeLists.txt#L125 returns the following:
|
The issue is that the C99 extension is not enabled during introspection, adding the following to the CMakeLists addressed the problem (adapted from python-cmake-buildsystem/python-cmake-buildsystem):
|
The following commit should be backported and integrated: Slicer/ITK@3cc1a24 |
Issue #4085
This enables MINC Image IO via ITK. This currently supports MINC version 2
(HDF5-based).