answered Apr 20 '16
your mask is not initialized properly. it has the right size / type, but the pixels contain uninitialized data.
Mat mask = Mat.zeros(submatrix.rows(), submatrix.cols(), CvType.CV_8UC1);
should do , what you want.