I need to separate the images based on quality. what is the best way to get the quality of the image using OpenCV? I know image.shape gives the height and width of the image but in some situations, for low-quality images, we can change the height and width. So height and width can't give the quality of an image as I think.
Asked
Active
Viewed 2,275 times
1
-
6What do you mean by *"quality"*? All PNGs are lossless so their nominal *"quality"* is 100%. – Mark Setchell Aug 11 '20 at 12:12
1 Answers
2
One useful quality in an image is that it is sharp and not blurry. A simple way to determine this is to measure the quantity of the gradient. Much energy in the gradients means sharp edges, low energy means blurry edges.
This i explained in one of the answers to this https://stackoverflow.com/questions/6646371/detect-which-image-is-sharper#:~:text=The%20simple%20method%20is%20to,produces%20the%20larger%20number%20wins. question.
With python opencv it would be something like this:
import cv2 as cv
import numpy as np
img = cv.imread('dave.jpg',0)
laplacian = cv.Laplacian(img,cv.CV_64F)
gnorm = np.sqrt(laplacian**2)
sharpness = np.average(gnorm)

Anders Sahlström
- 136
- 2