Introduction to Matlab Image Resize
MATLAB is designed to store most of the images in the form of two-dimensional matrices. In those matrices, each element corresponds to a distinct discrete pixel present in any stored image. The Image Processing Toolbox software available in MATLAB supports several operations that can be performed on images. The function of the resizing images is one of those functionalities. Resizing of any 2D image in MATLAB can be performed using imresize() function whereas imresize3() is used for resizing of 3-D volumetric intensity image.
|ImgOut = imresize(Img,scale)||This syntax is used to result an image ImgOut which is scaled-up version of input image Img with respect to its size. The input image Img can be of type binary, grayscale, categorical image or RGB.
Resizing an image using a GPU is optional for this syntax.
|ImgOut= imresize(Img,[row_numcol_num])||This syntax is used to result an image ImgOut created with number of rows and columns specified by the input argument vector|
|[ImgOut,newmap] = imresize(Img,map,___)||This syntax is used to result resized form of the indexed image Img with colormap map, presented by ImgOut. By default, imresize results in an optimized colormapi.enewmap, along with the resized indexed image ImgOut. In order to result the same colormap as that of the original colormap, the Colormap name-value pair argument needs to be used.
Application of this syntaxon a GPU is not supported.
|___ = imresize(___,method)||This syntax is used to result resized image with the interpolation method being specified.|
|___ = imresize(___,Name,Value)||This syntax is used to result resized image being customizedby means of name-value pair arguments in order to control different aspects of the resizing operation. Application of this syntaxon a GPU is not supported.|
Examples to Matlab Image Resize
There are different ways in which an image can be resized in a MATLAB program. They are:
1. Resizing using Magnification Value
The image can be magnified or shrink by a specific factor mention within the imresize() command.
Img = imread('MyIMage.png');% Reading input image from workspaceimshow(Img) %Showing given image on the output windowtitle('Original Image')Out = imresize(Img,0.5);imshow(Out)title(' Resized Image') axis off
2. Resizing usingfixed dimension Value
The image can be magnified or shrink to definite dimensions, mentioned within the imresize() command.
Img = imread('MyCircuit.png');imshow(Img)Out = imresize(Img,[100 150]);imshow(Out)axis off
3. Resizing using the specific interpolation method
The image can be magnified or shrink using a specific interpolation method, mentioned within the imresize() command.
Img = imread('MyIMage.png');imshow(Img)Out = imresize(Img,0.5, 'nearest'); %Applying the interpolation method ‘nearest- %neighbor’imshow(Out)axis off
By default, imresize() has an antialiasing feature turned on in order to limit the impact of aliasing for the output image for all interpolation types except for the method ‘nearest- neighbor’. The antialiasing can be turned off by specifying the ‘Antialiasing’ parameter having value as False.
Img = imresize(I,.75,'Antialiasing’, false);figure, imshow(Img)
4. Resizing indexed images
An indexed image specified in the form of a numerical array can be magnified or shrink using a scaling factor, mentioned within the imresize() command.
[M, map] = imread('trees.png');
[O, newmap] = imresize(M, map, 0.5);
5. Resizing RGB Image to the Specified Size of Output Image
An RGB image specified can be magnified or shrink to a definite dimention, mentioned within the imresize() command.
RGB = imread('trees.png');
RGBOut = imresize(RGB, [64 NaN]);
Input Arguments and Attributes
Below are the table explain arguments and attributes:
|Scale||It acts as Resizing factor by which the original image size gets changed.||0>val<1 or val>1|
|[numrowsnumcols]||This vector decides the number of rows and columns in which the resultant image should be created.||NaN or any positive integer|
|map||This attribute is associated with indexed image presenting color map for the same.||Values are in the range [0,1]|
|Method||This attribute talks about Interpolation method or kernel to be used in the resizing operation.||Methods: nearest, bilinear, bicubic Kernel: box, triangle,cubic,lanczos2, lanczos3|
|Antialiasing||The attribute decides on enabling an antialiasing effect on the output image when the input image is subjected to be shrink.||True/False|
|Colormap||This output parameter returns a value of an optimized or original colormap with respect to the indexed image.||Original/optimized|
|Dither||This attribute is used to perform color dithering. In this process, a form of noise is applied to the image in order to randomize quantization error as well as to prevent large-scale patterns.||True/False|
|Newmap||This attribute is used for Optimized colormap.||[0,1]|
Below are the points explain additional information:
- The function imresize()has been introduced in version 5.4 (R2007a). In earlier versions of the Image Processing Toolbox™, a different algorithm is being used by default. If the same results are expected to be produced by the previous version programming, instead of the function imresize(), the function imresize_old() needs to be adapted.
- The operation of imresize() method is carried out either by CPU or GPU. There is a numerical difference between the results of imresize that occurs on the bottom and rightmost borders of the resultant image. But this can be barely noticed by the naked eyes.
- In case of the resultant image not having size with an integer value, the imresize() function does not use the specified scaling factor. Imresize() uses ceil while calculating the size of the output image.
- If the input image has more than two dimensions, then imresize() supports performing resizing operation only to the first two dimensions.
This is a guide to Matlab Image Resize. Here we discuss an introduction to Matlab Image Resize, syntax with attributes, examples to resize images. You can also go through our other related articles to learn more –