-
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.
feat(image-io): add writeImage function
- Loading branch information
Showing
44 changed files
with
499 additions
and
85 deletions.
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
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
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
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
96 changes: 96 additions & 0 deletions
96
packages/image-io/typescript/cypress/e2e/write-image.cy.ts
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,96 @@ | ||
import { demoServer } from './common.ts' | ||
|
||
import { IntTypes, PixelTypes } from 'itk-wasm' | ||
|
||
const cthead1SmallBase64DataURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAAAAABWESUoAAAABGdBTUEAAL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Cl5if38q9FGV+CeAaFuK4OZY5nLRoksnsPX19nL5do2GsREoAlCtr68lo4VoXNROWdXD8j7GUNV96AMPye5MtYgU/ujF/887tHy+PXLt9o9/asUipvDfWpc1QNFWKPfla8PHI5Ysnsua2l2dH1Un7WS6rKlamxx9f/MKKhkX1syoxmLqcUMVRDTNMlZGkilPsUrOsJ6wxRSel/wuAkzbenLRf4gAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wNS0wNlQxNzoyNjozNC0wNDowMORO/MMAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDUtMDZUMTc6MjY6MzQtMDQ6MDCVE0R/AAAAAElFTkSuQmCC' | ||
const byteString = window.atob(cthead1SmallBase64DataURI.split(',')[1]) | ||
const mimeString = cthead1SmallBase64DataURI.split(',')[0].split(':')[1].split(';')[0] | ||
const intArray = new Uint8Array(byteString.length) | ||
for (let ii = 0; ii < byteString.length; ++ii) { | ||
intArray[ii] = byteString.charCodeAt(ii) | ||
} | ||
const cthead1SmallBlob = new window.Blob([intArray], { type: mimeString }) | ||
|
||
function verifyImage (image, componentType, pixelType) { | ||
cy.expect(image.imageType.dimension).to.equal(2) | ||
cy.expect(image.imageType.componentType).to.equal(componentType) | ||
cy.expect(image.imageType.pixelType).to.equal(pixelType) | ||
cy.expect(image.imageType.components).to.equal(1) | ||
cy.expect(image.origin[0]).to.equal(0.0) | ||
cy.expect(image.origin[1]).to.equal(0.0) | ||
cy.expect(image.spacing[0]).to.equal(1.0) | ||
cy.expect(image.spacing[1]).to.equal(1.0) | ||
cy.expect(image.size[0]).to.equal(32) | ||
cy.expect(image.size[1]).to.equal(32) | ||
cy.expect(image.data.length).to.equal(1024) | ||
cy.expect(image.data[512]).to.equal(12) | ||
} | ||
|
||
describe('write-image', () => { | ||
beforeEach(function() { | ||
cy.visit(demoServer) | ||
|
||
const testPathPrefix = '../test/data/input/' | ||
|
||
const testImageFiles = [ | ||
'cthead1.iwi.cbor' | ||
] | ||
testImageFiles.forEach((fileName) => { | ||
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName) | ||
}) | ||
}) | ||
|
||
it('Writes an image in the demo', function () { | ||
cy.get('sl-tab[panel="writeImage-panel"]').click() | ||
|
||
const testFile = { contents: new Uint8Array(this['cthead1.iwi.cbor']), fileName: 'cthead1.iwi.cbor' } | ||
cy.get('#writeImageInputs input[name="image-file"]').selectFile([testFile,], { force: true }) | ||
cy.get('#writeImage-image-details').should('contain', 'imageType') | ||
cy.get('#writeImageInputs sl-input[name="serialized-image"]').find('input', { includeShadowDom: true }).type('cthead1.png', { force: true }) | ||
|
||
cy.get('#writeImageInputs sl-button[name="run"]').click() | ||
|
||
cy.get('#writeImage-serialized-image-details').should('contain', '0,3') | ||
}) | ||
|
||
it('Writes an image to an ArrayBuffer', function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = await cthead1SmallBlob.arrayBuffer() | ||
const { image, webWorker } = await win.imageIo.readImage(null, { data: new Uint8Array(arrayBuffer), path: 'cthead1Small.png' }) | ||
const { serializedImage } = await win.imageIo.writeImage(webWorker, image, 'cthead1.mha') | ||
const { image: imageBack } = await win.imageIo.readImage(webWorker, serializedImage) | ||
webWorker.terminate() | ||
const componentType = IntTypes.UInt8 | ||
const pixelType = PixelTypes.Scalar | ||
verifyImage(imageBack, componentType, pixelType) | ||
}) | ||
}) | ||
|
||
it('Writes an image to an ArrayBuffer, given componentType, pixelType', function () { | ||
cy.window().then(async (win) => { | ||
const componentType = IntTypes.UInt16 | ||
const pixelType = PixelTypes.Vector | ||
const arrayBuffer = await cthead1SmallBlob.arrayBuffer() | ||
const { image, webWorker } = await win.imageIo.readImage(null, { data: new Uint8Array(arrayBuffer), path: 'cthead1Small.png' }) | ||
const { serializedImage } = await win.imageIo.writeImage(webWorker, image, 'cthead1.mha', { pixelType, componentType}) | ||
// Reading back, the pixelType is always Scalar (reader behavior). Is this a bug? | ||
const { image: imageBack } = await win.imageIo.readImage(webWorker, serializedImage, { pixelType }) | ||
webWorker.terminate() | ||
verifyImage(imageBack, componentType, pixelType) | ||
}) | ||
}) | ||
|
||
it('Writes an image to an ArrayBuffer, uses compression', function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = await cthead1SmallBlob.arrayBuffer() | ||
const { image, webWorker } = await win.imageIo.readImage(null, { data: new Uint8Array(arrayBuffer), path: 'cthead1Small.png' }) | ||
const options = { useCompression: false } | ||
const { serializedImage } = await win.imageIo.writeImage(webWorker, image, 'cthead1.mha', options) | ||
const { image: imageBack } = await win.imageIo.readImage(webWorker, serializedImage) | ||
webWorker.terminate() | ||
const componentType = IntTypes.UInt8 | ||
const pixelType = PixelTypes.Scalar | ||
verifyImage(imageBack, componentType, pixelType) | ||
}) | ||
}) | ||
}) |
2 changes: 1 addition & 1 deletion
2
packages/image-io/typescript/src/bio-rad-write-image-options.ts
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
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
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
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
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
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
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
Oops, something went wrong.