Ask Your Question

Revision history [back]

Image values manipulation

Hi, I would like to ask if what I did in converting from matlab source to opencv is correct or not. There is a matlab source something like below that I need to convert to opencv:

srcImg( 1:(end-1),:) = srcImg(1:(end-1),:) | srcImg0(2:end,:);
srcImg(2:end,:)     = srcImg(2:end,:) | srcImg0(1:(end-1),:);
srcImg(:,1:(end-1)) = srcImg(:,1:(end-1)) | srcImg0(:,2:end);
srcImg(:,2:end)     = srcImg(:,2:end) | srcImg0(:,1:(end-1));

srcImg(1:(end-1),1:(end-1)) = srcImg(1:(end-1),1:(end-1)) | srcImg0(2:end,2:end);
srcImg(2:end,2:end)         = srcImg(2:end,2:end) | srcImg0(1:(end-1),1:(end-1));
srcImg(1:(end-1),2:end)     = srcImg(1:(end-1),2:end) | srcImg0(2:end,1:(end-1));
srcImg(2:end,1:(end-1))     = srcImg(2:end,1:(end-1)) | srcImg0(1:(end-1),2:end);

I used std::vector<cv::Mat> srcImgs to store the resulted OR'd values. I have used 8 cv::Rect for this to extract submat, like this:

rect1 = cv::Rect(0,0,srcImg0.cols, srcImg0.rows-1);
rect2 = cv::Rect(0,1,srcImg0.cols, srcImg0.rows-1);
rect3 = cv::Rect(0,0,submat.cols-1, srcImg0.rows);
rect4 = cv::Rect(1,0,srcImg0.cols-1, srcImg0.rows);

... and 4 different rect combination continues

To extract, I did this first:

srcImgs.push_back(srcImgMat);

I then did this:

cv::Mat srcImg0, srcImg;
srcImgs[0].copyTo(srcImg0);

And then OR'd and push the result:

srcImg(rect1) = srcImg(rect1) | srcImg0[0](rect2);
srcImgs.push_back(srcImg);

And continued until the last line.

With my approach I got the same result as the matlab script, I just don't know if this is the efficient way of doing. Is there any better way of doing this?

Just learning ocv.

Thanks in advance gee