### C++ TorchScript Inference Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Perform TorchScript inference using C++. This example shows how to load a TorchScript model and run inference with it. ```cpp // C++ TorchScript inference #include int main() { auto device = torch::Device("cuda"); auto precision = torch::kFloat16; auto model = torch::jit::load("torchscript_model.pth"); model.setattr("backbone_scale", 0.25); model.setattr("refine_mode", "sampling"); model.setattr("refine_sample_pixels", 80000); model.to(device); auto src = torch::rand({1, 3, 1080, 1920}).to(device).to(precision); auto bgr = torch::rand({1, 3, 1080, 1920}).to(device).to(precision); auto outputs = model.forward({src, bgr}).toTuple()->elements(); auto pha = outputs[0].toTensor(); auto fgr = outputs[1].toTensor(); } ``` -------------------------------- ### Launch Webcam Interactive Demo Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Launch the real-time interactive matting demo using your webcam. Press 'B' to capture background and 'Q' to quit. ```bash # Launch webcam demo python inference_webcam.py \ --model-type mattingrefine \ --model-backbone resnet50 \ --model-backbone-scale 0.25 \ --model-refine-mode sampling \ --model-refine-sample-pixels 80000 \ --model-checkpoint "checkpoint/mattingrefine-resnet50.pth" \ --resolution 1280 720 ``` -------------------------------- ### Training Configuration Notes Source: https://github.com/peterl1n/backgroundmattingv2/blob/master/README.md This section provides notes on configuring the training process. It suggests setting the 'data_path.pth' to point to the dataset and mentions two training strategies: training the base model first, then the entire network, or training the entire network end-to-end. ```text Configure `data_path.pth` to point to your dataset. The original paper uses `train_base.pth` to train only the base model till convergence then use `train_refine.pth` to train the entire network end-to-end. More details are specified in the paper. ``` -------------------------------- ### Webcam Demo with MobileNetV2 for Faster Inference Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Run the webcam demo using MobileNetV2 for faster inference. This configuration is suitable for real-time applications where performance is critical. ```bash # With MobileNetV2 for faster inference python inference_webcam.py \ --model-type mattingrefine \ --model-backbone mobilenetv2 \ --model-backbone-scale 0.25 \ --model-refine-mode sampling \ --model-refine-sample-pixels 80000 \ --model-checkpoint "checkpoint/mattingrefine-mobilenetv2.pth" \ --resolution 1920 1080 \ --hide-fps ``` -------------------------------- ### Basic Video Matting to Video Output Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Use this command to perform background matting on a video and output the result as a video file. Specify input video, background image, and output directory. ```bash python inference_video.py \ --model-type mattingrefine \ --model-backbone resnet50 \ --model-backbone-scale 0.25 \ --model-refine-mode sampling \ --model-refine-sample-pixels 80000 \ --model-checkpoint "checkpoint/mattingrefine-resnet50.pth" \ --video-src "input/video.mp4" \ --video-bgr "input/background.jpg" \ --output-dir "output/" \ --output-types com pha fgr \ --output-format video \ --device cuda ``` -------------------------------- ### Initialize and Run MattingRefine Model Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Initializes the MattingRefine model with specified configurations for backbone, downsampling scale, and refinement mode. Input tensors must be divisible by 4. Recommended settings for HD and 4K resolutions are provided. ```python import torch from model import MattingRefine # Initialize refine model with configuration model = MattingRefine( backbone='resnet50', # Options: 'resnet50', 'resnet101', 'mobilenetv2' backbone_scale=0.25, # Downsample scale for backbone (default: 0.25 for HD) refine_mode='sampling', # Options: 'sampling', 'thresholding', 'full' refine_sample_pixels=80_000, # Fixed pixels to refine (sampling mode) refine_threshold=0.1, # Error threshold (thresholding mode) refine_kernel_size=3 # Refiner conv kernel size: 1 or 3 ) model.load_state_dict(torch.load('checkpoint.pth')) model = model.cuda().eval() # Prepare inputs (must be divisible by 4) src = torch.rand(1, 3, 1080, 1920).cuda() bgr = torch.rand(1, 3, 1080, 1920).cuda() with torch.no_grad(): pha, fgr, pha_sm, fgr_sm, err_sm, ref_sm = model(src, bgr) # pha, fgr: full resolution outputs # pha_sm, fgr_sm, err_sm: coarse resolution intermediates # ref_sm: refinement map showing which 4x4 patches were refined # For inference, only alpha and foreground are needed pha, fgr = model(src, bgr)[:2] # Recommended settings: # HD (1080p): backbone_scale=0.25, refine_sample_pixels=80000 # 4K (2160p): backbone_scale=0.125, refine_sample_pixels=320000 ``` -------------------------------- ### Initialize and Run MattingBase Model Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Initializes the MattingBase model, loads weights, and performs inference to generate alpha matte, foreground, error map, and hidden encoding. Ensure input tensors are normalized to 0-1. ```python import torch from model import MattingBase # Initialize base model with backbone choice model = MattingBase(backbone='resnet50') # Options: 'resnet50', 'resnet101', 'mobilenetv2' model.load_state_dict(torch.load('checkpoint.pth')) model = model.cuda().eval() # Prepare input tensors (normalized to 0-1) src = torch.rand(1, 3, 1080, 1920).cuda() # Source image with subject bgr = torch.rand(1, 3, 1080, 1920).cuda() # Background image without subject # Run inference with torch.no_grad(): pha, fgr, err, hid = model(src, bgr) # pha: (B, 1, H, W) alpha matte normalized 0-1 # fgr: (B, 3, H, W) foreground RGB normalized 0-1 # err: (B, 1, H, W) error prediction normalized 0-1 # hid: (B, 32, H, W) hidden encoding for refiner # Composite foreground onto new background new_bgr = torch.rand(1, 3, 1080, 1920).cuda() composite = pha * fgr + (1 - pha) * new_bgr ``` -------------------------------- ### Video Matting with Resize and Custom Background Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Perform video matting with custom background, resizing, and outputting as image sequences. This is useful for advanced video editing workflows. ```bash python inference_video.py \ --model-type mattingrefine \ --model-backbone resnet50 \ --model-backbone-scale 0.25 \ --model-refine-mode sampling \ --model-refine-sample-pixels 80000 \ --model-checkpoint "checkpoint/mattingrefine-resnet50.pth" \ --video-src "input/video.mp4" \ --video-bgr "input/background.jpg" \ --video-target-bgr "input/new_background.mp4" \ --video-resize 1920 1080 \ --output-dir "output/" \ --output-types com \ --output-format image_sequences \ --preprocess-alignment ``` -------------------------------- ### BackgroundMattingV2 Model Configuration and Usage Source: https://github.com/peterl1n/backgroundmattingv2/blob/master/doc/model_usage.md This section describes the configurable arguments for the BackgroundMattingV2 model, its expected input formats, and the structure of its outputs. It also provides guidance on compositing the foreground and background. ```APIDOC ## BackgroundMattingV2 Model Details ### Description This section outlines the parameters, inputs, and outputs for the BackgroundMattingV2 model. ### Model Arguments #### `backbone_scale` * **Type**: float * **Default**: 0.25 * **Description**: The downsampling scale for the backbone. For example, with an input resolution of 1920x1080 and `backbone_scale=0.25`, the backbone operates on 480x270 resolution. #### `refine_mode` * **Type**: string * **Default**: `sampling` * **Options**: [`sampling`, `thresholding`, `full`] * **Description**: Mode of refinement. * `sampling`: Sets a fixed maximum number of pixels to refine (`refine_sample_pixels`). Suitable for live applications with fixed computation and memory constraints per frame. * `thresholding`: Dynamically refines pixels with errors above a threshold (`refine_threshold`). Suitable for image editing applications where quality is prioritized over speed. * `full`: Refines the entire image. Primarily for debugging. #### `refine_sample_pixels` * **Type**: int * **Default**: 80,000 * **Description**: The fixed number of pixels to refine. Used in `sampling` mode. #### `refine_threshold` * **Type**: float * **Default**: 0.1 * **Description**: The threshold for refinement. Used in `thresholding` mode. #### `prevent_oversampling` * **Type**: bool * **Default**: true * **Description**: Used only in `sampling` mode. If false, it refines unnecessary pixels to enforce refining `refine_sample_pixels` amount of pixels. Used for speed testing. ### Model Inputs * **`src`** (B, 3, H, W): The source image with RGB channels normalized to 0 ~ 1. * **`bgr`** (B, 3, H, W): The background image with RGB channels normalized to 0 ~ 1. ### Model Outputs * **`pha`** (B, 1, H, W): The alpha matte normalized to 0 ~ 1. (Primary output) * **`fgr`** (B, 3, H, W): The foreground with RGB channels normalized to 0 ~ 1. (Primary output) * **`pha_sm`** (B, 1, Hc, Wc): The coarse alpha matte normalized to 0 ~ 1. * **`fgr_sm`** (B, 3, Hc, Wc): The coarse foreground with RGB channels normalized to 0 ~ 1. * **`err_sm`** (B, 1, Hc, Wc): The coarse error prediction map normalized to 0 ~ 1. * **`ref_sm`** (B, 1, H/4, W/4): The refinement regions, where 1 denotes a refined 4x4 patch. ### Usage Recommendation * For HD resolutions: `backbone_scale=0.25`, `refine_sample_pixels=80000`. * For 4K resolutions: `backbone_scale=0.125`, `refine_sample_pixels=320000`. ### Compositing To composite the foreground onto a new background, use the formula: `com = pha * fgr + (1 - pha) * bgr`. ``` -------------------------------- ### Load and Run TorchScript Model in Python Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Load a TorchScript model and configure its parameters at runtime using Python. This snippet demonstrates inference with the loaded model. ```python import torch # Load TorchScript model (no source code needed) model = torch.jit.load('torchscript_model.pth') # Configure model parameters at runtime model.backbone_scale = 0.25 model.refine_mode = 'sampling' model.refine_sample_pixels = 80_000 model.refine_threshold = 0.1 model = model.cuda() # Run inference src = torch.rand(1, 3, 1080, 1920).cuda().half() bgr = torch.rand(1, 3, 1080, 1920).cuda().half() pha, fgr = model(src, bgr)[:2] ``` -------------------------------- ### Train MattingBase Model Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Trains the MattingBase model. Supports pretrained DeepLabV3 initialization and mixed precision. Use `--model-pretrain-initialization` for pretrained weights or `--model-last-checkpoint` to resume training. ```bash CUDA_VISIBLE_DEVICES=0 python train_base.py \ --dataset-name videomatte240k \ --model-backbone resnet50 \ --model-name mattingbase-resnet50-videomatte240k \ --model-pretrain-initialization "pretraining/best_deeplabv3_resnet50_voc_os16.pth" \ --batch-size 8 \ --num-workers 16 \ --epoch-start 0 \ --epoch-end 8 \ --log-train-loss-interval 10 \ --log-train-images-interval 2000 \ --log-valid-interval 5000 \ --checkpoint-interval 5000 ``` ```bash CUDA_VISIBLE_DEVICES=0,1 python train_base.py \ --dataset-name photomatte85 \ --model-backbone mobilenetv2 \ --model-name mattingbase-mobilenetv2-photomatte85 \ --model-last-checkpoint "checkpoint/mattingbase-mobilenetv2/epoch-4.pth" \ --batch-size 16 \ --epoch-start 5 \ --epoch-end 10 ``` -------------------------------- ### PyTorch Inference with MattingRefine Source: https://github.com/peterl1n/backgroundmattingv2/blob/master/doc/model_usage.md Use this snippet for research purposes with the PyTorch backend. Ensure the MattingRefine model and checkpoint are correctly loaded. ```python import torch from model import MattingRefine device = torch.device('cuda') precision = torch.float32 model = MattingRefine(backbone='mobilenetv2', backbone_scale=0.25, refine_mode='sampling', refine_sample_pixels=80_000) model.load_state_dict(torch.load('PATH_TO_CHECKPOINT.pth')) model = model.eval().to(precision).to(device) src = torch.rand(1, 3, 1080, 1920).to(precision).to(device) bgr = torch.rand(1, 3, 1080, 1920).to(precision).to(device) with torch.no_grad(): pha, fgr = model(src, bgr)[:2] ``` -------------------------------- ### Inference Speed Test Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Benchmarks model throughput. Use `--model-type mattingrefine` for the refine model. Specify `--image-src` and `--image-bgr` for real image tests. ```bash python inference_speed_test.py \ --model-type mattingrefine \ --model-backbone resnet50 \ --model-backbone-scale 0.25 \ --model-refine-mode sampling \ --model-refine-sample-pixels 80000 \ --batch-size 1 \ --resolution 1920 1080 \ --backend pytorch \ --precision float32 \ --device cuda ``` ```bash python inference_speed_test.py \ --model-type mattingrefine \ --model-backbone mobilenetv2 \ --model-backbone-scale 0.25 \ --model-checkpoint "checkpoint/mattingrefine-mobilenetv2.pth" \ --model-refine-mode thresholding \ --model-refine-threshold 0.7 \ --batch-size 1 \ --backend torchscript \ --precision float16 \ --image-src "test/src.jpg" \ --image-bgr "test/bgr.jpg" ``` -------------------------------- ### MattingRefine Configuration - Full Mode Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Configures the MattingRefine model for full refinement, primarily for debugging purposes. This mode refines all pixels. ```python from model import MattingRefine # Full mode: Refine everything, only for debugging model = MattingRefine( backbone='resnet50', backbone_scale=0.25, refine_mode='full' ) ``` -------------------------------- ### Image Matting Inference Script Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Command-line script for batch processing images. Supports basic matting and advanced options like homographic alignment preprocessing. Specify model type, backbone, refinement settings, input/output paths, and device. ```bash python inference_images.py \ --model-type mattingrefine \ --model-backbone resnet50 \ --model-backbone-scale 0.25 \ --model-refine-mode sampling \ --model-refine-sample-pixels 80000 \ --model-checkpoint "checkpoint/mattingrefine-resnet50.pth" \ --images-src "input/src/" \ --images-bgr "input/bgr/" \ --output-dir "output/" \ --output-types com fgr pha \ --device cuda ``` ```bash python inference_images.py \ --model-type mattingrefine \ --model-backbone mobilenetv2 \ --model-backbone-scale 0.25 \ --model-refine-mode thresholding \ --model-refine-threshold 0.1 \ --model-checkpoint "checkpoint/mattingrefine-mobilenetv2.pth" \ --images-src "input/src/" \ --images-bgr "input/bgr/" \ --output-dir "output/" \ --output-types com pha fgr err ref \ --preprocess-alignment \ -y # Auto-confirm overwrite ``` -------------------------------- ### Export Model to TorchScript Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Export the trained model to TorchScript format for production deployment. The exported model can be configured at runtime. ```bash # Export to TorchScript python export_torchscript.py \ --model-backbone resnet50 \ --model-checkpoint "checkpoint/mattingrefine-resnet50.pth" \ --precision float32 \ --output "torchscript_model.pth" ``` -------------------------------- ### MattingRefine Configuration - Thresholding Mode Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Configures the MattingRefine model for thresholding mode, suitable for quality-focused applications. Pixels with an error greater than `refine_threshold` will be refined. ```python from model import MattingRefine # Thresholding mode: Dynamic computation, ideal for quality-focused applications model = MattingRefine( backbone='resnet50', backbone_scale=0.25, refine_mode='thresholding', refine_threshold=0.1 # Refine pixels with error > 0.1 ) ``` -------------------------------- ### MattingRefine Configuration - ONNX Compatibility Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Configures the MattingRefine model for ONNX compatibility. Uses `roi_align` and `scatter_element` for better compatibility with ONNX runtimes. ```python from model import MattingRefine # ONNX-compatible configuration model = MattingRefine( backbone='mobilenetv2', backbone_scale=0.25, refine_mode='sampling', refine_sample_pixels=80_000, refine_kernel_size=3, refine_patch_crop_method='roi_align', # Better ONNX compat than 'unfold' refine_patch_replace_method='scatter_element' # Better ONNX compat than 'scatter_nd' ) ``` -------------------------------- ### MattingRefine Configuration - Sampling Mode Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Configures the MattingRefine model for sampling mode, suitable for real-time applications. `refine_prevent_oversampling` can be set to `True` to avoid sampling when error is low. ```python from model import MattingRefine # Sampling mode: Fixed computation, ideal for real-time applications model = MattingRefine( backbone='resnet50', backbone_scale=0.25, refine_mode='sampling', refine_sample_pixels=80_000, # Refine top 80k error pixels refine_prevent_oversampling=True # Don't sample when error is low ) ``` -------------------------------- ### Train MattingRefine Model Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Trains the MattingRefine model end-to-end. Requires a trained base model specified by `--model-last-checkpoint`. ```bash CUDA_VISIBLE_DEVICES=0 python train_refine.py \ --dataset-name videomatte240k \ --model-backbone resnet50 \ --model-name mattingrefine-resnet50-videomatte240k \ --model-last-checkpoint "checkpoint/mattingbase-resnet50-videomatte240k/epoch-7.pth" \ --batch-size 4 \ --num-workers 16 \ --epoch-start 0 \ --epoch-end 4 \ --log-train-loss-interval 10 \ --log-train-images-interval 2000 \ --log-valid-interval 5000 \ --checkpoint-interval 5000 ``` -------------------------------- ### Inference Speed Test Script Source: https://github.com/peterl1n/backgroundmattingv2/blob/master/README.md This script measures the tensor throughput of the background matting model. It is useful for understanding the model's performance and potential for real-time applications. ```python import torch from model import MattingNetwork model = MattingNetwork() model.load_state_dict(torch.load("train_refine.pth")) model.eval() input_tensor = torch.randn(1, 4, 256, 256) with torch.no_grad(): output = model(input_tensor) print(output.shape) ``` -------------------------------- ### Video Inference Script Source: https://github.com/peterl1n/backgroundmattingv2/blob/master/README.md This script performs matting on a video file. Note that the video encoding and decoding are not hardware-accelerated or parallelized in this script, so it may not be real-time. For production use, additional engineering for hardware acceleration and parallel processing is recommended. ```python import cv2 import torch from model import MattingNetwork from util import imtrim, imdenormalize model = MattingNetwork() model.load_state_dict(torch.load("train_refine.pth")) model.eval() cap = cv2.VideoCapture("input.mp4") fps = cap.get(cv2.CAP_PROP_FPS) width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fourcc = cv2.VideoWriter_fourcc(*"mp4v") out = cv2.VideoWriter("output.mp4", fourcc, fps, (width, height)) while cap.isOpened(): ret, frame = cap.read() if not ret: break # Convert frame to tensor and normalize frame_tensor = torch.from_numpy(frame.astype(np.float32) / 255.0).permute(2, 0, 1).unsqueeze(0) with torch.no_grad(): # Perform matting # For simplicity, assuming background is not provided and using a dummy background # In a real scenario, you would capture or provide a background image dummy_background = torch.zeros_like(frame_tensor) merged_input = torch.cat((frame_tensor, dummy_background), dim=1) alpha = model(merged_input) # Convert alpha matte to image and composite alpha_np = alpha.squeeze().cpu().numpy() alpha_img = (alpha_np * 255).astype(np.uint8) # Composite with a green screen background for visualization green_screen = np.zeros_like(frame) green_screen[:] = (0, 255, 0) # Green color composited_frame = cv2.convertScaleAbs(frame * alpha_img[:, :, None] + green_screen * (1 - alpha_img[:, :, None])) out.write(composited_frame) cap.release() out.release() cv2.destroyAllWindows() ``` -------------------------------- ### Export Model to ONNX with Validation Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Export the model to ONNX format with validation. This command uses specific patch cropping and replacement methods for backend compatibility. ```bash # Export to ONNX with validation python export_onnx.py \ --model-type mattingrefine \ --model-checkpoint "checkpoint/mattingrefine-resnet50.pth" \ --model-backbone resnet50 \ --model-backbone-scale 0.25 \ --model-refine-mode sampling \ --model-refine-sample-pixels 80000 \ --model-refine-patch-crop-method roi_align \ --model-refine-patch-replace-method scatter_element \ --onnx-opset-version 12 \ --onnx-constant-folding \ --precision float32 \ --output "model.onnx" \ --validate ``` -------------------------------- ### Export ONNX for Thresholding Mode Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Export the model to ONNX in thresholding mode for better compatibility with some backends. This configuration uses MobileNetV2 and float16 precision. ```bash # For thresholding mode (better compatibility with some backends) python export_onnx.py \ --model-type mattingrefine \ --model-checkpoint "checkpoint/mattingrefine-mobilenetv2.pth" \ --model-backbone mobilenetv2 \ --model-backbone-scale 0.125 \ --model-refine-mode thresholding \ --model-refine-threshold 0.1 \ --model-refine-patch-crop-method gather \ --model-refine-patch-replace-method scatter_nd \ --onnx-opset-version 11 \ --precision float16 \ --output "model_4k.onnx" \ --validate ``` -------------------------------- ### TorchScript C++ Inference Source: https://github.com/peterl1n/backgroundmattingv2/blob/master/doc/model_usage.md Perform inference with a TorchScript model in a C++ environment. This requires the torch/script.h header and a compiled TorchScript model file. ```cpp #include int main() { auto device = torch::Device("cuda"); auto precision = torch::kFloat16; auto model = torch::jit::load("PATH_TO_MODEL.pth"); model.setattr("backbone_scale", 0.25); model.setattr("refine_mode", "sampling"); model.setattr("refine_sample_pixels", 80000); model.to(device); auto src = torch::rand({1, 3, 1080, 1920}).to(device).to(precision); auto bgr = torch::rand({1, 3, 1080, 1920}).to(device).to(precision); auto outputs = model.forward({src, bgr}).toTuple()->elements(); auto pha = outputs[0].toTensor(); auto fgr = outputs[1].toTensor(); } ``` -------------------------------- ### TorchScript Python Inference Source: https://github.com/peterl1n/backgroundmattingv2/blob/master/doc/model_usage.md Run inference using a TorchScript model in Python. This method bundles the model architecture and weights, requiring only the model file. ```python import torch device = torch.device('cuda') precision = torch.float16 model = torch.jit.load('PATH_TO_MODEL.pth') model.backbone_scale = 0.25 model.refine_mode = 'sampling' model.refine_sample_pixels = 80_000 model = model.to(device) src = torch.rand(1, 3, 1080, 1920).to(precision).to(device) bgr = torch.rand(1, 3, 1080, 1920).to(precision).to(device) pha, fgr = model(src, bgr)[:2] ``` -------------------------------- ### ONNX Runtime Inference Source: https://github.com/peterl1n/backgroundmattingv2/blob/master/doc/model_usage.md Execute inference using an ONNX model with ONNX Runtime in Python. This requires the ONNX model file and numpy for input data preparation. ```python import onnxruntime import numpy as np sess = onnxruntime.InferenceSession('PATH_TO_MODEL.onnx') src = np.random.normal(size=(1, 3, 1080, 1920)).astype(np.float32) bgr = np.random.normal(size=(1, 3, 1080, 1920)).astype(np.float32) pha, fgr = sess.run(['pha', 'fgr'], {'src': src, 'bgr': bgr}) ``` -------------------------------- ### Composite onto New Background Source: https://context7.com/peterl1n/backgroundmattingv2/llms.txt Composites a foreground with a new background using alpha and foreground masks. Ensure `pha` and `fgr` are pre-computed. ```python new_bgr = np.random.normal(size=(1, 3, 1080, 1920)).astype(np.float32) composite = pha * fgr + (1 - pha) * new_bgr ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.