how to use imresize function. (2024)

5 views (last 30 days)

Show older comments

mohd akmal masud on 2 Aug 2023

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function

Commented: mohd akmal masud on 30 Aug 2023

Accepted Answer: Shubham

  • image2988.zip
  • unknown.zip

Open in MATLAB Online

Dear All,

I have image unknown.png, I want to covert the size and map same with the image image2988.png (28x28 uint8)

Because my unknown.png is 2320x2864x3 uint8

I tried this command

%testing

testing = imread('unknown.png');

testing1 = imresize(testing, [28 28])

but the image still have 28x28x3 uint8 . What I want is just 28x28 uint8 only. Why the number of 3 have

3 Comments

Show 1 older commentHide 1 older comment

Stephen23 on 2 Aug 2023

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#comment_2835862

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#comment_2835862

Edited: Stephen23 on 2 Aug 2023

"Why the number of 3 have"

IMRESIZE does not convert an RGB image into a grayscale or select color channels or whatever unspecified operation you expect to occur. IMRESIZE uses a fairly universal definition of "resizing" an image: it changes the number of row/columns an image has, exactly as its documentation clearly states "If A has more than two dimensions, then imresize only resizes the first two dimensions". It is highly recommended to read the documentation for functions that you are using, to learn what those functions do and how to call them properly. Reading the documentation is faster and more reliable than guessing.

If you want one channel of your image then use indexing.

If you want to convert an RGB (e.g. truecolor) image to grayscale then use IM2GRAY:

https://www.mathworks.com/help/matlab/ref/im2gray.html

mohd akmal masud on 2 Aug 2023

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#comment_2835882

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#comment_2835882

Thats means the number of 3 showing the image is RGB.

Stephen23 on 2 Aug 2023

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#comment_2835952

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#comment_2835952

Edited: Stephen23 on 2 Aug 2023

"Thats means the number of 3 showing the image is RGB."

Probably, but not necessarily: it might be an Lab image, or use any of countless other colorspaces.

The number of channnels does not uniquely determine what colorspace an image is encoded with, that can only be determined with prior-knowledge (e.g. the color encoding stored as part of in an image file).

Sign in to comment.

Sign in to answer this question.

Accepted Answer

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#answer_1282162

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#answer_1282162

Hi Mohd,

The value "3" in the statement "2320x2864x3 uint8" refers to the number of color channels in the image. In this case, the image has 3 color channels, namely Red, Green, and Blue (RGB). Each pixel in the image is represented by three 8-bit unsigned integers (uint8) for the intensity values of each color channel.

If you want to convert the resulting image to grayscale and have a size of "28x28 uint8" with a single channel, you can use the "rgb2gray" function in MATLAB. Details

Also refer to this MATLAB Answer for more insight.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

More Answers (1)

Image Analyst on 2 Aug 2023

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#answer_1282367

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#answer_1282367

Open in MATLAB Online

"I have image unknown.png, I want to covert the size and map same with the image image2988.png (28x28 uint8)" so I take it that the unknown.png is an RGB image and image2988.png is an indexed image and you want to convert the unknown image to an indexed image, using the same colormap as image2988, and then resize it. So you can do this (untested)

% Read in reference image and it's colormap

[indexedImage, cmap] = imread('image2988.png');

% Get it's size.

[rows, columns, numberOfColorChannels] = size(indexedImage)

if isempty(cmap)

% If colormap does not exist, use gray scale.

cmap = gray(256);

end

% Read in unknown RGB image

unknownImage = imread('unknown.png');

% Resize image. Note this may change colors obviously.

unknownImage = imresize(unknownImage, [rows, columns]); % It's still an RGB image after this.

% Turn into an indexed image using the same colormap as the reference image.

unknownImage = rgb2ind(unknownImage, cmap);

If it doesn't work then let me know and I'll download your zip files and try it and correct it. Or if I didn't understand what you meant when you said you wanted to apply the map of image2988 to unknown, then please explain better.

1 Comment

Show -1 older commentsHide -1 older comments

mohd akmal masud on 30 Aug 2023

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#comment_2867181

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2003492-how-to-use-imresize-function#comment_2867181

THANK YOU @Stephen23 @Image Analyst @Shubham

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphicsImages

Find more on Images in Help Center and File Exchange

