View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Guided Filter

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.2
4.2 | 5 ratings Rate this file 51 Downloads (last 30 days) File Size: 2.54 KB File ID: #33143 Version: 1.0

Guided Filter

by

Rachel (view profile)

 

An 2D edge-preserving filter derived from a local linear model. Related to bilateral filter.

| Watch this File

File Information
Description

This is a novel type of explicit image filter - guided filter. Derived from a local linear model, the guided filter
generates the filtering output by considering the content of a guidance
image, which can be the input image itself or another different image.

The guided filter can perform as an edge-preserving smoothing operator
like the popular bilateral filter, but has better behavior near the edges. It also has a theoretical connection with the matting Laplacian matrix, so is a more generic concept than a smoothing operator and can better utilize the structures in the guidance image. Moreover, the
guided filter has a fast and on-approximate linear-time algorithm, whose
computational complexity is independent of the filtering kernel size. The guided filter is both effective and efficient in a great variety of computer vision and computer graphics applications including
noise reduction, detail smoothing/enhancement, HDR compression, image matting/feathering, haze removal, and joint upsampling.

There are two files: 'guided_filter.m' contains the guided filter function; 'guided.m' is an example script demonstrating the use of the filter.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
02 Oct 2016 pavithra p

THANK U

04 Jul 2016 Rachel

Rachel (view profile)

@Liu: thanks for the comment. It sounds like your input is a color image with three channels. This guided filter code only deals with gray-level images. To get around the problem, you can:

1) apply rgb2gray on the input image to convert it to a gray-level image then apply the guided filter.

2) apply guided filter individually to each of the three channels and combine the filtered the results at the end.

Comment only
01 Jul 2016 Liu

Liu (view profile)

Thanks for the code.
However, when I run this code, there is an error

"Error using .*
Matrix dimensions must agree.

Error in guided_filter (line 92)
filtered = mua .* input + mub;

Error in guided (line 14)
filtered = guided_filter(input, guide, .01, win_size);"

the dimension of mua is 384*1544, while the dimension of the input is 384*512*3, should I reshape the mua or the input? Thanks.

10 May 2016 Rachel

Rachel (view profile)

@Phithak: Hi Phithak, thanks for downloading guided filter. I tried to reproduce the error and couldn't get the same error message. When I replaced the input and the guide image with their UINT8 version, I got the following error:
========================================
Error using +
Integers can only be combined with integers of the same class, or scalar doubles.

Error in guided_filter (line 43)
mup = mup + circshift(paddedp, [i, j]);
========================================
This is what you would expect when you use operations for doubles on UINT8 type.

Can you double check your code and make sure that the file 'guided_filter.m' is actually in your MATLAB path when you run your script? The error you got sounds more like MATLAB can't find the file.

One way to test is to apply double() to your input and guide image and see if the the same error happens. If it still does, then the file 'guided_filter.m' is probably not in the current directory.

If you are still having problems, please send your code to me. I'm happy to take a look.

Another thing is: if you have MATLAB 2014a and up, you should find the imguidedfilter function from Mathworks. I have tested this command and it produces very similar results to my implementation. If you choose to use imguidedfilter, there won't be any problem with finding the external files.

Comment only
10 May 2016 phithak deang

i'm using Matlab R2012b. when i try to run the code i received
Undefined function 'guided_filter'
for input arguments of type
'uint8'.

why does it happen? can u explain more about this problem? Thank you

Comment only
18 Jun 2015 Stefan Karlsson

Stefan Karlsson (view profile)

Its always nice to see useful implementations. As pointed out, this function is already implemented in the imageprocessing toolbox, but for 2014 versions and onward.

A question: how does this code perform when compared to the one found here?:

http://research.microsoft.com/en-us/um/people/kahe/eccv10/

16 May 2015 Aasd

Aasd (view profile)

good job ,this code doing smooth well

17 Mar 2015 Rachel

Rachel (view profile)

@Royi: this code is simply using the input image (noisy image) as the guidance image, which the original authors used in their example (Fig. 1 in their original paper). If you compare the results from this code and the new MATLAB 2014a function 'imguidedfilter', you'll notice the results look almost identical. I suggest you have another look at the original paper before posting.

Comment only
16 Mar 2015 Royi Avital

Pay attention that you make it a linear combination of the Input Image while the article states that the output is a linear combination of the Guidance Image. Hence the code is wrong.

Comment only
01 Jul 2014 Spandan Tiwari

Guided filter is offered in the Image Processing Toolbox, as function imguidedfilter, since R2014a.

Comment only
24 Oct 2011 jun

jun (view profile)

Another codes from Kaiming He,author of the paper 'Guided Filter', are here: http://personal.ie.cuhk.edu.hk/~hkm007/

Comment only
24 Oct 2011 jun

jun (view profile)

The code doing smooth well @ epsilon in range[0.05,0.1]. And what about HDR compression?

Contact us