Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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&lt;="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.

click to hide/show revision 2
No.2 Revision

updated 2017-06-27 05:42:44 -0600

berak gravatar image

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));

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&lt;="0){" return="" 1;="" }="" else="" {="" return="" val;="" }="" }<="" p="">

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.