I am trying to quantify how much sharpness (or acutance) is in a picture which has some bokeh (out of focus background).
I am using the Python scikit image for that. Here is my naive approach:
import matplotlib.pyplot as plt from skimage import data from skimage.color import rgb2gray from skimage.morphology import disk from skimage.filters.rank import gradient cat = data.chelsea() # cat is a 300-by-451 pixel RGB image cat_gray = rgb2gray(cat) selection_element = disk(5) # matrix of n pixels with a disk shape cat_sharpness = gradient(cat_gray, selection_element) plt.imshow(cat_sharpness, cmap="viridis") plt.axis('off') plt.colorbar() plt.show()
This difference in contrast problem is more obvious if one uses the Lena image:
Here, the background is caught as well due to the difference in contrast (there is a black frame on the top right)
Any ideas about how to give an scalar value where only the focused areas are highlighted?