-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: test(image-io): port HDF5 test to package
- Loading branch information
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]') | ||
}) |