Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect which image is sharper

I'm looking for a way to detect which of two (similar) images is sharper.

I'm thinking this could be using some measure of overall sharpness and generating a score (hypothetical example: image1 has sharpness score of 9, image2 has sharpness score of 7; so image1 is sharper)

I've done some searches for sharpness detection/scoring algorithms, but have only come across ones that will enhance image sharpness.

Has anyone done something like this, or have any useful resources/leads?

I would be using this functionality in the context of a webapp, so PHP or C/C++ is preferred.

like image 725
econstantin Avatar asked Jul 11 '11 06:07

econstantin


People also ask

How do you check the sharpness of an image?

Image sharpness can be measured by the “rise distance” of an edge within the image. With this technique, sharpness can be determined by the distance of a pixel level between 10% to 90% of its final value (also called 10-90% rise distance; see Figure 3).

What determines an images sharpness or clarity of an image?

Camera Resolution and Image Sharpness Generally, the more pixels, the more detail you'll see (considering the same sensor size, lens quality, and settings). Many times, especially when we talk about smartphone photography, we rely on the megapixels of the camera to determine what is best in terms of sharpness.

What is the sharpness of an image called?

In photography, the term "acutance" describes a subjective perception of sharpness that is related to the edge contrast of an image. Acutance is related to the amplitude of the derivative of brightness with respect to space.

How do you measure a picture that is blurry?

Image blur is calculated with the basic formula: b = dwScos0 . This equation uses exposure duration directly.


1 Answers

As e.g. shown in this Matlab Central page, the sharpness can be estimated by the average gradient magnitude.

I used this in Python as

from PIL import Image import numpy as np  im = Image.open(filename).convert('L') # to grayscale array = np.asarray(im, dtype=np.int32)  gy, gx = np.gradient(array) gnorm = np.sqrt(gx**2 + gy**2) sharpness = np.average(gnorm) 

A similar number can be computed with the simpler numpy.diff instead of numpy.gradient. The resulting array sizes need to be adapted there:

dx = np.diff(array)[1:,:] # remove the first row dy = np.diff(array, axis=0)[:,1:] # remove the first column dnorm = np.sqrt(dx**2 + dy**2) sharpness = np.average(dnorm) 
like image 164
Robert Pollak Avatar answered Sep 22 '22 07:09

Robert Pollak