how to use imresize function.

7 visualizzazioni (ultimi 30 giorni)
mohd akmal masud
mohd akmal masud il 2 Ago 2023
Commentato: mohd akmal masud il 30 Ago 2023
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 Commenti
mohd akmal masud
mohd akmal masud il 2 Ago 2023
Thats means the number of 3 showing the image is RGB.
Stephen23
Stephen23 il 2 Ago 2023
Modificato: Stephen23 il 2 Ago 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).

Accedi per commentare.

Risposta accettata

Shubham
Shubham il 2 Ago 2023
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.

Più risposte (1)

Image Analyst
Image Analyst il 2 Ago 2023
"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.

Categorie

Scopri di più su Images in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by