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.
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).
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.
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.
Image blur is calculated with the basic formula: b = dwScos0 . This equation uses exposure duration directly.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With