Resize
We often encounter an image of some size that we would like to convert to an image of
some other size. We may want to upsize (zoom in) or downsize (zoom out) the image; we can
accomplish either task by using cvResize()
. This function
will fit the source image exactly to the destination image size. If the ROI is set in the
source image then that ROI will be resized to fit in the destination image. Likewise, if an
ROI is set in the destination image then the source will be resized to fit into the
ROI.
void cvResize( const CvArr* src, CvArr* dst, int interpolation = CV_INTER_LINEAR );
The last argument is the interpolation method, which defaults to linear interpolation. The other available options are shown in Table 5-4.
Table 5-4. cvResize() interpolation options
Interpolation |
Meaning |
---|---|
|
Nearest neighbor |
|
Bilinear |
|
Pixel area re-sampling |
|
Bicubic interpolation |
In general, we would like the mapping from the source image to the resized destination
image to be as smooth as possible. The argument interpolation
controls exactly how this will be handled. Interpolation arises when we are shrinking an image and a pixel in the destination image falls in between pixels in the source image. It can also occur when we are expanding an image and need to compute values of pixels that do not directly correspond to any pixel in the source image. In either case, there are several options for computing the values of such pixels. ...
Get Learning OpenCV now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.