Filter löschen
Filter löschen

how to use imresize function.

6 Ansichten (letzte 30 Tage)
mohd akmal masud
mohd akmal masud am 2 Aug. 2023
Kommentiert: mohd akmal masud am 30 Aug. 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 Kommentare
mohd akmal masud
mohd akmal masud am 2 Aug. 2023
Thats means the number of 3 showing the image is RGB.
Stephen23
Stephen23 am 2 Aug. 2023
Bearbeitet: Stephen23 am 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).

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Shubham
Shubham am 2 Aug. 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.

Weitere Antworten (1)

Image Analyst
Image Analyst am 2 Aug. 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.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by