Corrected the arrays' size of the histograms
Fixed errors in dilate function