how to use imresize function.

조회 수: 9 (최근 30일)
mohd akmal masud
mohd akmal masud 2023년 8월 2일
댓글: mohd akmal masud 2023년 8월 30일
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
mohd akmal masud
mohd akmal masud 2023년 8월 2일
Thats means the number of 3 showing the image is RGB.
Stephen23
Stephen23 2023년 8월 2일
편집: Stephen23 2023년 8월 2일
"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).

댓글을 달려면 로그인하십시오.

채택된 답변

Shubham
Shubham 2023년 8월 2일
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.

추가 답변 (1개)

Image Analyst
Image Analyst 2023년 8월 2일
"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.

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by