Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Resize an image but fill the space with black ?

I have a small Image:

Mat myImage;

This image is of Size(100,100). Now I would like to enlarge the dimension of this image to Size(1000,1000) (filling the rest of the space with black)

I could do in this way (but I think there could be a faster solution)

 Mat largerImage(Size(1000,1000),myImage.type());
 myImage.copyTo(largerImage());

How can I directly "expand" myImage ?

Resize an image but fill the space with black ?

I have a small Image:

Mat myImage;

This image is of Size(100,100). Now I would like to enlarge the dimension of this image to Size(1000,1000) (filling the rest of the space with black)

I could do in this way (but I think there could be a faster solution)

 Mat largerImage(Size(1000,1000),myImage.type());
 myImage.copyTo(largerImage());
myImage.copyTo(largerImage(Rect(0,0,myImage.cols,myImage.rows)));

How can I directly "expand" myImage ?

Resize an image but fill the space with black ?

I have a small Image:

Mat myImage;

This image is of Size(100,100). Now I would like to enlarge the dimension of this image to Size(1000,1000) (filling the rest of the space with black)

I could do in this way (but I think there could be a faster solution)

 Mat largerImage(Size(1000,1000),myImage.type());
 largerImage = Scalar(0);
 myImage.copyTo(largerImage(Rect(0,0,myImage.cols,myImage.rows)));

How can I directly "expand" myImage ?

Resize an image but fill the space with black ?

I have a small Image:

Mat myImage;

This image is of Size(100,100). Now I would like to enlarge the dimension of this image to Size(1000,1000) (filling the rest of the space with black)

I could do in this way (but I think there could be a faster solution)

 Mat largerImage(Size(1000,1000),myImage.type());
 largerImage = Scalar(0);
 myImage.copyTo(largerImage(Rect(0,0,myImage.cols,myImage.rows)));

How can I directly "expand" myImage ?