Refactor and improve imgdiag. am: 1f146b7db1 am: b43dca51d7
am: 39a6916ba8

Change-Id: I500836486f0466c2c6f2a51a2698ab6723d77585