code for generating and comparing images