resize an image
I am resizing my images to apply k-means for segmenting images and get ROI. I am using the following code from the book: mastering opencv android application programming:
int scaleFactor = calcScaleFactor(srcOrig.rows(), srcOrig.cols());
Imgproc.resize(srcOrig, src, new Size(srcOrig.rows()/scaleFactor, srcOrig.cols()/scaleFactor));
private static int calcScaleFactor(int rows, int cols){
int idealRow, idealCol;
if(rows<cols){
idealRow = 240;
idealCol = 320;
} else {
idealCol = 240;
idealRow = 320;
}
int val = Math.min(rows / idealRow, cols / idealCol);
if(val<=0){
return 1;
} else {
return val;
}
}
it is working fine and the time is reduced considerably but the image is stretched so much and for example circles became ellipses. do I need to scale the image back after segmentation or i need to change the scaling factor values for rows and cols or could you please suggest any solution. The problem is worse when the image is not a square and number of columns or rows is way bigger than the other.
Any help is appreciated.
@berak thank you very much you are my hero, it worked fine.