Added

I created a histogram function to learn how it works. 
How someone reading your code is supposed to know that? Then you should employ such tricks they are not general enough, i.e., it won't work with any other image. Even if you feel it is necessary to do so, then explain it in comments.