Skip to content

Commit

Permalink
feat(formats): add MetaImage support
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed May 30, 2017
1 parent 069d5f6 commit a33cd55
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ project(BridgeJavaScript)

set(BridgeJavaScript_IOModules
"ITKIOGDCM"
"ITKIOMeta"
"ITKIONRRD"
"ITKIOPNG"
"ITKIOVTK"
CACHE STRING
"String delimited list of ITK IO modules to support.")
set(imageio_ITKIOPNG itkPNGImageIO)
set(imageio_ITKIOMeta itkMetaImageIO)
set(imageio_ITKIONRRD itkNrrdImageIO)
set(imageio_ITKIOGDCM itkGDCMImageIO)
set(imageio_ITKIOVTK itkVTKImageIO)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Provides general scientific image IO capability and bridges
## Supported file formats

- [DICOM](http://dicom.nema.org/)
- [MetaImage](https://itk.org/Wiki/ITK/MetaIO/Documentation)
- [NRRD](http://teem.sourceforge.net/nrrd/format.html)
- [Portable Network Graphics (PNG)](https://en.wikipedia.org/wiki/Portable_Network_Graphics)
- [VTK legacy image file format](http://www.vtk.org/VTK/img/file-formats.pdf)
Expand Down
7 changes: 6 additions & 1 deletion src/itkExtensionToIO.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
let extensionToIO = {}

extensionToIO['dcm'] = 'itkGDCMImageIOJSBinding'
extensionToIO['DCM'] = 'itkGDCMImageIOJSBinding'

extensionToIO['mha'] = 'itkMetaImageIOJSBinding'
extensionToIO['mhd'] = 'itkMetaImageIOJSBinding'

extensionToIO['nrrd'] = 'itkNrrdImageIOJSBinding'
extensionToIO['NRRD'] = 'itkNrrdImageIOJSBinding'

extensionToIO['nhdr'] = 'itkNrrdImageIOJSBinding'
extensionToIO['NHDR'] = 'itkNrrdImageIOJSBinding'

extensionToIO['png'] = 'itkPNGImageIOJSBinding'
extensionToIO['PNG'] = 'itkPNGImageIOJSBinding'

extensionToIO['vtk'] = 'itkVTKImageIOJSBinding'
extensionToIO['VTK'] = 'itkVTKImageIOJSBinding'

module.exports = extensionToIO
91 changes: 91 additions & 0 deletions src/itkMetaImageIOJSBinding.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

#include <emscripten.h>
#include <emscripten/bind.h>

#include "itkMetaImageIO.h"

#include "itkImageIOBaseJSBinding.h"

typedef itk::ImageIOBaseJSBinding< itk::MetaImageIO > MetaImageIOJSBindingType;

EMSCRIPTEN_BINDINGS(itk_meta_image_io_js_binding) {
emscripten::register_vector<double>("AxisDirectionType");
emscripten::enum_<MetaImageIOJSBindingType::IOPixelType>("IOPixelType")
.value("UNKNOWNPIXELTYPE", itk::ImageIOBase::UNKNOWNPIXELTYPE)
.value("SCALAR", itk::ImageIOBase::SCALAR)
.value("RGB", itk::ImageIOBase::RGB)
.value("RGBA", itk::ImageIOBase::RGBA)
.value("OFFSET", itk::ImageIOBase::OFFSET)
.value("VECTOR", itk::ImageIOBase::VECTOR)
.value("POINT", itk::ImageIOBase::POINT)
.value("COVARIANTVECTOR", itk::ImageIOBase::COVARIANTVECTOR)
.value("SYMMETRICSECONDRANKTENSOR", itk::ImageIOBase::SYMMETRICSECONDRANKTENSOR)
.value("POINT", itk::ImageIOBase::POINT)
.value("COVARIANTVECTOR", itk::ImageIOBase::COVARIANTVECTOR)
.value("SYMMETRICSECONDRANKTENSOR", itk::ImageIOBase::SYMMETRICSECONDRANKTENSOR)
.value("DIFFUSIONTENSOR3D", itk::ImageIOBase::DIFFUSIONTENSOR3D)
.value("COMPLEX", itk::ImageIOBase::COMPLEX)
.value("FIXEDARRAY", itk::ImageIOBase::FIXEDARRAY)
.value("MATRIX", itk::ImageIOBase::MATRIX)
;
emscripten::enum_<MetaImageIOJSBindingType::IOComponentType>("IOComponentType")
.value("UNKNOWNCOMPONENTTYPE", itk::ImageIOBase::UNKNOWNCOMPONENTTYPE)
.value("UCHAR", itk::ImageIOBase::UCHAR)
.value("CHAR", itk::ImageIOBase::CHAR)
.value("USHORT", itk::ImageIOBase::USHORT)
.value("SHORT", itk::ImageIOBase::SHORT)
.value("UINT", itk::ImageIOBase::UINT)
.value("INT", itk::ImageIOBase::INT)
.value("ULONG", itk::ImageIOBase::ULONG)
.value("LONG", itk::ImageIOBase::LONG)
.value("FLOAT", itk::ImageIOBase::FLOAT)
.value("DOUBLE", itk::ImageIOBase::DOUBLE)
;
emscripten::class_<MetaImageIOJSBindingType>("ITKImageIO")
.constructor<>()
.function("SetNumberOfDimensions", &MetaImageIOJSBindingType::SetNumberOfDimensions)
.function("GetNumberOfDimensions", &MetaImageIOJSBindingType::GetNumberOfDimensions)
.function("SetFileName", &MetaImageIOJSBindingType::SetFileName)
.function("GetFileName", &MetaImageIOJSBindingType::GetFileName)
.function("CanReadFile", &MetaImageIOJSBindingType::CanReadFile)
.function("ReadImageInformation", &MetaImageIOJSBindingType::ReadImageInformation)
.function("SetDimensions", &MetaImageIOJSBindingType::SetDimensions)
.function("GetDimensions", &MetaImageIOJSBindingType::GetDimensions)
.function("SetOrigin", &MetaImageIOJSBindingType::SetOrigin)
.function("GetOrigin", &MetaImageIOJSBindingType::GetOrigin)
.function("SetSpacing", &MetaImageIOJSBindingType::SetSpacing)
.function("GetSpacing", &MetaImageIOJSBindingType::GetSpacing)
.function("SetDirection", &MetaImageIOJSBindingType::SetDirection)
.function("GetDirection", &MetaImageIOJSBindingType::GetDirection)
.function("GetDefaultDirection", &MetaImageIOJSBindingType::GetDefaultDirection)
.function("SetPixelType", &MetaImageIOJSBindingType::SetPixelType)
.function("GetPixelType", &MetaImageIOJSBindingType::GetPixelType)
.function("SetComponentType", &MetaImageIOJSBindingType::SetComponentType)
.function("GetComponentType", &MetaImageIOJSBindingType::GetComponentType)
.class_function("GetPixelTypeAsString", &MetaImageIOJSBindingType::GetPixelTypeAsString)
.class_function("GetComponentTypeAsString", &MetaImageIOJSBindingType::GetComponentTypeAsString)
.function("GetImageSizeInPixels", &MetaImageIOJSBindingType::GetImageSizeInPixels)
.function("GetImageSizeInBytes", &MetaImageIOJSBindingType::GetImageSizeInBytes)
.function("GetImageSizeInComponents", &MetaImageIOJSBindingType::GetImageSizeInComponents)
.function("SetNumberOfComponents", &MetaImageIOJSBindingType::SetNumberOfComponents)
.function("GetNumberOfComponents", &MetaImageIOJSBindingType::GetNumberOfComponents)
.function("Read", &MetaImageIOJSBindingType::Read)
;
}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ itk_add_test(NAME itkPNGImageIOJSBindingTest
ExternalData_Expand_Arguments(
ITKData
npm_test_inputs
DATA{Input/brainweb165a10f17.mha}
DATA{Input/vol-raw-little.nrrd}
DATA{Input/1.3.6.1.4.1.5962.99.1.3814087073.479799962.1489872804257.100.0.dcm}
DATA{Input/ironProt.vtk}
Expand Down
1 change: 1 addition & 0 deletions test/Input/brainweb165a10f17.mha.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aa0a1e072e0c39fb8b26a769b5a54b68
30 changes: 30 additions & 0 deletions test/formatsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,33 @@ test('Test reading a VTK legacy file', t => {
t.is(image.buffer[1000], 0, 'buffer[1000]')
})
})

test('Test reading a MetaImage file', t => {
const testFilePath = path.resolve(__dirname, '..', 'build', 'ExternalData', 'test', 'Input', 'brainweb165a10f17.mha')
return readImageLocalFile(testFilePath).then(function (image) {
t.is(image.imageType.dimension, 3, 'dimension')
t.is(image.imageType.componentType, IntTypes.UInt8, 'componentType')
t.is(image.imageType.pixelType, PixelTypes.Scalar, 'pixelType')
t.is(image.imageType.components, 1, 'components')
t.is(image.origin[0], 0.0, 'origin[0]')
t.is(image.origin[1], 0.0, 'origin[1]')
t.is(image.origin[2], 0.0, 'origin[2]')
t.is(image.spacing[0], 1.0, 'spacing[0]')
t.is(image.spacing[1], 1.0, 'spacing[1]')
t.is(image.spacing[2], 1.0, 'spacing[2]')
t.is(image.direction.getElement(0, 0), 1.0, 'direction (0, 0)')
t.is(image.direction.getElement(0, 1), 0.0, 'direction (0, 1)')
t.is(image.direction.getElement(0, 2), 0.0, 'direction (0, 2)')
t.is(image.direction.getElement(1, 0), 0.0, 'direction (1, 0)')
t.is(image.direction.getElement(1, 1), 1.0, 'direction (1, 1)')
t.is(image.direction.getElement(1, 2), 0.0, 'direction (1, 2)')
t.is(image.direction.getElement(2, 0), 0.0, 'direction (2, 0)')
t.is(image.direction.getElement(2, 1), 0.0, 'direction (2, 1)')
t.is(image.direction.getElement(2, 2), 1.0, 'direction (2, 2)')
t.is(image.size[0], 181, 'size[0]')
t.is(image.size[1], 217, 'size[1]')
t.is(image.size[2], 180, 'size[2]')
t.is(image.buffer.length, 7069860, 'buffer.length')
t.is(image.buffer[1000], 0, 'buffer[1000]')
})
})
10 changes: 10 additions & 0 deletions test/itkExtensionToIOTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ test('png maps to itkPNGImageIOJSBinding', t => {
t.is(io, 'itkPNGImageIOJSBinding')
})

test('mha maps to itkMetaImageIOJSBinding', t => {
let io = ExtensionToIO['mha']
t.is(io, 'itkMetaImageIOJSBinding')
})

test('mhd maps to itkMetaImageIOJSBinding', t => {
let io = ExtensionToIO['mhd']
t.is(io, 'itkMetaImageIOJSBinding')
})

test('nrrd maps to itkNrrdImageIOJSBinding', t => {
let io = ExtensionToIO['nrrd']
t.is(io, 'itkNrrdImageIOJSBinding')
Expand Down

0 comments on commit a33cd55

Please sign in to comment.