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;="" }="" }<="" p="">
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.