# How to filter the background of an image?

**URL:** <https://forum.opencv.org/t/how-to-filter-the-background-of-an-image/10907>\
**Category:** Python\
**Created:** [November 11, 2022, 6:39am UTC](https://forum.opencv.org/t/how-to-filter-the-background-of-an-image/10907 "2022-11-11T06:39:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nigel\_Lee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/nigel_lee/32/6421_2.png) [@Nigel\_Lee](https://forum.opencv.org/u/Nigel_Lee)\
**Post date:** [November 11, 2022, 6:39am UTC](https://forum.opencv.org/t/how-to-filter-the-background-of-an-image/10907/1 "2022-11-11T06:39:24Z")

</div>

I am working on a project about image retrieval, to retrieve similar images from a folder containing 1000 images.

I have an image like this:

 ![bus](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/e/effd8e805a7a21858e126bfa1b6382e2543b8559.jpeg)

I tried to detect the edges first by using the Canny edge detector :

> bus\_img = cv.imread(“bus.jpg”)  
> bus\_img\_gray = cv.cvtColor(bus\_img, cv.COLOR\_BGR2GRAY)  
> edges = cv.Canny(bus\_img\_gray, 100, 10)

 ![edgebus](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/0/0ec4e2e2388ec7569ad719dbcc4da4286e82dd1d.jpeg)

However, it contains lots of edges from the buildings behind.  
Is there a possible way I can filter them out?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [November 11, 2022, 8:14am UTC](https://forum.opencv.org/t/how-to-filter-the-background-of-an-image/10907/2 "2022-11-11T08:14:57Z")

</div>

> [@Nigel\_Lee](#):
>
> retrieve similar images from a folder containing 1000 images

big field of study: [Content-based image retrieval - Wikipedia](https://en.wikipedia.org/wiki/Content-based_image_retrieval)

ditch Canny. that will only make things worse.

also forget about “filtering”. wrong approach. the only viable ways to do that would involve DL/AI.

instead of just using DL/AI for preprocessing, you should use DL/AI to get features describing the picture directly.
