Code for successfully generate an histogram UIImage. But it is too slow. I decided not follow this path anymore.