Resize image - MATLAB imresize (2024)

Table of Contents
Syntax Description Examples Shrink Image By Factor of Two Using Default Interpolation Method Shrink Image Using Nearest-Neighbor Interpolation Resize RGB Image Specifying Size of Output Image Resize Indexed Image Input Arguments A — Image to be resized numeric array | logical array | categorical array scale — Resize factor positive number [numrows numcols] — Row and column dimensions of output image two-element vector of positive numbers X — Indexed image to be resized real, nonsparse numeric array map — Colormap associated with indexed image c-by-3 numeric matrix method — Interpolation method character vector | string scalar | two-element cell array Name-Value Arguments Antialiasing — Perform antialiasing when shrinking an image true | false Colormap — Return optimized colormap "optimized" (default) | "original" Dither — Perform color dithering true (default) | false Method — Interpolation method character vector | string scalar | cell array OutputSize — Size of output image two-element vector of positive numbers Scale — Resize scale factor positive number | two-element vector of positive numbers Output Arguments B — Resized image numeric array | logical array | categorical array Y — Resized indexed image numeric array newmap — Colormap of resized indexed image m-by-3 numeric matrix Extended Capabilities C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™. GPU Code Generation Generate CUDA® code for NVIDIA® GPUs using GPU Coder™. Thread-Based Environment Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool. GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™. Version History R2019a: Supports categorical images See Also Topics MATLAB Command Americas Europe Asia Pacific FAQs

Resize image

collapse all in page

Syntax

B = imresize(A,scale)

B = imresize(A,[numrows numcols])

[Y,newmap]= imresize(X,map,___)

___ = imresize(___,method)

___ = imresize(___,Name,Value)

Description

example

B = imresize(A,scale) returns image B that is scale times the size of image A. The input image A can be a grayscale, RGB, binary, or categorical image.

If A has more than two dimensions, then imresize only resizes the first two dimensions. If scale is between 0 and 1, then B is smaller than A. If scale is greater than 1, then B is larger than A. By default, imresize uses bicubic interpolation.

example

B = imresize(A,[numrows numcols]) returns image B that has the number of rows and columns specified by the two-element vector [numrows numcols].

example

[Y,newmap]= imresize(X,map,___) resizes the indexed image X where map is the colormap associated with the image.

example

___ = imresize(___,method) specifies the interpolation method used.

___ = imresize(___,Name,Value) returns the resized image where name-value arguments control various aspects of the resizing operation. Specify name-value arguments after all other input arguments.

Examples

collapse all

Shrink Image By Factor of Two Using Default Interpolation Method

Open Live Script

Load image into the workspace.

I = imread('ngc6543a.jpg');

Shrink the image by a factor of two.

J = imresize(I, 0.5);

Display the original image and the resized image.

figure, imshow(I), figure, imshow(J)

Resize image - MATLAB imresize (1)

Resize image - MATLAB imresize (2)

Shrink Image Using Nearest-Neighbor Interpolation

Open Live Script

Load an image into the workspace.

I = imread('ngc6543a.jpg');

Shrink the image to 40% of the original size using nearest-neighbor interpolation. This is the fastest method, but it has the lowest quality.

J = imresize(I,0.4,'nearest');

Display the original image and the resized image.

imshow(I)title('Original Image')

Resize image - MATLAB imresize (3)

Resize image - MATLAB imresize (4)

Resize RGB Image Specifying Size of Output Image

Open Live Script

Read an RGB image into the workspace.

RGB = imread('peppers.png');

Resize the RGB image to have 64 rows. imresize calculates the number of columns automatically.

RGB2 = imresize(RGB,[64 NaN]);

Get the size of the resized image.

sz = size(RGB2)
sz = 1×3 64 86 3

Display the original image and the resized image.

imshow(RGB)title("Original Image")

Resize image - MATLAB imresize (5)

imshow(RGB2)title("Resized Image with 64 Rows")

Resize image - MATLAB imresize (6)

Resize Indexed Image

Open Live Script

Read an indexed image into the workspace.

[X,map] = imread("corn.tif");

Increase the size of the indexed image by 50%.

[Y,newmap] = imresize(X,map,1.5);

Display the original image and the resized image.

imshow(X,map)title("Original Indexed Image and Colormap")

Resize image - MATLAB imresize (7)

imshow(Y,newmap)title("Resized Image and Optimized Colormap")

Resize image - MATLAB imresize (8)

Input Arguments

collapse all

AImage to be resized
numeric array | logical array | categorical array

Image to be resized, specified as a numeric array, logical array, or categorical array of any dimension. Input must be nonsparse, and numeric input must be real.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical | categorical

scaleResize factor
positive number

Resize factor, specified as a positive number. imresize applies the same scale factor to the row and column dimensions. To apply a different resize factor to each dimension, use the Scale name-value argument.

If you specify a resize factor that does not result in integer-length image dimensions, then imresize follows the resizing operation with a call to the ceil function. In other words, the output image has ceil(scale*size(A,1)) rows and ceil(scale*size(A,2)) columns.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

[numrows numcols]Row and column dimensions of output image
two-element vector of positive numbers

Row and column dimensions of output image, specified as a two-element vector of positive numbers. You can specify the value NaN for either numrows or numcols. In this case, imresize calculates the number of rows or columns for that dimension automatically, preserving the aspect ratio of the image.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

XIndexed image to be resized
real, nonsparse numeric array

Indexed image to be resized, specified as a real, nonsparse numeric array of positive integers.

Data Types: double | uint8 | uint16

mapColormap associated with indexed image
c-by-3 numeric matrix

Colormap associated with indexed image X, specified as a c-by-3 numeric matrix with values in the range [0, 1]. Each row is a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.

Data Types: double

methodInterpolation method
character vector | string scalar | two-element cell array

Interpolation method, specified as a character vector, string scalar, or two-element cell array. The default value for numeric and logical images is "bicubic". The default value for categorical images is "nearest". Categorical images only support the values "nearest" and "box".

When method is a character vector or string scalar, it identifies a particular method or named interpolation kernel, listed in the following table.

MethodDescription

"nearest"

Nearest-neighbor interpolation; the output pixel is assigned the value of the pixel that the point falls within. No other pixels are considered.

"bilinear"

Bilinear interpolation; the output pixel value is a weighted average of pixels in the nearest 2-by-2 neighborhood.

"bicubic"

Bicubic interpolation; the output pixel value is a weighted average of pixels in the nearest 4-by-4 neighborhood.

Note

Bicubic interpolation can produce pixel values outside the original range.

Interpolation KernelDescription
"box"

Box-shaped kernel

"triangle"Triangular kernel (equivalent to "bilinear")
"cubic"Cubic kernel (equivalent to "bicubic")
"lanczos2"Lanczos-2 kernel
"lanczos3"Lanczos-3 kernel

When method is a two-element cell array, it defines a custom interpolation kernel. The cell array has the form {f,w}, where f is a function handle for a custom interpolation kernel and w is the width of the custom kernel. f(x) must be zero outside the interval -w/2 <= x < w/2. The function handle f can be called with a scalar or a vector input. For user-specified interpolation kernels, the output image can have some values slightly outside the range of pixel values in the input image.

For more information about the built-in and custom interpolation kernels, see Create and Compare Resizing Interpolation Kernels.

Data Types: char | string | cell

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: B = imresize(A,0.5,Antialiasing=false) does not perform antialiasing when shrinking an image.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: B = imresize(A,0.5,"Antialiasing",false) does not perform antialiasing when shrinking an image.

AntialiasingPerform antialiasing when shrinking an image
true | false

Perform antialiasing when shrinking an image, specified as true or false.

  • If the interpolation method is "nearest", then the default value of Antialiasing is false.

  • If the interpolation method is "box" and the input image is categorical, then the default value of Antialiasing is false.

  • For all other interpolation methods, the default value is true.

Data Types: logical

ColormapReturn optimized colormap
"optimized" (default) | "original"

Return optimized or original colormap for indexed image, specified as one of the following values.

ValueDescription
"original"The output colormap newmap is the same as the input colormap map.
"optimized"imresize returns a new optimized colormap.

The Colormap argument is valid only when resizing indexed images.

Data Types: char | string

DitherPerform color dithering
true (default) | false

Perform color dithering, specified as true or false. In dithering, you apply a form of noise to the image to randomize quantization error and prevent large-scale patterns.

The Dither argument is valid only when resizing indexed images.

Data Types: logical

MethodInterpolation method
character vector | string scalar | cell array

Interpolation method, specified as a character vector, string scalar, or two-element cell array. For details, see method.

Data Types: char | string | cell

OutputSizeSize of output image
two-element vector of positive numbers

Size of the output image, specified as a two-element vector of positive numbers. For details, see [numrows numcols].

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

ScaleResize scale factor
positive number | two-element vector of positive numbers

Resize scale factor, specified as a positive number or two-element vector of positive numbers. If you specify a scalar, then imresize applies the same scale factor to the row and column dimensions. If you specify a two-element vector, then imresize applies a different scale value to each dimension.

If you specify a resize scale factor that does not result in integer-length image dimensions, then imresize follows the resizing operation with a call to the ceil function. In other words, the output image has ceil(Scale(1)*size(A,1)) rows and ceil(Scale(2)*size(A,2)) columns.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

B — Resized image
numeric array | logical array | categorical array

Resized image, returned as a numeric, logical, or categorical array of the same data type as the input image, A.

Y — Resized indexed image
numeric array

Resized indexed image, returned as a numeric array of the same data type as the input indexed image, X.

newmap — Colormap of resized indexed image
m-by-3 numeric matrix

Colormap of the resized indexed image Y, returned as an m-by-3 numeric matrix. By default, imresize returns a new, optimized colormap with the resized image. To return a colormap that is the same as the original colormap, use the Colormap name-value argument.

Extended Capabilities

Version History

Introduced before R2006a

expand all

The imresize function now supports categorical images.

See Also

imresize3 (Image Processing Toolbox) | interp2

Topics

  • Working with Image Types in MATLAB
  • Create and Compare Resizing Interpolation Kernels

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Resize image - MATLAB imresize (9)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Resize image - MATLAB imresize (2024)

FAQs

How do I resize an image in Matlab? ›

B = imresize( A , scale ) returns image B that is scale times the size of image A . The input image A can be a grayscale, RGB, binary, or categorical image. If A has more than two dimensions, then imresize only resizes the first two dimensions. If scale is between 0 and 1, then B is smaller than A .

How can we resize the image answer? ›

Generally speaking, image resizing comes in two forms:
  1. Making the image bigger (upscaling) by increasing the dimensions, adding or stretching pixels, or increasing the file size.
  2. Making the image smaller (downscaling) by decreasing the dimensions, subtracting or contracting pixels, or decreasing the overall file size.
Feb 2, 2024

How do you increase the pixel size of an image in Matlab? ›

Resize the image, using the imresize function. In this example, you specify a magnification factor. To enlarge an image, specify a magnification factor greater than 1. magnificationFactor = 1.25; J = imresize(I,magnificationFactor);

What is the best way to resize an image? ›

Adobe Express comes with all the options you need to change your image's dimensions instantly. Crop an image, change the aspect ratio, scale it, or resize it to a preset or custom dimension. The Adobe Express image resizer lets you resize images effortlessly — and for free.

How do I rescale an image intensity in MATLAB? ›

J = imadjust( I ) maps the intensity values in grayscale image I to new values in J . By default, imadjust saturates the bottom 1% and the top 1% of all pixel values. The function linearly maps pixel values between the saturation limits to values between 0 and 1.

How do I adjust the size of an image? ›

How to Resize an Image?
  1. Click on the "Select Image" button to select an image.
  2. Enter a new target size for your image.
  3. Click the "Resize Image" button to resize the image.

How can we resize an object answer? ›

Resize a picture, shape, text box, or other object
  1. Select the object.
  2. Hold down CTRL.
  3. Move the mouse pointer over one of the handles and then click and drag the mouse.
  4. Release the mouse button before you release CTRL.

How do I resize an image to a different size? ›

To scale an image to fit your desired dimensions:
  1. Open Photoshop.
  2. Click "Open" and select the image you want to scale.
  3. Click on the Image tab, and select Image Size.
  4. In this window, you can specify what you want the image size to be. ...
  5. You will notice that there is a link icon between the height and the width.
Mar 14, 2023

How to get image size in MATLAB? ›

You must use [height, width, colour_planes] = size(image); because images have 3 dimensions. The third dimension is the number of colour planes. If you don't need this value, you can substitute ~ to ignore it.

