Skip to content
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

Batch processing #14

Merged
merged 7 commits into from
Mar 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
project(dcm2niix)
cmake_minimum_required(VERSION 2.6)

# Option1: Choose whether to build the batch version
option(BATCH_VERSION "Build dcm2niibatch for multiple conversions as well" OFF)
message(${BATCH_VERSION})

# Option2: Build qt gui
# TODO

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

cmake_minimum_required(VERSION 2.6)
#
# Zlib
#
find_package(ZLIB)
#find_package(ZLIB)

# Resolve system dependency on yaml-cpp, which apparently does not
# provide a CMake find_package() module.
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(YAML_CPP yaml-cpp)
find_path(YAML_CPP_INCLUDE_DIR
NAMES yaml_cpp.h
PATHS ${YAML_CPP_INCLUDE_DIRS})
find_library(YAML_CPP_LIBRARY
NAMES YAML_CPP
PATHS ${YAML_CPP_LIBRARY_DIRS})
endif()

# Predefined permission set to enforce proper permissions
# during install even if files in the sources have different
Expand Down
116 changes: 98 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
##### About
## About

dcm2nii is a designed to convert neuroimaging data from the NIfTI format to the DICOM format. For details and compiled versions visit the [NITRC wiki](http://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage)
dcm2niix is a designed to convert neuroimaging data from the NIfTI format to the DICOM format. For details and compiled versions visit the [NITRC wiki](http://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage)

##### Versions
## Versions

12-Dec-2015
- Support PAR/REC FP values when possible(see PMC3998685)
Expand All @@ -29,25 +29,89 @@ dcm2nii is a designed to convert neuroimaging data from the NIfTI format to the
11-Oct-2014
- Initial public release

Building command line version:
## Running

This requires a C compiler. With a terminal, change directory to the 'conosle' folder and run the following:
See help: `dcm2niix -h`
e.g. `dcm2niix /path/to/dicom/folder`

**Optional batch processing version:**

Perform a batch conversion of multiple dicoms using the configurations specified in a yaml file.
```bash
dcm2niibatch run_configuration.yaml
```

The configuration file should be in yaml format as shown in example `run_configuration.yaml`

```yaml
Options:
isGz: false
isFlipY: false
isVerbose: false
isCreateBIDS: false
isOnlySingleFile: false
Files:
-
in_dir: /path/to/first/folder
out_dir: /path/to/output/folder
filename: dcemri
-
in_dir: /path/to/second/folder
out_dir: /path/to/output/folder
filename: fa3
```

You can add as many files as you want to convert as long as this structure stays consistent. Note that a dash must separate each file.

## Build

### Build command line version with cmake (Linux, Windows, OSx)

```bash
mkdir build
cd build
cmake ..
```
`dcm2niix` will be created in the `bin` folder

**optional batch processing version:**

The batch processing binary `dcm2niibatch` is optional. To build `dcm2niibatch` as well change the cmake command to `cmake -DBATCH_VERSION=ON ..`

This requires the following libraries:
- pkg-config
- yaml-cpp
- a compiler that supports c++11

e.g. the dependencies can be installed on Ubuntu 14.04 by running
```
sudo apt-get install pkg-config libyaml-cpp-dev libyaml-cpp0.5 cmake
```

### Building the command line version without cmake

This requires a C compiler. With a terminal, change directory to the 'console' folder and run the following:

##### DEFAULT BUILD

- g++ -O3 -DmyDisableOpenJPEG -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -dead_strip -o dcm2niix
```
g++ -O3 -DmyDisableOpenJPEG -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -dead_strip -o dcm2niix
```

##### ZLIB BUILD
If we have zlib, we can use it (-lz) and disable [miniz](https://code.google.com/p/miniz/) (-myDisableMiniZ)

- g++ -O3 -DmyDisableOpenJPEG -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -dead_strip -o dcm2niix -lz -DmyDisableMiniZ
```
g++ -O3 -DmyDisableOpenJPEG -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -dead_strip -o dcm2niix -lz -DmyDisableMiniZ
```

##### MINGW BUILD

If you use the (osbsolete) compiler MinGW on Windows you will want to include the rare libgcc libraries with your executable so others can use it. Here I also demonstrate the optional "-DmyDisableZLib" to remove zip support.

- g++ -O3 -s -DmyDisableOpenJPEG -DmyDisableZLib -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -o dcm2niix -static-libgcc
If you use the (obsolete) compiler MinGW on Windows you will want to include the rare libgcc libraries with your executable so others can use it. Here I also demonstrate the optional "-DmyDisableZLib" to remove zip support.

```
g++ -O3 -s -DmyDisableOpenJPEG -DmyDisableZLib -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -o dcm2niix -static-libgcc
```

##### JPEG2000 BUILD

Expand All @@ -58,17 +122,25 @@ If you use the (osbsolete) compiler MinGW on Windows you will want to include th
sudo make install
You should then be able to run then run:

- g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -o dcm2niix -lopenjp2
```
g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -o dcm2niix -lopenjp2
```

But in my experience this works best if you explicitly tell the software how to find the libraries, so your compile will probably look like one of these two options:

- g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -o dcm2niix -I/usr/local/include /usr/local/lib/libopenjp2.a
```
g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -o dcm2niix -I/usr/local/include /usr/local/lib/libopenjp2.a
```

- g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -o dcm2niix -I/usr/local/lib /usr/local/lib/libopenjp2.a
```
g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -o dcm2niix -I/usr/local/lib /usr/local/lib/libopenjp2.a
```

If you want to build this with JPEG2000 decompression support using Jasper: You will need to have the Jasper (http://www.ece.uvic.ca/~frodo/jasper/) and libjpeg (http://www.ijg.org) libraries installed which for Linux users may be as easy as running 'sudo apt-get install libjasper-dev' (otherwise, see http://www.ece.uvic.ca/~frodo/jasper/#doc). You can then run:

- g++ -O3 -DmyDisableOpenJPEG -DmyEnableJasper -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -s -o dcm2niix -ljasper -ljpeg
```
g++ -O3 -DmyDisableOpenJPEG -DmyEnableJasper -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -s -o dcm2niix -ljasper -ljpeg
```

##### VISUAL STUDIO BUILD

Expand All @@ -79,15 +151,23 @@ You should be able to click on the Visual Studio icons to open and build this co
Building command line version universal binary from OSX 64 bit system:
This requires a C compiler. With a terminal, change directory to the 'conosle' folder and run the following:

- g++ -O3 -DmyDisableOpenJPEG -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -dead_strip -arch i386 -o dcm2niix32
```
g++ -O3 -DmyDisableOpenJPEG -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -dead_strip -arch i386 -o dcm2niix32
```

- g++ -O3 -DmyDisableOpenJPEG -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -dead_strip -o dcm2niix64
```
g++ -O3 -DmyDisableOpenJPEG -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp -dead_strip -o dcm2niix64
```

- lipo -create dcm2niix32 dcm2niix64 -o dcm2niix
```
lipo -create dcm2niix32 dcm2niix64 -o dcm2niix
```

To validate that the resulting executable supports both architectures type

- file ./dcm2niix
```
file ./dcm2niix
```

##### OSX GRAPHICAL INTERFACE BUILD

Expand Down
42 changes: 30 additions & 12 deletions console/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
project(console)
set(PROGRAMS dcm2niix)

add_executable(dcm2niix
main_console.cpp
nii_dicom.cpp
jpg_0XC3.cpp
ujpeg.cpp
nifti1_io_core.cpp
nii_ortho.cpp
nii_dicom_batch.cpp)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# using Clang
ADD_DEFINITIONS(-dead_strip)
add_definitions(-dead_strip)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
Expand All @@ -28,7 +19,34 @@ endif()
#else(ZLIB_FOUND)
# ADD_DEFINITIONS(-DmyDisableZlib)
#endif(ZLIB_FOUND)
ADD_DEFINITIONS(-DmyDisableJasper)
ADD_DEFINITIONS(-DmyDisableOpenJPEG)
add_definitions(-DmyDisableJasper)
add_definitions(-DmyDisableOpenJPEG)

add_executable(dcm2niix
main_console.cpp
nii_dicom.cpp
jpg_0XC3.cpp
ujpeg.cpp
nifti1_io_core.cpp
nii_ortho.cpp
nii_dicom_batch.cpp)


if (BATCH_VERSION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

message("Creating batch version")

add_executable(dcm2niibatch
main_console_batch.cpp
nii_dicom.cpp
jpg_0XC3.cpp
ujpeg.cpp
nifti1_io_core.cpp
nii_ortho.cpp
nii_dicom_batch.cpp)

target_link_libraries(dcm2niibatch yaml-cpp)
endif()

install(TARGETS ${PROGRAMS} DESTINATION bin)
Empty file modified console/main_console.cpp
100755 → 100644
Empty file.
80 changes: 80 additions & 0 deletions console/main_console_batch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// main.m dcm2niix
// by Chris Rorden on 3/22/14, released under Gnu General Public License, Version 2.
// Copyright (c) 2014 Chris Rorden. All rights reserved.


#include <stdlib.h>
#include <stdbool.h>
#include <time.h> // clock_t, clock, CLOCKS_PER_SEC
#include <stdio.h>
#include <cmath>
#include <string>
#include <iostream>

#include "nii_dicom_batch.h"

#include <fstream>
#include <yaml-cpp/yaml.h>

const char* removePath(const char* path) { // "/usr/path/filename.exe" -> "filename.exe"
const char* pDelimeter = strrchr (path, '\\');
if (pDelimeter)
path = pDelimeter+1;
pDelimeter = strrchr (path, '/');
if (pDelimeter)
path = pDelimeter+1;
return path;
} //removePath()


int rmainbatch(TDCMopts opts)
{
printf("Chris Rorden's dcm2niiX version %s (%lu-bit)\n",kDCMvers, sizeof(size_t)*8);

clock_t start = clock();
nii_loadDir(&opts);
printf ("Conversion required %f seconds.\n",((float)(clock()-start))/CLOCKS_PER_SEC);
return EXIT_SUCCESS;
}

int main(int argc, const char * argv[])
{

if (argc != 2) {
std::cout << "Do not include additional inputs with a config file \n";
throw;
}

// Process it all via a yaml file
std::string yaml_file = argv[1];
std::cout << "yaml_path: " << yaml_file << std::endl;
YAML::Node config = YAML::LoadFile(yaml_file);

struct TDCMopts opts;

opts.isCreateBIDS = config["Options"]["isCreateBIDS"].as<bool>();
opts.isOnlySingleFile = config["Options"]["isOnlySingleFile"].as<bool>();
opts.isCreateText = false;
opts.isVerbose = false;
opts.isGz = config["Options"]["isGz"].as<bool>(); //force use of internal compression instead of pigz
if (opts.isGz) {
// TODO this is not the same as previous
strcpy(opts.pigzname, "");
}

for (auto i: config["Files"]) {

std::string indir = i["in_dir"].as<std::string>();
strcpy(opts.indir, indir.c_str());

std::string outdir = i["out_dir"].as<std::string>();
strcpy(opts.outdir, outdir.c_str());

std::string filename = i["filename"].as<std::string>();
strcpy(opts.filename, filename.c_str());

rmainbatch(opts);

}
return 1;
}
16 changes: 16 additions & 0 deletions run_configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Options:
isGz: false
isFlipY: false
isVerbose: false
isCreateBIDS: false
isOnlySingleFile: false

Files:
-
in_dir: /path/to/first/folder
out_dir: /path/to/output/folder
filename: dcemri
-
in_dir: /path/to/second/folder
out_dir: /path/to/output/folder
filename: fa3