Tags

  • image acquisition
  • image segmentation
  • digital image processing
  • image analysis
  • image processing

Products

  • Image Processing Toolbox

Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


how to use imresize function. (8)

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

Contact your local office

how to use imresize function. (2024)

FAQs

How does imresize work? ›

By default, imresize uses bicubic interpolation. B = imresize( A , [numrows numcols] ) returns image B that has the number of rows and columns specified by the two-element vector [numrows numcols] . [ Y , newmap ] = imresize( X , map ,___) resizes the indexed image X where map is the colormap associated with the image.

How to use resize function in Matlab? ›

B = resize( A , m , Name=Value ) specifies additional parameters for resizing using one or more name-value arguments. For example, resize(A,m,Pattern="circular") , where m is greater than the size of A in the operating dimension, resizes by repeating the input data circularly.

How to use cv2 resize in python? ›

Output
  1. We first load the input image using cv2. imread() .
  2. Then, we define the desired dimensions (width and height) for the resized image.
  3. Next, we use the resize() function to resize the image to the specified dimensions.
  4. Finally, we save the resized image using cv2. imwrite() .
Apr 8, 2024

What is the default method of Imresize in Matlab? ›

By default, imresize uses bicubic interpolation, but you can specify other interpolation methods or interpolation kernels. You can also specify your own custom interpolation kernel. This example use nearest neighbor interpolation. L = imresize(I,magnificationFactor,"nearest");

How do I use an online image resizer? ›

How to resize an image.
  1. Select. Upload your JPG or PNG to our image resize tool.
  2. Resize. Choose a size template based on the social platform or add your own.
  3. Continue editing. Instantly download your resized image or keep editing.

Is there an app to resize photos? ›

The YouCam Perfect photo resizer app has all these size options for you, so you can resize your images in seconds. In just three simple steps, you'll have a photo that's ready to share on social media.

How do you use the resize function? ›

size (MATLAB Functions) d = size(X) returns the sizes of each dimension of array X in a vector d with ndims(X) elements. [m,n] = size(X) returns the size of matrix X in separate variables m and n . m = size(X,dim) returns the size of the dimension of X specified by scalar dim .

How do I use resize command? ›

To resize a window, move the cursor to the edge or corner of the window. The cursor should change to a double-headed arrow, allowing you to increase or decrease the size by clicking and dragging with the mouse.

How to resize an image and keep aspect ratio? ›

On the Home tab, in the Image group, select Resize. *Once the Maintain aspect ratio check box is selected, you only need to enter the horizontal value (width) or vertical value (height). The other value in the Resize area will update automatically.

How does resize work in Python? ›

resize(), we can resize the size of an array. Array can be of any shape but to resize it we just need the size i.e (2, 2), (2, 3) and many more. During resizing numpy append zeros if values at a particular place is missing.

What is interpolation in resize? ›

Interpolation is generally used to estimate new data points from the known data points by statisticians for better understanding of the underlying data, can be used to approximate complex functions for efficient experimentations or even used for scaling images!

What is the Imresize function? ›

imresize resizes an image of any type using the specified interpolation method. method is a string that can have one of these values: 'nearest' (default) uses nearest neighbor interpolation. 'bilinear' uses bilinear interpolation.

How to make two images of the same size in MATLAB? ›

1 Answer. B = imresize( B,[size(A,1) size(A,2)]); For accessing more options with resizing, use this resource.

How to calculate image size in MATLAB? ›

You must use [height, width, colour_planes] = size(image); because images have 3 dimensions.

How does image resizing work? ›

When an image is resized, its pixel information is changed. For example, an image is reduced in size, any unneeded pixel information will be discarded by the photo editor (Photoshop).

How does image size app work? ›

This app allows you to resize an image to whatever size you like, quickly and easily. To preserve aspect ratio just tap on the chain icon between width and height input fields. Image Size gives you the option of saving, emailing, printing or sharing the final image.

How much does image resizer cost? ›

Image Resizing Service at Rs 45/image in New Delhi | ID: 7828061248.

Does Imagify resize images? ›

Imagify is an image optimization tool that helps you reduce the size of your images the easy way without losing its quality. Imagify also converts your images to WebP format, which will additionally reduce the size of your website making it faster.

Top Articles
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6422

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.