Ask Your Question
0

resize an image

asked 2017-06-27 05:26:00 -0600

Nani gravatar image

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

berak gravatar 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.

edit retag flag offensive close merge delete

Comments

@berak thank you very much you are my hero, it worked fine.

Nani gravatar imageNani ( 2017-06-27 06:34:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-06-27 05:50:41 -0600

berak gravatar image

you probably wanted:

 new Size(srcOrig.cols()/scaleFactor, srcOrig.rows()/scaleFactor)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-27 05:26:00 -0600

Seen: 355 times

Last updated: Jun 27 '17