From what I’ve gleaned, there are many approaches to determining image quality (sharpness/contrast/resolving ability). The slanted-edge approach seems to be the most accepted, and is in fact the basis of ISO 12233. Below are some links to browse to get the general drift of it.

Imerge has the most authentic Lens Blur effect on the market complete with realistic ‘bokeh balls’. Buy Imerge now and play around with settings for different results, mask out different areas to create realistic subject separation, and more.

Depth-of-field may be the most common way to create depth in an image, but it certainly isn’t the only way. You can also use techniques like lens compression, field-of-view, and atmospheric effects. Combining two or more of these techniques can create unique images with lots of dimensionality.

Here’s code for an autofocus routine used in microscopy, of interest mostly for how they calculate contrast: https://github.com/micro-manager/micro-manager/blob/master/scripts/autofocus_test.bsh

Longer lenses can be used to bring objects ‘closer together’ in the resulting image, reducing the depth and increasing the implied ‘intimacy’ between them. Wider (or shorter) lenses can be used to make things seem far apart, for example – using a fisheye lens to shoot a long corridor can make it appear to go on almost forever.

Image

Imerge is the world’s first fully non-destructive RAW image compositor. Take control of your color with Imerge’s unique workflow for end-to-end color preservation, or get creative with 68 non-destructive effects. Imerge is almost entirely GPU-accelerated to make the most of your hardware – leaving you more time to focus on the important stuff.

Too much depth can make it hard to tell what you’re looking at. Sometimes just a little can achieve the effect you’re looking for – and will preserve some of the context of your scene for viewers to pick up on. The benefit of a wider depth-of-field is also that it’s much easier to keep things in focus – pulling focus on a moving subject is pretty difficult when your depth-of-field only spans a thin sliver of the range.

Simply put, depth is the distance from the camera. Depth of field is the portion of that distance or ‘depth’ that is ‘in-focus’. A higher depth of field would see the whole image from foreground to background sharp and in focus, a lower depth would result in blurry backgrounds and blurred elements in the foreground too.

Depth of field is all about drawing focus onto a particular subject and works in much the same way that the lens in your eye does.

MTF is a common mathematical measure of image sharpness. It involves differentiation and a Fast Fourier Transform. I hoped to find it in one of the standard or extended libraries but so far have not.

o MTF seems to be most often calculated as the normalized FFT of the derivative of the image, but I suppose there might be other measures as well; maybe even the histogram of pixel values could have utility for this (since a perfect step would have pixel values in only two bins, white and black; any intermediate bins with pixels in them would indicate blur). I would imagine that image-based autofocus approaches do something similar. Those have been around for a long time. My nearly 30-year-old Sony handicam had image-based autofocus.

The reason that the areas that are out of focus appear blurry is that the precision of the light being captured from these areas is sacrificed to benefit the precision of those you want to look at. This means that the light in these areas becomes scattered – usually in the shape of a circle because of the shape of your iris – the part of your eye that ‘steers’ light onto your retina

Modulation transfer functionimageprocessing

Lens compression is what happens when you have really ‘zoomed-in’ telephoto lenses. It refers to the ‘squishing’ of elements or layers together so they seem closer together (or farther apart) than they actually are.

Our mission is to empower creators worldwide to tell their stories through video. We bring opportunity to the creative industry with powerful, intuitive and accessible tools. , as well as learning resources to support you in achieving your creative vision.

Introduction to Modulation Transfer Function | Edmund Optics --less on the slant-edge approach, more relating to resolving line patterns and other classical stuff

What’s happening here is your eye clamps a ‘focusing range’ around your finger so it can stay focused on it. As you move your finger away, your eye adjusts to move that focusing range with it, meaning the objects in the background are coming closer to the centre of focus.

For my application, I need to do a fast calculation of the modulation transfer function of a test image. I’m starting from scratch and would appreciate suggestions on how best to do this.

Landscape photography typically (but not always) uses a large depth-of-field to capture all of the detail of the landscape, whereas portrait photography usually utilizes shallow depth-of-field to draw focus onto the subject.

How to Measure Modulation Transfer Function (4) « Harvest Imaging Blog --good, concise description of the slant-edge approach

Image mtfformula

Image

MTFcurve

Different lenses have different maximum apertures. Aperture is measured in f-stop and the lower the f-stop number, the higher the aperture (wider the iris). Therefore an f-stop of 1.8 has a wider aperture than an f-stop of 3.5.

Okay, I’ve studied this quite a lot today. Needed is a scalar measure of sharpness/contrast/acutance. Focusing and other lens adjustments would serve to optimize this quantity.

