Ask Your Question
0

How to resize Float Matrix in OpenCV

asked 2013-04-25 07:23:09 -0600

Karthik gravatar image

I have a Mat object of type CV_32FC1 of size 300x300 ....

I tried :

B=Mat::ones(rows,cols,CV_32FC1)*100;

...process B...

Mat res_B=Mat::zeros(480,640,CV_32FC1); 

resize(B, res_B, Size(640,480), 0, 0, INTER_CUBIC);

How to resize it to size 640x480 ?? When I used the resize() function in OpenCV it doesnt seem to work...Any suggestions??

edit retag flag offensive close merge delete

Comments

what exactly does not work ?

berak gravatar imageberak ( 2013-04-25 07:39:02 -0600 )edit

I could reproduce your code and it works. I printed the matrix using the following code: cv::namedWindow("Display Image", CV_WINDOW_AUTOSIZE); imshow("Display Image", res_B); waitKey(0);

Nyenna gravatar imageNyenna ( 2013-04-25 09:02:00 -0600 )edit

@berak All values in res_B are 100.... But after processing B contains several floating point nos... In the resized Mat res_B it is not !!

Karthik gravatar imageKarthik ( 2013-04-25 11:53:31 -0600 )edit

@Nyenna Did you use Float Mat ??? I think,imshow function supports only CV_8UC1 ..

Karthik gravatar imageKarthik ( 2013-04-25 11:55:58 -0600 )edit

I used the very same code that you posted (without the processing part, of course). Are you sure you process B correctly? Can you verify that you do by showing the image just before the resize() line?

Nyenna gravatar imageNyenna ( 2013-04-26 01:15:58 -0600 )edit

No...aftr processing there will be floating values in Mat.... You manually assign certain pixels with float values such as 21.11,19.33,88.43 and then resize ...and display...do you get same result???

Karthik gravatar imageKarthik ( 2013-04-26 02:00:14 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2013-04-26 03:54:41 -0600

Nyenna gravatar image

updated 2013-04-26 06:22:50 -0600

The following code works:

cv::Mat B = cv::Mat::ones(300,300,CV_32FC1);

for (int i = 0; i < 100; i++)
{
    B.at<int>(50, i) = 0;
    B.at<int>(51, i) = 0;
}

cv::Mat res_B;

resize(B, res_B, Size(640, 480));

namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", B );
imshow( "Display Resized Image", res_B );

waitKey(0);

I hope it will help.

edit flag offensive delete link more

Comments

Maybe there is something I don't get, but isn't it normal if you put data in a matrix, then expand it to not have the same result everywhere because of the interpolation ?

Even if the matrix is homogeneous, i noticed that OpenCV do some weird things with floating point values (maybe some double => float truncation) that I couldn't explain by the fact that the set of floating point values is not continuous.

So the essence of interpolation is to "create" data that could be correct regarding the neighbourhood.

Or am I just really far of the problem here ?

Rogeeeer gravatar imageRogeeeer ( 2013-04-26 04:27:17 -0600 )edit

Yes..It resizes properly.... if I give the interpolation option as INTER_NEAREST or INTER_LINEAR... if i use INTER_CUBIC , there are several negative values in the resized matrix whereas I had all positive values in the original matrix..... Do you know why INTER_CUBIC generates negative float values in resized matrix.... I still used it for an Image(uchar) and got the resized image pretty well

Karthik gravatar imageKarthik ( 2013-04-27 11:11:22 -0600 )edit

Question Tools

Stats

Asked: 2013-04-25 07:23:09 -0600

Seen: 8,755 times

Last updated: Apr 26 '13