Mat orig = imread("in.jpg");
Mat test = orig.clone();
//test.setTo(Scalar::all(255), mask1ch); // assign the pixel value to 255 when its corresponding pixel is 1 in mask1ch
Scalar::all(255) means (255,255,255,255)
mask.convertTo(inv_mask, CV_8UC3, -1.0, 255.0); // inverse the mask matrix means I_new(x,j) = -1*I(x,j) + 255.
This is the model c = a* I + beta. at opencv the convertTo can not change the channel number
convert to only can change the data type instead of channel numbers