Moving yourself (or the camera) closer towards the objects in the scene increases the relative distance between the objects themselves when compared with the distance from the camera. This increases the perceived depth and can add more lens blur to background and foreground layers. Similarly, moving the camera further away will reduce the depth of field and make objects seem closer together.

“Misha” makes several references to a paper by Marzillano that describes an efficient method of calculating sharpness: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.7.9921&rep=rep1&type=pdf …reading through that now.

Now, I started this thread asking about MTF. But MTF gives a graph vs. spatial frequency, not the figure of merit desired (though I suppose one could pick a spatial frequency and use the value of that bin for optimization).

That’s hugely helpful. I’m a newbie with this so a firmware approach in the future would be wonderful. Meanwhile I’ll see what I can accomplish! Thank you.

I’m going to be doing some work on this FFT stuff this weekend. Can you post a link to an easy to understand paper or website for MTF? I can add it then.

One of the main purposes of depth of field is to create what’s called ‘subject separation’. Bokeh can be used to soften distracting elements in the background or foreground of an image so that the eye is automatically drawn to the subject of choice.

After my reading, it seems DCT rather than FFT will give us the info we needed with more efficiency. See https://users.cs.cf.ac.uk/Dave.Marshall/Multimedia/PDF/10_DCT.pdf …As I’m sure you know (it was new to me as of today!), DCT is basis of .jpeg, so an efficient implementation probably already exists in OpenMV.

The focal length of a lens dictates its field-of-view, i.e. how ‘wide’ it is. For example ‘wide-angle’ and ‘fisheye’ lenses have a wide focal length (usually between 10 and 35mm) and ‘telephoto’ lenses can have focal lengths of anywhere from 80 to 2000mm or more. The longer the focal length, the more ‘zoomed-in’ the image that the lens produces.

So I’m googling on [“image based” “auto focus” OR autofocus] and find an intriguing reference to “histogram entropy” as a metric of image sharpness here: http://www.emo.org.tr/ekler/dbdbf7ea134592e_ek.pdf

Also see computer vision - Assessing the quality of an image with respect to compression? - Stack Overflow --post by the same author.

Thank you! I am working on the step by step list. First I’m sifting through all the references and pointers and opinions to come up with an optimum approach. Expect my input shortly.

Wondering if this might be less compute-intensive than the FFT approach. I’m poking through OpenCV now in search of nuggets. UPDATE: Per the discussion at http://answers.opencv.org/question/5395/how-to-calculate-blurriness-and-sharpness-of-a-given-image/ OpenCV has a function, calcBlurriness, which would do the job. Unfortunately it’s undocumented (OpenCV: Video Stabilization). Trying to ferret out the source now.

My own application has frame-rate as a priority, so efficiency trumps exactitude for me. I just want to maximize “sharpness” and don’t care much about rigorous compliance with ISO this-and-that. I’d imagine autofocus would have similar priorities. Reading material:

Try closing one eye and placing your finger in front of the other. Now focus on your finger, and slowly move it away from your eye whilst staying focused on it. Do you notice how the background slowly comes into focus?

The aperture of your lens refers to how wide the diaphragm or ‘iris’ in your camera opens. When you open the iris wider (a higher aperture), it increases the radius at which light can disperse when making its way to the sensor. This creates lens blur that’s more pronounced, and as a result, reduces the depth of field.

Ah, so, we actually have code for the 2D FFT onboard for phase correlation. If you modify the C firmware the camera can do what you want. The phase correlation file shows an example of this: https://github.com/openmv/openmv/blob/master/src/omv/img/phasecorrelation.c

Image mtfgraph

http://www.dougkerr.net/Pumpkin/articles/MTF_Slant_Edge.pdf --a few pages of less-interesting background lead up to a nice description of the slant-edge approach

If you’re just getting started in the world of photography and filmmaking, you might have come across the term ‘depth of field’. While it might sound quite complicated, depth of field is actually a fairly simple technique that can add a ton of value to your images. In this article, we’ll cover what depth of field is, how it works, and how to use it creatively in your images.

MTF imagequality

I might have time to write the code for this tommorrow. If you can work out a high level step by step guide for what you want me to do then I can do that. Note that “compute the PSF” is not a sufficient guide… I’ve seen a lot of details on that but I don’t know what they mean.

Getting your camera down low can offer unique perspectives in any context. When using a shallow depth of field, it can also create a smooth ‘taper’ effect at ground-level that can look really interesting.

