php – How do you compare the quality of the images?

Question:

I have a set of images.

With a parser through Google's image search, I pull out all identical photos. These photos are of different size and quality.

I need to identify the best quality image.

For example: There are 2 identical images 700x700 px.
One has an original size of 700x700 px.
The other was resized from a 300x300 px image.
Naturally, the quality of the second is lower.

So far I have come up with only resizing all photos to one resolution and comparing their sizes.

Is there a better way to organize the comparison?

Answer:

Apparently, here instead of "image quality" (a subjective concept) it is better to talk about "amount of information". After all, the more information in the picture (and we are not talking about the file size), the "better" it is from the point of view of your definition (not obtained "by resizing", etc.).

If we accept this terminology, then we can try to use the characteristic "amount of information in the image", defined as the sum of the absolute values ​​of the differences in color components for all pairs of neighboring pixels.

For the sake of simplicity, let's assume for now that it makes sense to compare these characteristics only for images of the same size.

Example:

There is a 6×3 pixel source image:

123456
321654
123456

And there is a reduced version of it 2×1 in size (we took the averaging over both 3×3 squares:

25

To understand which picture is better, they need to be reduced to one size (i.e., stretch the second, without using any anti-aliasing algorithms). We get the following result

222555
222555
222555

Now let's count our characteristics for the first picture and for the stretched second picture: we get the values 15+8 and 9+0 , respectively (here 15 and 9 is the sum of the absolute values ​​of the differences along the horizontal axis, and 8 and 0 are the same along the vertical axis) … This means that there is much more information in the first picture (which we had no doubt about).

With a little thought, you can come to the understanding that there was no need to stretch the second picture, but rather correctly take this stretch into account when calculating the characteristic. But this is already an optimization stage, and at the prototype stage, I would recommend training the algorithm by comparing images of the same size.

Scroll to Top