using std::vector for each pixel (!!!) is very inefficient. Consider using a single joint array of CodeWord structures (concatenated array of codebooks).