Fixed an index out of bounds error on 2D intensity calculation