UNPKG

@itk-wasm/image-io

Version:

Input and output for scientific and medical image file formats.

83 lines (67 loc) 2.12 kB
// Generated file. To retain edits, remove this comment. import { Image, JsonCompatible, InterfaceTypes, PipelineOutput, PipelineInput, runPipelineNode } from 'itk-wasm' import BioRadWriteImageNodeOptions from './bio-rad-write-image-node-options.js' import BioRadWriteImageNodeResult from './bio-rad-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 {BioRadWriteImageNodeOptions} options - options object * * @returns {Promise<BioRadWriteImageNodeResult>} - result object */ async function bioRadWriteImageNode( image: Image, serializedImage: string, options: BioRadWriteImageNodeOptions = {} ) : Promise<BioRadWriteImageNodeResult> { 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', 'bio-rad-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 bioRadWriteImageNode