thinningIteration() function is very slow
Profiling thinning() in VisualStudio2017 i have discovered that it takes a crazy amount of time in Mat.at(). Changing the following code has made it run 3 times faster for me.
whats the proper process for making fixes like this, or proposing them?
static void thinningIteration(Mat img, int iter, int thinningType){
Mat marker = Mat::zeros(img.size(), CV_8UC1);
uchar *p239, *p48, *p567;
int rowsm1 = img.rows - 1;
int colsm1 = img.cols - 1;
if(thinningType == THINNING_ZHANGSUEN){
for (int i = 1; i < rowsm1; i++)
{
uchar* ptri = img.ptr<uchar>(i);
uchar* ptrim1 = img.ptr<uchar>(i-1);
uchar* ptrip1 = img.ptr<uchar>(i+1);
for (int j = 1; j < colsm1; j++)
{
p239 = &(ptrim1[j - 1]);
p48 = &(ptri[j - 1]);
p567 = &(ptrip1[j - 1]);
uchar p9 = *(p239);
uchar p2 = *(++p239);
uchar p3 = *(++p239);
uchar p8 = *p48; p48++;
uchar p4 = *(++p48);
uchar p7 = *p567;
uchar p6 = *(++p567);
uchar p5 = *(++p567);
//uchar p2 = img.at<uchar>(i - 1, j);
//uchar p3 = img.at<uchar>(i-1, j+1);
//uchar p4 = img.at<uchar>(i, j+1);
//uchar p5 = img.at<uchar>(i+1, j+1);
//uchar p6 = img.at<uchar>(i+1, j);
//uchar p7 = img.at<uchar>(i+1, j-1);
//uchar p8 = img.at<uchar>(i, j-1);
//uchar p9 = img.at<uchar>(i - 1, j - 1);
see How_to_contribute