def METHOD_NAME(file):
    from .prepare_data_utils import extract_roi
    logger.debug(f"  Processing of {file}.")
    container = container_from_filename(file)
    subfolder = "roi_based"
    if parameters["preprocessing"] == "custom":
        if not parameters["roi_custom_template"]:
            raise ClinicaDLArgumentError(
                "A custom template must be defined when the modality is set to custom."
            )
        parameters["roi_template"] = parameters["roi_custom_template"]
        parameters["roi_mask_pattern"] = parameters["roi_custom_mask_pattern"]
    else:
        from .prepare_data_utils import PATTERN_DICT, TEMPLATE_DICT
        parameters["roi_template"] = TEMPLATE_DICT[parameters["preprocessing"]]
        parameters["roi_mask_pattern"] = PATTERN_DICT[
            parameters["preprocessing"]
        ]
    parameters["masks_location"] = (
        caps_directory / "masks" / f"tpl-{parameters['roi_template']}"
    )
    if len(parameters["roi_list"]) == 0:
        raise ClinicaDLArgumentError(
            "A list of regions of interest must be given."
        )
    else:
        check_mask_list(
            parameters["masks_location"],
            parameters["roi_list"],
            parameters["roi_mask_pattern"],
            None
            if parameters["use_uncropped_image"] is None
            else not parameters["use_uncropped_image"],
        )
    output_mode = extract_roi(
        Path(file),
        masks_location=parameters["masks_location"],
        mask_pattern=parameters["roi_mask_pattern"],
        cropped_input=None
        if parameters["use_uncropped_image"] is None
        else not parameters["use_uncropped_image"],
        roi_names=parameters["roi_list"],
        uncrop_output=parameters["uncropped_roi"],
    )
    logger.debug(f"    ROI extracted.")
    write_output_imgs(output_mode, container, subfolder)