> ## Documentation Index
> Fetch the complete documentation index at: https://imsdkdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Segmentation

Segmentation tasks differ fundamentally from classification and detection. While classification and detection models output discrete results — class labels, bounding boxes, confidence scores — segmentation models generate pixel-wise masks that delineate object boundaries within each frame. This example uses the [DeepLabV3+ MobileNet](https://aihub.qualcomm.com/iot/models/deeplabv3_plus_mobilenet) model from Qualcomm AI Hub.

<img src="https://mintcdn.com/qimsdk/xdnKhBBjxpS5mUYP/qimsdk-overview/images/img-segment1.png?fit=max&auto=format&n=xdnKhBBjxpS5mUYP&q=85&s=22f77d5320713645860a03ae06f8e7d9" alt="gst-ai-video-segmentation-new" width="2495" height="821" data-path="qimsdk-overview/images/img-segment1.png" />

For segmentation, the [`qtimlpostprocess`](../plugin-reference/qtimlpostprocess) plugin outputs an RGBA image mask rather than structured metadata. This mask is blended with the original video frame using [`qtivcomposer`](../plugin-reference/qtivcomposer) with `sink_1::alpha=0.5`. The [`qtivoverlay`](../plugin-reference/qtivoverlay) plugin is not needed for segmentation.

The order of inputs to [`qtivcomposer`](../plugin-reference/qtivcomposer) matters — the video frame must be connected first, and the segmentation mask second, so the mask is correctly composited on top.

## Run example on device

<Steps>
  <Step title="Download Required Files">
    | File                            | Download                                                                                                                                               | Save as                           |
    | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------- |
    | DeepLabV3+ MobileNet W8A8 model | [Qualcomm AI Hub — DeepLabV3+](https://aihub.qualcomm.com/iot/models/deeplabv3_plus_mobilenet)                                                         | `deeplabv3_plus_mobilenet.tflite` |
    | Segmentation labels             | <a href="../labels/dv3-argmax.json" download="dv3-argmax.json">dv3-argmax.json</a>                                                                     | `dv3-argmax.json`                 |
    | Sample video                    | <a href="https://github.com/qualcomm/sample-apps-for-qualcomm-linux/raw/refs/heads/main/qualcomm-linux/artifacts/videos/demo_samples/">Input video</a> | `ai_demo_sample.mp4`              |

    <Note>
      If any downloaded file is a `.zip` archive, extract it on your host machine before copying:
      `unzip filename.zip`
    </Note>
  </Step>

  <Step title="Copy files to device">
    Create the required directories and transfer the downloaded files to your device.

    <CodeGroup>
      ```bash SCP (SSH) theme={null}
      # Run from your host machine — replace <user> and <device-ip>
      ssh <user>@<device-ip> "mkdir -p $HOME/{models,labels,media,media/output}"
      scp deeplabv3_plus_mobilenet.tflite  <user>@<device-ip>:$HOME/models/
      scp dv3-argmax.json                   <user>@<device-ip>:$HOME/labels/
      scp ai_demo_sample.mp4                         <user>@<device-ip>:$HOME/media/
      ```
    </CodeGroup>
  </Step>

  <Step title="Connect to device">
    <CodeGroup>
      ```bash SCP (SSH) theme={null}
      ssh <user>@<device-ip>
      ```
    </CodeGroup>
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export MODEL_NAME=deeplabv3_plus_mobilenet.tflite
    export LABELS_NAME=dv3-argmax.json
    export SRC_VIDEO_NAME=ai_demo_sample.mp4
    export VIDEO_SOURCE="filesrc location=$HOME/media/$SRC_VIDEO_NAME ! qtdemux ! h264parse ! v4l2h264dec capture-io-mode=4 output-io-mode=4 ! video/x-raw,format=NV12"
    ```
  </Step>

  <Step title="Run example on device">
    <Tabs>
      <Tab title="GStreamer Command line">
        ```bash theme={null}
        gst-launch-1.0 $VIDEO_SOURCE ! \
          tee name=t \
          t. ! queue ! mixer. \
          t. ! qtimlvconverter name=preprocess ! queue ! \
               qtimltflite name=inference delegate=external \
                 external-delegate-path=libQnnTFLiteDelegate.so \
                 external-delegate-options="QNNExternalDelegate,backend_type=htp;" \
                 model=$HOME/models/$MODEL_NAME ! queue ! \
               qtimlpostprocess name=postprocess module=deeplab-argmax \
                 labels=$HOME/labels/$LABELS_NAME ! mixer. \
          qtivcomposer name=mixer sink_1::alpha=0.5 ! video/x-raw,format=NV12 ! \
          waylandsink sync=true fullscreen=true
        ```
      </Tab>

      <Tab title="GStreamer Python application">
        * **Python source code:** [gst-ai-video-segmentation.py](https://github.com/qualcomm/gst-plugins-imsdk/tree/main/gst-python-examples/gst-ai-video-segmentation.py)

        * **Run:**

          ```bash theme={null}
          python3 gst-ai-video-segmentation.py -s "$VIDEO_SOURCE" -o display
          ```
      </Tab>

      <Tab title="GStreamer C/C++ application">
        * **Application source code:** [gst-ai-video-segmentation](https://github.com/qualcomm/gst-plugins-imsdk/tree/main/gst-sample-apps/gst-ai-video-segmentation)

        * **Build your application:**

                  <Tabs>
                    <Tab title="Yocto">
                      <a href="../advanced/yocto-build#steps-to-build-custom-application">
                        Steps to build custom application
                      </a>
                    </Tab>

                    <Tab title="Ubuntu">
                      <a href="../advanced/ubuntu-build#steps-to-build-custom-application">
                        Steps to build custom application
                      </a>
                    </Tab>
                  </Tabs>

        * **Run:**

          ```bash theme={null}
          gst-ai-video-segmentation -s "$VIDEO_SOURCE" -o display
          ```
      </Tab>
    </Tabs>
  </Step>
</Steps>

## Expected output

The segmentation mask is blended on top of the original video frame in real time.

<img src="https://mintcdn.com/qimsdk/xdnKhBBjxpS5mUYP/qimsdk-overview/images/image-segmentation-background.jpg?fit=max&auto=format&n=xdnKhBBjxpS5mUYP&q=85&s=e0da04cd6ebd22b977ae9a77def1cafe" alt="image-segmentation-background" width="1060" height="706" data-path="qimsdk-overview/images/image-segmentation-background.jpg" />
