Refactor and improve imgdiag.
am: 1f146b7db1

Change-Id: I5e1a736658ec75b25dde4f2f9e97d744eea4d7bd