GFG App
Open App Browser
Continue

Prerequisite : RGB image representation

MATLAB stores most images as two-dimensional matrices, in which each element of the matrix corresponds to a single discrete pixel in the displayed image. Some images, such as truecolor images, represent images using a three-dimensional array. In truecolor images, the first plane in the third dimension represents the red pixel intensities, the second plane represents the green pixel intensities, and the third plane represents the blue pixel intensities.

#### Image Resize using `imresize()`:

Image resize changes the size of an image. There are two ways of using the imresize column. if the input image has more than two dimensions imresize only resizes the first two dimensions.

• `J = imresize(I, scale)` : The method takes the input image `I` as input and a scaling factor and scales the input image with that factor. For eg. if we choose 0.5 as the scaling factor every two pixels in the original image is mapped to one pixel value in the output image for both the dimensions.
• `J = imresize(I, [numrows numcols])` : The methods takes the number of rows and columns and fits the original input image to an output image having the specified number of rows and columns.

Code #1: Read the image from file

 `% read image file ` `I = imread(``'image.jpg'``); ` ` `  `%display image size ` `size(I) ` ` `  `%display the image ` `figure, imshow(I); `

Output :

```ans = 371   660     3
``` Code #2: Resize by scaling

 `% compress the image and save  ` `% in another variable ` `I1 = imresize(I, 0.5); ` ` `  `%display image size ` `size(I1) ` ` `  `%display the image ` `figure, imshow(I1); `

Output :

```ans = 186   330     3
``` Code #3: Resize with specified rows and columns

 `% resize by specifying rows  ` `% and columns ` `I2 = imresize(I, [100, 200]); ` ` `  `%display image size ` `size(I2) ` ` `  `%display the image ` `figure, imshow(I2); `

Output :

```ans = 100   200     3
``` My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.7662379,"math_prob":0.9880008,"size":1831,"snap":"2023-14-2023-23","text_gpt3_token_len":439,"char_repetition_ratio":0.16475096,"word_repetition_ratio":0.0,"special_character_ratio":0.24795194,"punctuation_ratio":0.13068181,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9946116,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,null,null,null,null,6,null,6,null,6,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-02T19:35:26Z\",\"WARC-Record-ID\":\"<urn:uuid:0512e251-8d52-492d-a4b0-c37a6db4590c>\",\"Content-Length\":\"246115\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d9765a19-9e8c-4864-84e9-91795840f146>\",\"WARC-Concurrent-To\":\"<urn:uuid:d3d12fb6-5424-49ff-bf6e-a1eb1746334b>\",\"WARC-IP-Address\":\"44.228.100.190\",\"WARC-Target-URI\":\"https://origin.geeksforgeeks.org/image-resizing-in-matlab/?ref=lbp\",\"WARC-Payload-Digest\":\"sha1:ZX6YCE2S3ERN3YWP6EN7RGK6QKFX7EFD\",\"WARC-Block-Digest\":\"sha1:AM7GWAQA777OHDEZM3IDSQWN47UAZV2P\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224648850.88_warc_CC-MAIN-20230602172755-20230602202755-00345.warc.gz\"}"}