This sounds like a problem with a full reference image quality rating .
The easiest way to get closer to this is to try to calculate the PSNR between PNG24 and PNG8 images. This is a measure of the difference between the two images. The higher the PSNR, the smaller the images. After using the color quantization software, check if the PSNR exceeds a certain threshold (you will have to determine it empirically), and if so, then the quantization was “safe”.
PSNR has its downsides, namely the fact that it does not always correspond to how the human visual system works (for example, it neglects the phenomenon of spatial and contrast masking). Another metric, SSIM , is trying to take care of this problem, but it is a little more difficult to calculate (here is the OpenCV implementation , though). You can use SSIM instead of PSNR in the threshold method described above.
Here is another thread that may come in handy.
source share