You are on page 1of 2

In Focus Regions

Ezequiel G. Debada
April 11, 2015

Turns out that recently I have put a


foot into photography world, and I am
discovering a great deal of interesting things
I hadnt think about before. One of the
point I have been getting information about
is how does auto-focus function works.
Like always wikipedia has a quick response
for my inquiry. Furthermore, some time
in the past I saw an interesting camera
functionality consisting on highlighting
in-focus regions within the imagen in liveview mode. I didnt stop to think how such
a thing worked but, that moment has arrived.

0.8

0.6

0.4

0.2

Figure 1: Sharp Vs Smooth image


the probability of been an in-focus region. Assuming that the image being processed does
have some focused-region, the biggest values
should correspond which such a regions. That
information is relative to the image in the
sense that, at least that we knew beforehand
what values corresponds to in-focus regions,
in totally blurred images we could have false
positives. There is an alternative way to measure sharpness with doesnt have that problem, and it is frequency methods which uses
fast Fourier transform and measure the high
frequency components to determine if the image is in focus or not. As you can imagine this
approach is harder to understand so kernel solutions will meet our expectations today.
The sharpness value in each pixel is calculated
simply by applying the next kernel:

0 1 0
1 4 1
(1)
0 1 0

The target of todays post is to develop an


script to highlight in-focus regions within an
image. The code which generates the results
here presented is available HERE.
Firstly, what is the differences between infocus and blurred images? : sharpness. A
property which measures how pixel intensity
varies between a pixel and its neighbourhood.
In the next stripped image, we can see how
the pixel-intensity values change smoother in
blurred images. Several ways to measure that
property come across. Among all of them,
two methods stand out: kernel vs frequencial methods. Kernel method consists basically in registering the differences between
each pixel within the image and its neighbourhood. The greater is that value, the greater is

To see how this works we take the next


1

image, and we apply the kernel. The next


two pictures show the source image and the
result (after normalize the Sharpness matrix).
Now, we apply a threshold to the
resulting image in such a way that regions
with high sharpness values will be assigned 1
and 0 otherwise. This last result is used in
order to highlight pixels in the original image. Finally, as it cant be in other way, a gif
which shows a sequence of images with different in-focus after being processed with the
code.

You might also like