this is terribly inefficient. You basically allocate a chunk of memory in dynamic head for each pixel. Simple solution would be to move vector<float> declaration outside of the loops.