@itk-wasm/image-io
Version:
Input and output for scientific and medical image file formats.
83 lines (67 loc) • 2.09 kB
text/typescript
// Generated file. To retain edits, remove this comment.
import {
Image,
JsonCompatible,
InterfaceTypes,
PipelineOutput,
PipelineInput,
runPipelineNode
} from 'itk-wasm'
import MetaWriteImageNodeOptions from './meta-write-image-node-options.js'
import MetaWriteImageNodeResult from './meta-write-image-node-result.js'
import path from 'path'
import { fileURLToPath } from 'url'
/**
* Write an itk-wasm file format converted to an image file format
*
* @param {Image} image - Input image
* @param {string} serializedImage - Output image serialized in the file format.
* @param {MetaWriteImageNodeOptions} options - options object
*
* @returns {Promise<MetaWriteImageNodeResult>} - result object
*/
async function metaWriteImageNode(
image: Image,
serializedImage: string,
options: MetaWriteImageNodeOptions = {}
) : Promise<MetaWriteImageNodeResult> {
const mountDirs: Set<string> = new Set()
const desiredOutputs: Array<PipelineOutput> = [
{ type: InterfaceTypes.JsonCompatible },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.Image, data: image },
]
const args = []
// Inputs
const imageName = '0'
args.push(imageName)
// Outputs
const couldWriteName = '0'
args.push(couldWriteName)
const serializedImageName = serializedImage
args.push(serializedImageName)
mountDirs.add(path.dirname(serializedImageName))
// Options
args.push('--memory-io')
if (options.informationOnly) {
options.informationOnly && args.push('--information-only')
}
if (options.useCompression) {
options.useCompression && args.push('--use-compression')
}
const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'meta-write-image')
const {
returnValue,
stderr,
outputs
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs)
if (returnValue !== 0 && stderr !== "") {
throw new Error(stderr)
}
const result = {
couldWrite: outputs[0]?.data as JsonCompatible,
}
return result
}
export default metaWriteImageNode