// Generated file. To retain edits, remove this comment.
import { InterfaceTypes, runPipelineNode } from 'itk-wasm';
import path from 'path';
import { fileURLToPath } from 'url';
/**
 * Apply local averaging and subsample the input image.
 *
 * @param {Image} input - Input image
 * @param {DownsampleBinShrinkNodeOptions} options - options object
 *
 * @returns {Promise<DownsampleBinShrinkNodeResult>} - result object
 */
async function downsampleBinShrinkNode(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.informationOnly) {
        options.informationOnly && args.push('--information-only');
    }
    const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'downsample-bin-shrink');
    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 downsampleBinShrinkNode;
//# sourceMappingURL=downsample-bin-shrink-node.js.map