This while loop seems unnecessary to me since we already have one in getPixelLabels function.