December 13, 2019

Finding Edges

Finding Edges

In my well-used copy of Principles of Digital Image Processing: Fundamental Techniques, there's a chapter on Edges and Contours. I had looked through it several times, and had mostly understood the concepts, but I really had no use for the techniques it described.

Then one day I was reading a blog post titled "Stopping Down Some Bargain Primes and Zooms" that contained a short section with the heading "So How Do You Check Your Field Curvature". In it Roger Cicala  describes how to use Photoshop's Find Edges filter to show the field of focus in a photograph. (And also the possible curvature or tilt of said field of focus.) Well, that got me going.

Yet Another Computer Program

So, of course, we now have a new computer app that takes a photo and produces an image of its edges. We could have just loaded up Photoshop and used it, but where's the fun in that? Here's kind of how things progressed. The new app implements two (apparently) old reliable edge detection filters: the Prewitt and the Sobel edge operators. Let's take a picture and run the app on it using the Sobel operator. Here's the picture:

Just looking at this picture, we see some edges in the tree bark, but no real edges in the out-of-focus background. Here's what the Sobel edge detection operator produces:

Not so interesting. The places in the picture where there are no edges are black; any edges are lighter in value. This image has no really prominent edges, so there are only the faintest lighter values. It would probably be prudent to scale the edge values so that the sharpest edges in the picture (whether they are actually very sharp or not) are pure white. When we do that, we get:

This is somewhat better. However, I prefer seeing the edges as black lines against a light background instead of light lines against a black background. So let's do that:

That's even better, but still a bit washed out. So we'll scale the edge values an arbitrary amount to get an image that suits us.

And finally, because we like this image just for itself, we'll adjust the color and contrast a bit to give it a final look.

Yes, it's likely you'll be seeing one or two of these "edge" images On the Cork Board.

Back to Checking Your Field of Focus.

OK, so what got us into this mess to start with was the desire to use an edge filter to show us a lens' field of focus. Here's a practical application. I was just out taking pictures in an overgrown pasture with a 70-200mm zoom at 70mm. Here's the shot I was trying to get:

A very real issue in this situation is "Where do I focus?" Knowing I had the find edges app, I took four exposures. In the first, I focused in the center of the picture. In each subsequent exposure, I moved the focus point closer to the bottom of the picture. When I got home, I ran all four exposures through the find edges app. Here's what I got.

You can see the field of focus getting closer to the camera. It shows up as darker than the out-of-focus areas. (Note also that my lens has a curved field of focus, which is not much of a surprise.) Based on the look I was after, I chose the upper right image as the one with the best field of focus.

Some of you may recognize that this "find edges" technique is what your camera is doing when you use "focus peaking". More fun with computation.

No comments: