In the nearest interpolation method, the output pixel is assigned the value of the pixel that the point falls within. The default method is bicubic, but we can change it to nearest or bilinear by entering a string containing the new method’s name in the imresize() function. We can also change the method of interpolation, which is used to resize the image. The right image is the original image in the output, and the left image is the resized image. For example, let’s read an indexed image and resize it. To plot an indexed image, we have to use the 2D array and the map. The resize function will give us a new 2D array and a new colormap. To resize an indexed image, we have to use a second variable inside the imresize() function, which is the colormap of the input image, which we can get using a second output of the imread() function.
An RGB image contains the color as a third dimension, but the indexed image contains color as a separate colormap. An indexed image is different as compared to an RGB image, it is composed of a 2D array with byte data stored in it, and we can also put a different type of data in it like double, int16, etc. We can also resize an indexed image using the imresize() function. The third dimension is not changed because it contains the color values present in the image. You can also see the size of the output image on top of the right image, which is 100-by-100. The left image is the original image in the output, and the right image is the resized image.
For example, let’s resize the above image to get an image of size 100-by-100. Instead of using an integer as the resize scale value, we can use a vector to define the size of the output image like to get an output image of size 100-by-100. For example, in the case of the above code, if you look at the workspace in Matlab, you will know that the third dimension is the same in both the original and resized image. If the image contains more than two dimensions, the imresize() function will only change the size of the first two dimensions, and other dimensions will remain the same. You can also check the size of the variable in which the two output image is stored, and it will be ten times greater than the original size. For example, let’s read an image using the imread() function and resize it using the imresize() function, and then plot both using the imshow() function. The second argument is the scale, or the resize factor, and it should be a positive number. It can be of type logical, numeric, and categorical, but the numeric values should be real. The first argument is the image to be resized. If the resize scale is 0.5, the pixel will become half. In this case, the imresize() function will remove pixels from the image depending on the resize value.
If we want to lower the size of the image, we can use a resize scale value of less than 1. This function creates more pixels using the pixel values already present in the neighborhood. For example, if we resize an image two times of size 100-by-100, then its final size will be 200-by-200. This function resizes images by increasing or decreasing their pixels.
We can use the imresize() function to resize images in Matlab. Resize an Image Using the imresize() Function in MATLAB This tutorial will discuss resizing an image using the imresize() function in Matlab.