---
title: "remove-background"
description: "## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#overview](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#overview)Overview This example shows you how to remove the background of an image using depth camera with range filter. ## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#expect-output](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#expect-output)Expect Output ![rbg1 1 | LIPS® Developer Documentation](https://dev.lips-hci.com/wp-content/uploads/2025/02/rbg1-1.avif) ## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#prerequisite](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#prerequisite)Prerequisite - [OpenCV Viewer](https://github.com/lips-marketing/lips_gitbook_dev/blob/master/sdk-code-samples-and-languages-wrappers/openni2/opencv_viewer/README.md) - [Align Depth & Color](https://github.com/lips-marketing/lips_gitbook_dev/blob/master/sdk-code-samples-and-languages-wrappers/openni2/align-depth-color/README.md) -…"
url: "https://dev.lips-hci.com/lipsedge-sdk-python/python-remove-background/"
updated: "2025-06-30"
category: "LIPSedge™ SDK 1.x / LIPSedge™ SDK Languages & Libraries / Python"
tags:
  - LIPSedge SDK
---

# remove-background

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#overview](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#overview)Overview

This example shows you how to remove the background of an image using depth camera with range filter.

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#expect-output](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#expect-output)Expect Output

![rbg1 1 | LIPS® Developer Documentation](https://dev.lips-hci.com/wp-content/uploads/2025/02/rbg1-1.avif)

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#prerequisite](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#prerequisite)Prerequisite

- [OpenCV Viewer](https://github.com/lips-marketing/lips_gitbook_dev/blob/master/sdk-code-samples-and-languages-wrappers/openni2/opencv_viewer/README.md)
- [Align Depth & Color](https://github.com/lips-marketing/lips_gitbook_dev/blob/master/sdk-code-samples-and-languages-wrappers/openni2/align-depth-color/README.md)
- [Range Filter](https://github.com/lips-marketing/lips_gitbook_dev/blob/master/sdk-code-samples-and-languages-wrappers/openni2/range-filter/README.md)

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#tutorial](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#tutorial)Tutorial

Modify from [range-filter](https://github.com/lips-marketing/lips_gitbook_dev/blob/master/sdk-code-samples-and-languages-wrappers/openni2/range-filter/README.md), we add two variables to determinate the desired distance. Then add two keyboard shorcut to set these values.

```
thresholdValueUp = 530
thresholdValueDown = 385

input = cv2.waitKey(1)
if input == ord('p'):
    if thresholdValueUp + 5 <= 2000:
        thresholdValueUp += 5
    else:
        thresholdValueUp = 2000
    print(f"Threshold Value (Up): {thresholdValueUp} (Down): {thresholdValueDown}")

elif input == ord('o'):
    if thresholdValueUp - 5 >= 0 and thresholdValueUp - 5 >= thresholdValueDown:
        thresholdValueUp -= 5
    print(f"Threshold Value (Up): {thresholdValueUp} (Down): {thresholdValueDown}")

elif input == ord('x'):
    if thresholdValueDown + 5 <= 2000 and thresholdValueDown + 5 <= thresholdValueUp:
        thresholdValueDown += 5
    print(f"Threshold Value (Up): {thresholdValueUp} (Down): {thresholdValueDown}")

elif input == ord('z'):
    if thresholdValueDown - 5 >= 0:
        thresholdValueDown -= 5
    else:
        thresholdValueDown = 0
    print(f"Threshold Value (Up): {thresholdValueUp} (Down): {thresholdValueDown}")

elif input == ord('q'):
    break
```

Using these two values to create range filter mask image like we did before.

```
 _, thres = cv2.threshold(thres, thresholdValueDown, 1024, cv2.THRESH_TOZERO)
_, thres = cv2.threshold(thres, thresholdValueUp, 1024, cv2.THRESH_TOZERO_INV)
_, thres = cv2.threshold(thres, 1, 1024, cv2.THRESH_BINARY)
```

Then we use OpenCV `bitwise_and` operation on the color image and the mask. We also need to convert the mask to `CV_8UC1` because that the format needed by `bitwise_and`. Finally we will get the result image that remove the background.

```
thres = cv2.convertScaleAbs(thres, alpha=255.0 / 1024.0)
res = cv2.bitwise_and(rgbMat, rgbMat, mask=thres)
```

## [https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#full-code](https://dev.lips-hci.com/lipsedge-tm-sdk-languages-and-libraries/overview-1/remove-background#full-code)Full code

[remove-background.py](https://github.com/lips-hci/dev-doc-code-samples/blob/master/python/opencv_viewer/remove-background.py)
