Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guided filter in OpenCV and Python

Tags:

python

opencv

I wanted to use a guided filter on an image to compare bilateral and guided filters, but my guided filter code shows the error:

AttributeError: 'module' object has no attribute 'GuidedFilter'

How do I fix this error? My code is as follows:

import cv2
import numpy as np

img = cv2.imread("C:\\Users\\Saloni\\Pictures\\p1.jpg")    
guided = cv2.GuidedFilter(img,13,70)    
cv2.imshow("image",img)    
cv2.imshow("guided filtering",guided)    
cv2.waitKey()
like image 487
Saloni Singh Avatar asked Jun 22 '16 07:06

Saloni Singh


People also ask

What is guided filter in image processing?

The imguidedfilter function performs edge-preserving smoothing on an image, using the content of a second image, called a guidance image, to influence the filtering. The guidance image can be the image itself, a different version of the image, or a completely different image.

What are filters in OpenCV?

Image filtering is the process of modifying an image by changing its shades or color of the pixel. It is also used to increase brightness and contrast.

What are the different types of filters available in OpenCV?

Blurring, Smoothing, Distortion, Warp Stabilizer, alpha extract, bilateral, color matrix, chrome hold are few video filters available in OpenCV.

What is a bilateral filter used for?

A bilateral filter is a non-linear, edge-preserving, and noise-reducing smoothing filter for images. It replaces the intensity of each pixel with a weighted average of intensity values from nearby pixels.


1 Answers

GuidedFilter is not in core, but in the ximgproc contrib module.

So you'll have to make sure your OpenCV installation is built with contrib modules enabled in order to use GuidedFilter. If it's not, you might check this link.

If contrib modules are installed you can just do

from cv2.ximgproc import guidedFilter
like image 98
s1hofmann Avatar answered Sep 20 '22 08:09

s1hofmann