2D normalizeDensity and calculateDensity functions