Add mean_images function