Okay, I’m assuming that a firmware update that exposes the fft functionality (or better yet, provides a proper MTF method or some other measure of image sharpness) is some time in the future. I’m interested in fiddling with the firmware. Is the process for doing so documented? I’m not finding it.

As well as creating dimension and context, out-of-focus elements in the foreground can be used to obstruct unsightly elements in the scene, or create more mystery surrounding the context of your subject. Close up elements can create a subtle and unobtrusive effect that slowly tapers off the detail in an area of the image.

While it can be tempting to go out and shoot everything at the highest possible aperture to get that nice ‘creamy’ bokeh, it’s easy to get carried away and forget what you’re trying to achieve.

Here is something interesting. If you have fast .jpeg compression then the job may already be done. Per Detection of Blur in Images/Video sequences - Stack Overflow (poster Misha), the DCT coefficients provide a measure of the high-frequency components in the image.

If the different layers in your scene are too close together, there won’t be enough distance between the objects to create any noticeable difference in how much light can be dispersed. In some ways, this will make the objects appear to be on the same plane (or at least in the vicinity) of each other.

The focal length of your lens can affect depth of field because it affects the apparent distance between you and the objects in your scene. Longer focal lengths tend to have a pronounced depth of field, so using a telephoto lens like an 85mm or 105mm can be a good way to add dimension and depth (providing you use a high enough aperture to make use of it).

You can also use depth of field to create what’s called ‘layering’. Photographers and cinematographers will often add elements like plants or structural elements as an out-of-focus layer in the foreground. This helps to add dimension to your image, and creates a more immersive perspective for the viewer. Try experimenting with two, three, four, or even five layers to see how it affects your final result.

MTFlens

Image mtfcurve

Depth of field can also be used to draw attention to a particular detail in an image – for example the shoelace in a photograph of a boot, or a person’s eyes in a portrait. It increases the contrast in the focus area relative to the areas around it, and our eyes are naturally drawn to areas of high contrast. If you have more than one subject in your shot, you can use depth of field to pull your viewers focus to one in particular.

Image

MTFcamera

and py_mtf/mtf.py at master · weiliu4/py_mtf · GitHub --some Python example codes I’ve been picking through Thanks! Meanwhile I’ll play around with that firmware link you provided. Many thanks for that!

Increasing the space between objects increases the depth, and therefore the distance that light has to disperse and create bokeh. However, it’s not always possible to move the elements in your scene, especially if you’re shooting events, documentary, wildlife, or sports. So what else can you do to control depth of field?

Um, anyway, the FFT code I wrote can do 1d FFTs up to 1024 points. It can do both real->complex and complex->complex ffts. It can also do reverse ffts too.

It’s also worth noting that when you widen the aperture, you’re letting more light through and therefore need to compensate for exposure by using a faster shutter speed or lower ISO value. If you’re shooting in an ‘auto’ mode, your camera should do this for you.

Nice : “One of the properties of the 2-D DCT is that it is separable meaning that it can be separated into a pair of 1-D DCTs. To obtain the 2-D DCT of a block a 1-D DCT is first performed on the rows of the block then a 1-D DCT is performed on the columns of the resulting block.”

I can do the math easily. I just don’t know what particular steps you’d like me to do. We can’t output graphs on the OpenMV Cam. So, everything needs to boil down to one value.

More broadly, how does one assess the contrast/sharpness of an arbitrary image? Is there a less-fancy approach that might be more applicable to a tiny processor?

Another way to create a sense of depth in your imagery is with atmospheric effects. We’re talking about things like mist, fog, haze, or dust. These types of effects usually create a subtle ‘diffusion’ of light and reduce the contrast between different layers. The heavier the atmosphere, the stronger the effect and sense of depth. Using atmospheric effects in combination with long lenses can create powerful layering in your images.

o MTF, then, boils down to calculating how much high-spatial-frequency content is in the image. Lens quality and setup (focus, etc) is an obviously dominant contributor, but the whole imaging system contributes. In the olden days of analog video connections, even cable quality could have a profound impact.

o A slant-edge image target (black/white, at a small angle vs. the pixel array axes) serves as a step function for the imaging system. How steeply stepped does your imaging system perceive it to be? The sharper the step, the more high-spatial-frequency content in its Fourier transform; blurrier images have less.

Bokeh is the name for the blur that occurs as a result of a narrow depth of field. It is typically circular because it scatters within the confines of a circular element in the eye or a camera lens called an diaphragm or ‘iris’. The wider the iris, the larger the circles.

If I hadn’t started this thread, how would a machine vision engineer have answered that question? Is there a tried-and-true approach?