Identifying the quality of an png format image with opencv

Question:

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 By: RCvaram

||

Answers:

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)
Answered By: Anders Sahlström
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.