# Revision history [back]

To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.


Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);


To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

Mat myMask = Mat::zeros(img.size(), img.type(), );


To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.


Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);


To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

Mat myMask = Mat::zeros(img.size(), Mat(img.size(), img.type(), Vec3b(255,255,255) );


To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.


Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);


To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

Mat myMask = Mat(img.size(), img.type(), Vec3b(255,255,255) );


To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.


Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);


To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

Mat myMask = Mat(img.size(), img.type(), Vec3b(255,255,255) );
myMask); //set all areas of img to black that are within the white area of the mask.


To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.


Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);
cv::threshold(mySubmat,mySubmat,....); //BTW: thresholding will only work on image if single channel image


To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

options:
Mat myMask = Mat(img.size(), img.type(), Vec3b(255,255,255) ); CV_8UC1, 255); //create completely white mask
roi
img.setTo(Vec3b(0,0,0), myMask); //set all areas of img to black that are within the white area of the mask.


To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.


Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....); //BTW: thresholding will only work on image if single channel image


To your first question. There are probably several ways how to do this: This one works, but there might be faster options: options:

Mat myMask = Mat(img.size(), CV_8UC1, 255); //create completely white mask