UNPKG

@itk-wasm/image-io

Version:

Input and output for scientific and medical image file formats.

91 lines (75 loc) 2.48 kB
// Generated file. To retain edits, remove this comment. import { Image, JsonCompatible, BinaryFile, InterfaceTypes, PipelineOutput, PipelineInput, runPipeline } from 'itk-wasm' import MrcWriteImageOptions from './mrc-write-image-options.js' import MrcWriteImageResult from './mrc-write-image-result.js' import { getPipelinesBaseUrl } from './pipelines-base-url.js' import { getPipelineWorkerUrl } from './pipeline-worker-url.js' import { getDefaultWebWorker } from './default-web-worker.js' /** * 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 {MrcWriteImageOptions} options - options object * * @returns {Promise<MrcWriteImageResult>} - result object */ async function mrcWriteImage( image: Image, serializedImage: string, options: MrcWriteImageOptions = {} ) : Promise<MrcWriteImageResult> { const desiredOutputs: Array<PipelineOutput> = [ { type: InterfaceTypes.JsonCompatible }, { type: InterfaceTypes.BinaryFile, data: { path: serializedImage, data: new Uint8Array() }}, ] 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) // 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 = 'mrc-write-image' let workerToUse = options?.webWorker if (workerToUse === undefined) { workerToUse = await getDefaultWebWorker() } const { webWorker: usedWebWorker, returnValue, stderr, outputs } = await runPipeline(pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl(), webWorker: workerToUse, noCopy: options?.noCopy }) if (returnValue !== 0 && stderr !== "") { throw new Error(stderr) } const result = { webWorker: usedWebWorker as Worker, couldWrite: outputs[0]?.data as JsonCompatible, serializedImage: outputs[1]?.data as BinaryFile, } return result } export default mrcWriteImage