// Generated file. To retain edits, remove this comment.
import { InterfaceTypes, runPipelineNode } from 'itk-wasm';
import path from 'path';
import { fileURLToPath } from 'url';
/**
 * Subsample the input label image a according to weighted voting of local labels.
 *
 * @param {Image} input - Input image
 * @param {DownsampleLabelImageNodeOptions} options - options object
 *
 * @returns {Promise<DownsampleLabelImageNodeResult>} - result object
 */
async function downsampleLabelImageNode(input, options = { shrinkFactors: [2, 2], }) {
    const desiredOutputs = [
        { type: InterfaceTypes.Image },
    ];
    const inputs = [
        { type: InterfaceTypes.Image, data: input },
    ];
    const args = [];
    // Inputs
    const inputName = '0';
    args.push(inputName);
    // Outputs
    const downsampledName = '0';
    args.push(downsampledName);
    // Options
    args.push('--memory-io');
    if (options.shrinkFactors) {
        if (options.shrinkFactors.length < 2) {
            throw new Error('"shrink-factors" option must have a length > 2');
        }
        args.push('--shrink-factors');
        options.shrinkFactors.forEach((value) => {
            args.push(value.toString());
        });
    }
    if (options.cropRadius) {
        if (options.cropRadius.length < 2) {
            throw new Error('"crop-radius" option must have a length > 2');
        }
        args.push('--crop-radius');
        options.cropRadius.forEach((value) => {
            args.push(value.toString());
        });
    }
    const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'downsample-label-image');
    const { returnValue, stderr, outputs } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs);
    if (returnValue !== 0 && stderr !== "") {
        throw new Error(stderr);
    }
    const result = {
        downsampled: outputs[0]?.data,
    };
    return result;
}
export default downsampleLabelImageNode;
//# sourceMappingURL=downsample-label-image-node.js.map