added function to free image arrays. Also changed error printing to stderr from stdout
populating max and min value metadata for greyscales