Ask Your Question

Wurstpelle's profile - activity

2017-04-27 06:54:47 -0500 received badge  Editor (source)
2017-04-27 06:52:57 -0500 asked a question Efficient pointer-scanning on image

Hi everyone, I´m new in C++ and OpenCv and have a little problem with scanning an image with pointers.

I want to switch my running (slowly) Source into faster code by using pointers instead of the iteration through the loop.

The actual code is listed below:

for (int i = 0; i < Image.rows; i++)
 {
    for (int j = 0; j < Image.cols; j++)
     {
       int y = x - Image.at<cv::Vec3b>(i, j)[2];

       if ( (y - Image.at<cv::Vec3b>(i, j)[1] < Threshold1) && (x - Image.at<cv::Vec3b>(i, j)[0] < Threshold2))
           {
               BinaryImage.at<cv::Vec3b>(i, j)[0] = 255;
               BinaryImage.at<cv::Vec3b>(i, j)[1] = 255;
               BinaryImage.at<cv::Vec3b>(i, j)[2] = 255;                            
            }
      }
    }

I´m not sure how to replace the part for computing the y-value and the if-line:

 int y = x - Image.at<cv::Vec3b>(i, j)[2];

and

if ( (y - Image.at<cv::Vec3b>(i, j)[1] < Threshold1) && (x - Image.at<cv::Vec3b>(i, j)[0] < Threshold2))

My first solution doesn´t work.

 uchar* ptr_Image = Image.ptr<uchar>(i);
uchar* ptr_BinaryImage = BinaryImage.ptr<uchar>(i);
    for (int j = 0; j < Image.cols; ++j)
     {
        int y = x - *ptr_Image+2;

    if ( (y - *ptr_Image++ < Threshold1) && (x - *ptr_Image < Threshold2))
         {   *ptr_BinaryImage++ = 255;
             *ptr_BinaryImage++ = 255;
             *ptr_BinaryImage++ = 255;
          }
     }

I know, that an binary-image is ordinarily type CV_8U not CV_8UC3 but I need this with three channels ;)

Thank you!

Daniel S.

2017-04-11 02:47:11 -0500 commented answer Conversion from RGB to HSI

Can anyone explain why there is a multiplication for s with factor 100?