File Exchange

image thumbnail

Focus Measure

version 2.2 (4.62 KB) by

A function to measure the relative degree of focus of an image.

4.89474
19 Ratings

79 Downloads

Updated

View License

This function measures the relative degree of focus of an image. Several up-to-date focus measuring algorithms have been implemented and the function supports uint8 or double images. For futher details on each focus measuring algorithm the reader is referred to [1] and the references therein. For further information and datasets, see https://sites.google.com/view/cvia/focus-measure
[1] S. Pertuz et al., Analysis of focus measure operators for shape-from-focus. Pattern Recognition, 46(5):1415:1432, 2013.

Comments and Ratings (26)

Said Pertuz

Said Pertuz (view profile)

Thanks @Joel Cottrell for spotting this bug! The problem has been fixed

Joel Cottrell

This is a very useful function for quickly trying out a range of focus measures, thank you.
Is there possibly a bug in the AcMomentum function, on line 245? It seems like the mean of the image shouldn't be multiplied by 255, because it is already in the 0-255 range (not 0.00-1.00).

If SFRQ is computed, the gradient components are initialized with the image. This yields overly high focus measure values at right and bottom image borders. I suggest to initialize both gradient components with zeros.

Nam Yeo Kang

user001

DCTE and DCTR return exclusively NaN for inputs of type double (haven't tried uint8 inputs).

shike

shike (view profile)

6666666666666666

Said Pertuz

Said Pertuz (view profile)

@Anthony, the normalization is not strictly necessary since the operations are performed in double precision. However, your suggestion is quite correct if we want to avoid stability issues. I have corrected the code accordingly, thanks!

Anthony

Thanks for providing your code!
Concerning the GDER criterion, I wonder wether the divisions in l 80/81 should not be replaced by

Gx = Gx / max(max(abs(Gx))) (resp. Gy)

in order to normalize the kernels?
The symmetry of the kernels implicates sum(Gx(:)) -> 0 thus creating extremely high values in resulting Gx & Gy (order of 10^13).

Sorry if I completely missed the point!

Thanks.
In your implementation of Brenners metric there seems to be a bug. diff(Image,2,1) and diff(Image,2,2) is used. This is somewhat like calculating the second order discrete derivation but shouldn't it be the (~first order) difference between two pixels with a distance d=2?

Jesse

Jesse (view profile)

Sayonics.com seems to have gone away.

Misha

Misha (view profile)

Ahmed

Ahmed (view profile)

Thanks very much :)

How do you choose WSize=15 and sig=N/2.5 in 'GDER'? If anyone can help I would appreciate it.
Thank you for providing your code.

Very helpful, allows you to try quickly many different methods and see what suits your case.
There is for sure a small bug in SFIL case, between 270 and 315 degrees, R(:,:,7) appears twice instead of R(:,:,7) and R(:,:,8)

MTJ1990

Engin

Engin (view profile)

It seems like some of the metrics (options) needs Wavelet Toolbox (if there is something like this?), because a lot of functions for WAVS, WAVV and WAVR are missing.

Moreover, it is not exactly clear if an image should be of type uint8 or double or what - however results of some metrics depends on datatype of image.

Quite a useful tool to measure various focus measures.

Rob

Rob (view profile)

I was wondering how you got the plot.

Bosheng

Nek Valous

Jonathan

Great tool, exactly what I was looking for!

Note that the ACMO method as written also requires the Fixed-Point Toolbox. I just commented out the isdouble() check, and make sure my images are uint8 before passing them in.

Dave Holden

Very useful

Updates

2.2

Fixed a bug in the function AcMomentum

2.1

- Description updated

2.1

- Bug fixed in GDER focus operator

2.0

- Some bugs have been fixed (Brenner's and GDER's focus measure operators)

1.3

- The function no longer requires the floating-point toolbox.

MATLAB Release
MATLAB 7.7 (R2008b)
Acknowledgements

Inspired: Shape from focus, Extended depth-of-field

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

» Watch video

Win prizes and improve your MATLAB skills

Play today