How to resize raster MATLAB? ›

Resize the raster using mapresize . Double the length and width of the raster by specifying the scale as 2. Use nearest neighbor interpolation by specifying the interpolation method as 'nearest' . [Z2,R2] = mapresize(Z,R,2,'nearest');

How to enhance image quality in MATLAB? ›

Improve Image Resolution Using Bicubic Interpolation

A standard way to increase image resolution without deep learning is to use bicubic interpolation. Upscale the low-resolution image using bicubic interpolation so that the resulting high-resolution image is the same size as the reference image.

Can I resize a JPEG image? ›

In Windows, open your JPEG using Paint, click “Select All,” and adjust the height and width by percentage or pixel length. Then select “Save As” and choose “JPEG.” On Macs, open your JPEG in Preview, click “Tools” and “Adjust Size.” Adjust the height and width by percent or pixel length, click “o*k,” and click “Save.”

How do I crop an image size in MATLAB? ›

Crop Image by Specifying Crop Region

Icropped = imcrop( I , rect ) crops the image I according to the position and dimensions specified in the crop rectangle rect . The cropped image includes all pixels in the input image that are completely or partially enclosed by the rectangle.

How do I resize an image code? ›

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.

How do you size a figure in MATLAB? ›

Set Figure Size

Set the figure size by clicking File > Export Setup. Specify the desired dimensions in the Width and Height fields, for example 5-by-4 inches. The dimensions include the entire figure window except for the frame, title bar, menu bar, and any tool bars.

How do I resize an image keeping proportions? ›

If the Shift key is held down whilst moving the handle, then the proportions of the object will be preserved. For example, if I hold Shift and drag the bottom edge upwards to reduce the size by half, then the right edge will automatically move to the left to reduce the width of the object by the same amount.

Top Articles
Robin Herd: 1939-2019
Taylor Swift's dancing skills mocked by Lilly Becker and Motsi Mabuse
Victory Road Radical Red
Cottonwood Vet Ottawa Ks
Body Rubs Austin Texas
Obituaries
Braums Pay Per Hour
Magic Mike's Last Dance Showtimes Near Marcus Cedar Creek Cinema
You can put a price tag on the value of a personal finance education: $100,000
Elle Daily Horoscope Virgo
New Mexico Craigslist Cars And Trucks - By Owner
Inevitable Claymore Wow
Colts seventh rotation of thin secondary raises concerns on roster evaluation
Job Shop Hearthside Schedule
The fabulous trio of the Miller sisters
Moonshiner Tyler Wood Net Worth
Interactive Maps: States where guns are sold online most
Letter F Logos - 178+ Best Letter F Logo Ideas. Free Letter F Logo Maker. | 99designs
Palm Coast Permits Online
All Obituaries | Buie's Funeral Home | Raeford NC funeral home and cremation
Apply for a credit card
Lawson Uhs
Halo Worth Animal Jam
SN100C, An Australia Trademark of Nihon Superior Co., Ltd.. Application Number: 2480607 :: Trademark Elite Trademarks
A Man Called Otto Showtimes Near Cinemark University Mall
The best brunch spots in Berlin
Lines Ac And Rs Can Best Be Described As
Wat is een hickmann?
Marilyn Seipt Obituary
How do you get noble pursuit?
Cfv Mychart
Anesthesia Simstat Answers
Weather Underground Durham
King Soopers Cashiers Check
Poster & 1600 Autocollants créatifs | Activité facile et ludique | Poppik Stickers
Glossytightsglamour
How to Watch the X Trilogy Starring Mia Goth in Chronological Order
Despacito Justin Bieber Lyrics
Rocketpult Infinite Fuel
Claim loopt uit op pr-drama voor Hohenzollern
Bella Thorne Bikini Uncensored
Dee Dee Blanchard Crime Scene Photos
Colorado Parks And Wildlife Reissue List
062203010
Discover Things To Do In Lubbock
Kutty Movie Net
Deepwoken: How To Unlock All Fighting Styles Guide - Item Level Gaming
3500 Orchard Place
Aurora Southeast Recreation Center And Fieldhouse Reviews
Stoughton Commuter Rail Schedule
Okta Hendrick Login
Marion City Wide Garage Sale 2023
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 5693

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.