title: Compare images for rendering differences (ignoring antialiasing)
body: <p>I have a PDF file that I render using Adobe PDF engine as well as another PDF rip. I want to try to identify places where they render differently. The problem is that they both render with slightly different anti-alias, color, and very minimal positional differences. I am more concerned with larger difference. I'd like to compare the attached files <code>match1.png</code> and <code>match2.png</code>. These two should match. The files <code>diff1.png</code> and <code>diff2.png</code> should NOT match. They should fail as the one has a missing letter. I've worked with ImageMagick's compare, but haven't got good enough results to ignore the slight rendering differences and only focus on the major ones.  I think the below algorithm could work, but I wasn't sure how to read PNG files and compare them pixel by pixel.</p>
  <p><a href="https://www.carlisleprinting.com/sites/default/files/article_files/ImagesCompare.zip" rel="nofollow noreferrer">sample image files</a></p>
  <ol>
  <li>compare each pixel in ImageA to the same pixel in ImageB. Also compare to each neighboring pixel in ImageB</li>
  <li>Find the nearest matching pixel from all the tested pixels in ImageB.</li>
  <li>Store the color difference of this closest matching pixel as difference index for that pixel in ImageA.</li>
  <li>Repeat this calculation for each pixel in ImageA.</li>
  <li>Normalize the difference values to make the smallest difference a zero. Un-normalized values might be (3,8,5,18) and normalized may be (0,5,2,15) or some other type of normalizing function.</li>
  <li>Then count up how many pixels are over a threshold value, say, 5 or whatever. Then this count of 'bad' pixels could be used to calculate the probability that there is a rendering error in one of the images.</li>
  </ol>
  <p>This is just a sample algorithm. I wasn't sure how to process PNG files pixel by pixel. I'd be open to a PHP solution or a solution using command line tools such as imagemagick, etc.</p>