Estimates the portrait alpha channel with three output ports: out is the structured result (alpha + backend info), mask the 0-255 gray mask, and cutout the RGBA transparent cutout (alpha passthrough, background transparent). Alpha is bilinearly rescaled back to the input size. backend semantics match face_detect: MediaPipe (selfie segmenter) first, MNN (MODNet) fallback.

Module:Image matting · Task type:matting

Ports

Inputs

PortTypeRequired
inImage / cv::Mat✓

Outputs

PortTypeRequired
outImage / cv::Mat—
maskImage / cv::Mat—
cutoutImage / cv::Mat—

Parameters

参数类型默认值范围 / 选项说明
backendenum0Auto / MediaPipe / MNNinference backend; Auto degrades gracefully (MediaPipe → MNN)
model_pathstring(空)shown conditionally on backend。
delegateenum0CPU / GPU*shown conditionally on backend。*MediaPipe inference delegate (CPU / GPU)
deviceenum2CPU / Metal / Auto*shown conditionally on backend。*MNN device (CPU / Metal / Auto)
threadsint4[1, 16]*shown conditionally on backend。*CPU inference threads

Example graph

A minimal runnable pipeline (read → process → write). Drag it into GraphStudio or open via --open; replace data/test.png with a real path.

{
  "version": "2.0",
  "tasks": [
    {
      "id": "read",
      "type": "opencv_image_read",
      "params": {
        "file_path": "data/test.png"
      }
    },
    {
      "id": "node",
      "type": "matting",
      "params": {
        "backend": 0,
        "delegate": 0,
        "device": 2,
        "threads": 4
      }
    },
    {
      "id": "save1",
      "type": "opencv_image_write",
      "params": {
        "file_path": "out_out.png"
      }
    },
    {
      "id": "save2",
      "type": "opencv_image_write",
      "params": {
        "file_path": "out_mask.png"
      }
    },
    {
      "id": "save3",
      "type": "opencv_image_write",
      "params": {
        "file_path": "out_cutout.png"
      }
    }
  ],
  "edges": [
    {
      "from": "read",
      "from_port": "out",
      "to": "node",
      "to_port": "in"
    },
    {
      "from": "node",
      "from_port": "out",
      "to": "save1",
      "to_port": "in"
    },
    {
      "from": "node",
      "from_port": "mask",
      "to": "save2",
      "to_port": "in"
    },
    {
      "from": "node",
      "from_port": "cutout",
      "to": "save3",
      "to_port": "in"
    }
  ]
}

Notes

  • cutout feeds gpu_alpha_composite directly (in) over a background (in2) for final compositing.
  • Both backends agree on foreground coverage for standard portraits (within ~0.1%).
  • TG_MATTING_DEBUG=1 enables MNN diagnostics.

Part of the GraphStudio node guide series; parameters reflect the latest release.