Sivaram Rasathurai
Sivaram Rasathurai

Reputation: 6373

Identifying the quality of an png format image with opencv

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.

Upvotes: 1

Views: 4003

Answers (1)

Anders Sahlström
Anders Sahlström

Reputation: 156

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)

Upvotes: 4

Related Questions