==== Problem ====
After surveying the original code. We found one three major hot-spots for heavy CPU usage.
This block of code handles reshapes input pixels into a set of samples for classification.
const int N = width * height;[[File:SetSamplesSerial.png]] const int dim = imgThis block of code computes the distances between sampled centers and other input samples.channels(); cv[[File::Mat samples = cv::Mat(N, dim, CV_32FC1);CalculateDistanceSerial.png]] for (int x = 0; x<width; x++) { for (int y = 0; y<height; y++) { for (int d = 0; d<dim; d++) {This block of code generates the image that has to be outputted. int index = y * width + x; samples [[File:GenerateImageSerial.at<float>(index, d) = (float)img.at<uchar>(y, x*dim + d);png]] } } }
==== Analysis ====