1 | initial version |
Core.subtract will indeed saturate results for unsigned data types. note, that your allocation here:
grayImg1=new Mat(300,300,CV_32S);
will get overwritten (it's useless, and you only fool yourself here), and the grayscale result has the same depth as the input (CV_8U);
also note, that opencv uses BGR pixel order, so you have to use COLOR_BGR2GRAY.
to preserve thnegative values, you have to convert the image to some signed (and larger) type, so all in all it should be:
Mat grayImg1 = new Mat();
Imgproc.cvtColor(img1, grayImg1, Imgproc.COLOR_BGR2GRAY);
Mat gray_32 = new Mat();
grayImg1.convertTo(gray_32, CvType.CV_32S);
Scalar img1mean = Core.mean(grayImg1);
Core.subtract(gray_32, img1mean, gray_32);