@itk-wasm/image-io
Version:
Input and output for scientific and medical image file formats.
58 lines • 2.33 kB
JavaScript
// Generated file. To retain edits, remove this comment.
import { InterfaceTypes, runPipeline } from 'itk-wasm';
import { getPipelinesBaseUrl } from './pipelines-base-url.js';
import { getPipelineWorkerUrl } from './pipeline-worker-url.js';
import { getDefaultWebWorker } from './default-web-worker.js';
/**
* Read an image file format and convert it to the itk-wasm file format
*
* @param {File | BinaryFile} serializedImage - Input image serialized in the file format
* @param {GiplReadImageOptions} options - options object
*
* @returns {Promise<GiplReadImageResult>} - result object
*/
async function giplReadImage(serializedImage, options = {}) {
const desiredOutputs = [
{ type: InterfaceTypes.JsonCompatible },
{ type: InterfaceTypes.Image },
];
let serializedImageFile = serializedImage;
if (serializedImage instanceof File) {
const serializedImageBuffer = await serializedImage.arrayBuffer();
serializedImageFile = { path: serializedImage.name, data: new Uint8Array(serializedImageBuffer) };
}
const inputs = [
{ type: InterfaceTypes.BinaryFile, data: serializedImageFile },
];
const args = [];
// Inputs
const serializedImageName = serializedImageFile.path;
args.push(serializedImageName);
// Outputs
const couldReadName = '0';
args.push(couldReadName);
const imageName = '1';
args.push(imageName);
// Options
args.push('--memory-io');
if (options.informationOnly) {
options.informationOnly && args.push('--information-only');
}
const pipelinePath = 'gipl-read-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,
couldRead: outputs[0]?.data,
image: outputs[1]?.data,
};
return result;
}
export default giplReadImage;
//# sourceMappingURL=gipl-read-image.js.map