Skip to content

Commit

Permalink
WIP: test(image-io): port HDF5 test to package
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Oct 7, 2023
1 parent 409b29e commit 8917a75
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/image-io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if(WASI)
"ITKIONRRD"
"ITKIOVTK"
"ITKIOBMP"
"ITKIOHDF5"
"ITKIOMRC"
"ITKIOLSM"
"MGHIO"
Expand Down Expand Up @@ -201,7 +202,7 @@ foreach(io_module ${WebAssemblyInterface_ImageIOModules} WebAssemblyInterface)
foreach(target ${target_esm_read} ${target_umd_read} ${target_esm_write} ${target_umd_write})
set(exception_catching )
if(${io_module} STREQUAL "ITKIOGE")
set(exception_catching " -s DISABLE_EXCEPTION_CATCHING=0")
set(exception_catching " -s DISABLE_EXCEPTION_CATCHING=0")
endif()
set(imageio_common_link_flags " -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s SUPPORT_LONGJMP=1")
get_property(link_flags TARGET ${target} PROPERTY LINK_FLAGS)
Expand Down
44 changes: 44 additions & 0 deletions packages/image-io/typescript/cypress/e2e/hdf5.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { demoServer } from './common.ts'

describe('hdf5', () => {
beforeEach(function() {
cy.visit(demoServer)

const testPathPrefix = '../test/data/input/'

const testImageFiles = [
'ITKImage.hdf5',
'ITKImage.iwi.cbor',
]
testImageFiles.forEach((fileName) => {
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName)
})
})

it('Reads a BMP image', function () {
cy.get('sl-tab[panel="bmpReadImage-panel"]').click()

const testFile = { contents: new Uint8Array(this['image_color.bmp']), fileName: 'image_color.bmp' }
cy.get('#bmpReadImageInputs input[name="serialized-image-file"]').selectFile([testFile,], { force: true })
cy.get('#bmpReadImage-serialized-image-details').should('contain', '0,3')

cy.get('#bmpReadImageInputs sl-button[name="run"]').click()

cy.get('#bmpReadImage-could-read-details').should('contain', 'true')
cy.get('#bmpReadImage-image-details').should('contain', 'imageType')
})

it('Writes a BioRad image', function () {
cy.get('sl-tab[panel="bmpWriteImage-panel"]').click()

const testFile = { contents: new Uint8Array(this['image_color.iwi.cbor']), fileName: 'image_color.iwi.cbor' }
cy.get('#bmpWriteImageInputs input[name="image-file"]').selectFile([testFile,], { force: true })
cy.get('#bmpWriteImage-image-details').should('contain', 'imageType')
cy.get('#bmpWriteImageInputs sl-input[name="serialized-image"]').find('input', { includeShadowDom: true }).type('image_color.bmp', { force: true })

cy.get('#bmpWriteImageInputs sl-button[name="run"]').click()

cy.get('#bmpWriteImage-could-write-details').should('contain', 'true')
cy.get('#bmpWriteImage-serialized-image-details').should('contain', '0,3')
})
})
38 changes: 38 additions & 0 deletions packages/image-io/typescript/test/node/hdf5-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import test from 'ava'
import path from 'path'

import { hdf5ReadImageNode } from '../../dist/bundles/image-io-node.js'
import { IntTypes, PixelTypes, getMatrixElement } from 'itk-wasm'

import { testInputPath } from './common.js'

const testInputFilePath = path.join(testInputPath, 'ITKImage.hdf5')

test('Test reading a HDF5 file', async t => {
const { couldRead, image } = await hdf5ReadImageNode(testInputFilePath)
t.true(couldRead)
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, 'origin[0]')
t.is(image.origin[1], 5, 'origin[1]')
t.is(image.origin[2], 10, 'origin[2]')
t.is(image.spacing[0], 1, 'spacing[0]')
t.is(image.spacing[1], 2, 'spacing[1]')
t.is(image.spacing[2], 3, 'spacing[2]')
t.is(getMatrixElement(image.direction, 3, 0, 0), 0.866025403784439, 'direction (0, 0)')
t.is(getMatrixElement(image.direction, 3, 0, 1), -0.5, 'direction (0, 1)')
t.is(getMatrixElement(image.direction, 3, 0, 2), 0.0, 'direction (0, 2)')
t.is(getMatrixElement(image.direction, 3, 1, 0), 0.5, 'direction (1, 0)')
t.is(getMatrixElement(image.direction, 3, 1, 1), 0.866025403784439, 'direction (1, 1)')
t.is(getMatrixElement(image.direction, 3, 1, 2), 0, 'direction (1, 2)')
t.is(getMatrixElement(image.direction, 3, 2, 0), 0.0, 'direction (2, 0)')
t.is(getMatrixElement(image.direction, 3, 2, 1), 0.0, 'direction (2, 1)')
t.is(getMatrixElement(image.direction, 3, 2, 2), 1.0, 'direction (2, 2)')
t.is(image.size[0], 5, 'size[0]')
t.is(image.size[1], 5, 'size[1]')
t.is(image.size[2], 5, 'size[2]')
t.is(image.data.length, 125, 'data.length')
t.is(image.data[10], 132, 'data[10]')
})

0 comments on commit 8917a75

Please sign in to comment.