I get the same Image as the original, but I don't get a bigger one with the ROI in the center. Maybe it's easy, but I don't find the problem.
for( int index = 0; index < contours.size();index++ ){
Mat contour = contours.get(index);
double contourArea =Imgproc.contourArea(contour);
if( contourArea > max) {
max = Math.max(max, contourArea);
indexMax = index;
}
}
if( indexMax > -1){
Imgproc.threshold(mCellCopy, mCellCopy, 128, 255, Imgproc.THRESH_BINARY);
// ROI source
Converters.Mat_to_vector_Point(contours.get(indexMax), contourPoints);
boundingRect = Imgproc.boundingRect(contourPoints);
Mat mROISource = new Mat(boundingRect.width, boundingRect.height, CvType.CV_8UC1, new Scalar(0));
mROISource = mCellCopy.submat(boundingRect);
//Img destine
Mat mCentredNumber = new Mat(100,100, CvType.CV_8UC1, new Scalar(255));
//ROI destine in the center of the new Image
int x = (int) (Math.floor(mCentredNumber.size().width/2.0f)); - boundingRect.width/2;
int y = (int) (Math.floor(mCentredNumber.size().height/2.0f)); - boundingRect.height/2;
Rect ROI = new Rect(x,y,boundingRect.width,boundingRect.height);
// Referencing ROI destine
Mat mROIC = mCentredNumber.submat(ROI);
// ROI source to ROI destine
mROISource.copyTo(mROIC);
Highgui.imwrite("/mnt/sdcard/CellCentred/"+i+j+".png", mROIC);
Thank you.